diff options
| author | Keith Randall <keithr@alum.mit.edu> | 2019-03-20 10:47:17 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2019-04-03 21:27:05 +0000 |
| commit | 9da6530faab0a58c4c4e02b2f3f4a5c754dcbd4e (patch) | |
| tree | a49cee6c873b4854bb64ae252f11dc6051869647 /src/runtime | |
| parent | 48ef01051ae58265088ee87f3a408224d2cfaec3 (diff) | |
| download | go-9da6530faab0a58c4c4e02b2f3f4a5c754dcbd4e.tar.xz | |
syscall: avoid _getdirentries64 on darwin
Getdirentries is implemented with the __getdirentries64 function
in libSystem.dylib. That function works, but it's on Apple's
can't-be-used-in-an-app-store-application list.
Implement Getdirentries using the underlying fdopendir/readdir_r/closedir.
The simulation isn't faithful, and could be slow, but it should handle
common cases.
Don't use Getdirentries in the stdlib, use fdopendir/readdir_r/closedir
instead (via (*os.File).readdirnames).
Fixes #30933
Update #28984
RELNOTE=yes
Change-Id: Ia6b5d003e5bfe43ba54b1e1d9cfa792cc6511717
Reviewed-on: https://go-review.googlesource.com/c/go/+/168479
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/sys_darwin.go | 11 | ||||
| -rw-r--r-- | src/runtime/sys_darwin_32.go | 11 | ||||
| -rw-r--r-- | src/runtime/sys_darwin_386.s | 37 | ||||
| -rw-r--r-- | src/runtime/sys_darwin_64.go | 11 | ||||
| -rw-r--r-- | src/runtime/sys_darwin_amd64.s | 37 | ||||
| -rw-r--r-- | src/runtime/sys_darwin_arm.s | 2 | ||||
| -rw-r--r-- | src/runtime/sys_darwin_arm64.s | 6 |
7 files changed, 84 insertions, 31 deletions
diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go index f34ac88352..434fa5f588 100644 --- a/src/runtime/sys_darwin.go +++ b/src/runtime/sys_darwin.go @@ -89,6 +89,17 @@ func syscall_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) } func syscall6X() +//go:linkname syscall_syscallPtr syscall.syscallPtr +//go:nosplit +//go:cgo_unsafe_args +func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { + entersyscallblock() + libcCall(unsafe.Pointer(funcPC(syscallPtr)), unsafe.Pointer(&fn)) + exitsyscall() + return +} +func syscallPtr() + //go:linkname syscall_rawSyscall syscall.rawSyscall //go:nosplit //go:cgo_unsafe_args diff --git a/src/runtime/sys_darwin_32.go b/src/runtime/sys_darwin_32.go index 2f17091327..f126be83e5 100644 --- a/src/runtime/sys_darwin_32.go +++ b/src/runtime/sys_darwin_32.go @@ -19,14 +19,3 @@ func syscall_syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, e return } func syscall9() - -//go:linkname syscall_syscallPtr syscall.syscallPtr -//go:nosplit -//go:cgo_unsafe_args -func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { - entersyscallblock() - libcCall(unsafe.Pointer(funcPC(syscallPtr)), unsafe.Pointer(&fn)) - exitsyscall() - return -} -func syscallPtr() diff --git a/src/runtime/sys_darwin_386.s b/src/runtime/sys_darwin_386.s index 1bc1a63c28..d318509e0a 100644 --- a/src/runtime/sys_darwin_386.s +++ b/src/runtime/sys_darwin_386.s @@ -675,9 +675,42 @@ ok: POPL BP RET -// Not used on 386. +// syscallPtr is like syscall except the libc function reports an +// error by returning NULL and setting errno. TEXT runtime·syscallPtr(SB),NOSPLIT,$0 - MOVL $0xf1, 0xf1 // crash + PUSHL BP + MOVL SP, BP + SUBL $24, SP + MOVL 32(SP), CX + MOVL (0*4)(CX), AX // fn + MOVL (1*4)(CX), DX // a1 + MOVL DX, 0(SP) + MOVL (2*4)(CX), DX // a2 + MOVL DX, 4(SP) + MOVL (3*4)(CX), DX // a3 + MOVL DX, 8(SP) + + CALL AX + + MOVL 32(SP), CX + MOVL AX, (4*4)(CX) // r1 + MOVL DX, (5*4)(CX) // r2 + + // syscallPtr libc functions return NULL on error + // and set errno. + TESTL AX, AX + JNE ok + + // Get error code from libc. + CALL libc_error(SB) + MOVL (AX), AX + MOVL 32(SP), CX + MOVL AX, (6*4)(CX) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVL BP, SP + POPL BP RET // syscall6 calls a function in libc on behalf of the syscall package. diff --git a/src/runtime/sys_darwin_64.go b/src/runtime/sys_darwin_64.go index 8c128811b9..07b0bb54af 100644 --- a/src/runtime/sys_darwin_64.go +++ b/src/runtime/sys_darwin_64.go @@ -19,14 +19,3 @@ func syscall_syscallX(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { return } func syscallX() - -//go:linkname syscall_syscallXPtr syscall.syscallXPtr -//go:nosplit -//go:cgo_unsafe_args -func syscall_syscallXPtr(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { - entersyscallblock() - libcCall(unsafe.Pointer(funcPC(syscallXPtr)), unsafe.Pointer(&fn)) - exitsyscall() - return -} -func syscallXPtr() diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s index f99cb00ab8..934c510b88 100644 --- a/src/runtime/sys_darwin_amd64.s +++ b/src/runtime/sys_darwin_amd64.s @@ -637,9 +637,40 @@ ok: POPQ BP RET -// Not used on amd64. -TEXT runtime·syscallXPtr(SB),NOSPLIT,$0 - MOVL $0xf1, 0xf1 // crash +// syscallPtr is like syscallX except that the libc function reports an +// error by returning NULL and setting errno. +TEXT runtime·syscallPtr(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $16, SP + MOVQ (0*8)(DI), CX // fn + MOVQ (2*8)(DI), SI // a2 + MOVQ (3*8)(DI), DX // a3 + MOVQ DI, (SP) + MOVQ (1*8)(DI), DI // a1 + XORL AX, AX // vararg: say "no float args" + + CALL CX + + MOVQ (SP), DI + MOVQ AX, (4*8)(DI) // r1 + MOVQ DX, (5*8)(DI) // r2 + + // syscallPtr libc functions return NULL on error + // and set errno. + TESTQ AX, AX + JNE ok + + // Get error code from libc. + CALL libc_error(SB) + MOVLQSX (AX), AX + MOVQ (SP), DI + MOVQ AX, (6*8)(DI) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVQ BP, SP + POPQ BP RET // syscall6 calls a function in libc on behalf of the syscall package. diff --git a/src/runtime/sys_darwin_arm.s b/src/runtime/sys_darwin_arm.s index 54c7afbf34..6c3fa0739d 100644 --- a/src/runtime/sys_darwin_arm.s +++ b/src/runtime/sys_darwin_arm.s @@ -418,7 +418,7 @@ ok: RET // syscallPtr is like syscall except the libc function reports an -// error by returning NULL. +// error by returning NULL and setting errno. TEXT runtime·syscallPtr(SB),NOSPLIT,$0 MOVW.W R0, -4(R13) // push structure pointer MOVW 0(R0), R12 // fn diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s index 29951d8ad7..89a2b8a054 100644 --- a/src/runtime/sys_darwin_arm64.s +++ b/src/runtime/sys_darwin_arm64.s @@ -465,9 +465,9 @@ TEXT runtime·syscallX(SB),NOSPLIT,$0 ok: RET -// syscallXPtr is like syscallX except that the libc function reports an -// error by returning NULL. -TEXT runtime·syscallXPtr(SB),NOSPLIT,$0 +// syscallPtr is like syscallX except that the libc function reports an +// error by returning NULL and setting errno. +TEXT runtime·syscallPtr(SB),NOSPLIT,$0 SUB $16, RSP // push structure pointer MOVD R0, (RSP) |
