Skip to content

Commit be5f646

Browse files
committed
internal/syscall/unix: use libc calls on Darwin
Add unexported unlinkat, openat, and fstatat calls, so that the internal/syscall/unix package can use them. Change-Id: I1df81ecae6427211dd392ec68c9f020fe131a526 Reviewed-on: https://go-review.googlesource.com/c/148457 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
1 parent d0a91f2 commit be5f646

12 files changed

+305
-9
lines changed

src/internal/syscall/unix/at.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build linux darwin openbsd netbsd dragonfly
5+
// +build linux openbsd netbsd dragonfly
66

77
package unix
88

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package unix
6+
7+
import (
8+
"syscall"
9+
_ "unsafe" // for linkname
10+
)
11+
12+
func Unlinkat(dirfd int, path string, flags int) error {
13+
return unlinkat(dirfd, path, flags)
14+
}
15+
16+
func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
17+
return openat(dirfd, path, flags, perm)
18+
}
19+
20+
func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
21+
return fstatat(dirfd, path, stat, flags)
22+
}
23+
24+
//go:linkname unlinkat syscall.unlinkat
25+
func unlinkat(dirfd int, path string, flags int) error
26+
27+
//go:linkname openat syscall.openat
28+
func openat(dirfd int, path string, flags int, perm uint32) (int, error)
29+
30+
//go:linkname fstatat syscall.fstatat
31+
func fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error

src/runtime/sys_darwin_arm64.s

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ ok:
483483
// C calling convention (use libcCall).
484484
TEXT runtime·syscall6(SB),NOSPLIT,$0
485485
SUB $16, RSP // push structure pointer
486-
MOVD R0, (RSP)
486+
MOVD R0, 8(RSP)
487487

488488
MOVD 0(R0), R12 // fn
489489
MOVD 16(R0), R1 // a2
@@ -492,19 +492,25 @@ TEXT runtime·syscall6(SB),NOSPLIT,$0
492492
MOVD 40(R0), R4 // a5
493493
MOVD 48(R0), R5 // a6
494494
MOVD 8(R0), R0 // a1
495+
496+
// If fn is declared as vararg, we have to pass the vararg arguments on the stack.
497+
// See syscall above. The only function this applies to is openat, for which the 4th
498+
// arg must be on the stack.
499+
MOVD R3, (RSP)
500+
495501
BL (R12)
496502

497-
MOVD (RSP), R2 // pop structure pointer
503+
MOVD 8(RSP), R2 // pop structure pointer
498504
ADD $16, RSP
499505
MOVD R0, 56(R2) // save r1
500506
MOVD R1, 64(R2) // save r2
501507
CMPW $-1, R0
502508
BNE ok
503509
SUB $16, RSP // push structure pointer
504-
MOVD R2, (RSP)
510+
MOVD R2, 8(RSP)
505511
BL libc_error(SB)
506512
MOVW (R0), R0
507-
MOVD (RSP), R2 // pop structure pointer
513+
MOVD 8(RSP), R2 // pop structure pointer
508514
ADD $16, RSP
509515
MOVD R0, 72(R2) // save err
510516
ok:

src/syscall/syscall_darwin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
344344
//sysnb exit(res int) (err error)
345345
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error)
346346
//sys fcntlPtr(fd int, cmd int, arg unsafe.Pointer) (val int, err error) = SYS_fcntl
347+
//sys unlinkat(fd int, path string, flags int) (err error)
348+
//sys openat(fd int, path string, flags int, perm uint32) (fdret int, err error)
349+
//sys fstatat(fd int, path string, stat *Stat_t, flags int) (err error) = SYS_fstatat64
347350

348351
func init() {
349352
execveDarwin = execve

src/syscall/zsyscall_darwin_386.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_darwin_386.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,11 @@ TEXT ·libc_exit_trampoline(SB),NOSPLIT,$0-0
239239
JMP libc_exit(SB)
240240
TEXT ·libc_sysctl_trampoline(SB),NOSPLIT,$0-0
241241
JMP libc_sysctl(SB)
242+
TEXT ·libc_unlinkat_trampoline(SB),NOSPLIT,$0-0
243+
JMP libc_unlinkat(SB)
244+
TEXT ·libc_openat_trampoline(SB),NOSPLIT,$0-0
245+
JMP libc_openat(SB)
246+
TEXT ·libc_fstatat64_trampoline(SB),NOSPLIT,$0-0
247+
JMP libc_fstatat64(SB)
242248
TEXT ·libc_gettimeofday_trampoline(SB),NOSPLIT,$0-0
243249
JMP libc_gettimeofday(SB)

src/syscall/zsyscall_darwin_amd64.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_darwin_amd64.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,11 @@ TEXT ·libc_exit_trampoline(SB),NOSPLIT,$0-0
239239
JMP libc_exit(SB)
240240
TEXT ·libc_sysctl_trampoline(SB),NOSPLIT,$0-0
241241
JMP libc_sysctl(SB)
242+
TEXT ·libc_unlinkat_trampoline(SB),NOSPLIT,$0-0
243+
JMP libc_unlinkat(SB)
244+
TEXT ·libc_openat_trampoline(SB),NOSPLIT,$0-0
245+
JMP libc_openat(SB)
246+
TEXT ·libc_fstatat64_trampoline(SB),NOSPLIT,$0-0
247+
JMP libc_fstatat64(SB)
242248
TEXT ·libc_gettimeofday_trampoline(SB),NOSPLIT,$0-0
243249
JMP libc_gettimeofday(SB)

src/syscall/zsyscall_darwin_arm.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_darwin_arm.s

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ TEXT ·libc_unmount_trampoline(SB),NOSPLIT,$0-0
223223
JMP libc_unmount(SB)
224224
TEXT ·libc_write_trampoline(SB),NOSPLIT,$0-0
225225
JMP libc_write(SB)
226+
TEXT ·libc_writev_trampoline(SB),NOSPLIT,$0-0
227+
JMP libc_writev(SB)
226228
TEXT ·libc_mmap_trampoline(SB),NOSPLIT,$0-0
227229
JMP libc_mmap(SB)
228230
TEXT ·libc_munmap_trampoline(SB),NOSPLIT,$0-0
@@ -237,7 +239,11 @@ TEXT ·libc_exit_trampoline(SB),NOSPLIT,$0-0
237239
JMP libc_exit(SB)
238240
TEXT ·libc_sysctl_trampoline(SB),NOSPLIT,$0-0
239241
JMP libc_sysctl(SB)
240-
TEXT ·libc_writev_trampoline(SB),NOSPLIT,$0-0
241-
JMP libc_writev(SB)
242+
TEXT ·libc_unlinkat_trampoline(SB),NOSPLIT,$0-0
243+
JMP libc_unlinkat(SB)
244+
TEXT ·libc_openat_trampoline(SB),NOSPLIT,$0-0
245+
JMP libc_openat(SB)
246+
TEXT ·libc_fstatat64_trampoline(SB),NOSPLIT,$0-0
247+
JMP libc_fstatat64(SB)
242248
TEXT ·libc_gettimeofday_trampoline(SB),NOSPLIT,$0-0
243249
JMP libc_gettimeofday(SB)

src/syscall/zsyscall_darwin_arm64.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)