darwin: replace custom syscall package with Go native syscall package

This required a few compiler and runtime tricks to work, but I ran a
bunch of tests and it seems fine. (CI will of course do more exhaustive
testing).

The main benefit here is that we don't need to maintain the darwin
version of the syscall package, and reduce extra risks for bugs (because
we reuse the well-tested syscall package). For example, Go 1.23 needed a
bunch of new constants in the syscall package. That would have been
avoided if we had used the native syscall package on MacOS.
This commit is contained in:
Ayke van Laethem
2024-08-18 19:33:04 +02:00
committed by Ron Evans
parent 753f4b38b4
commit 105fe9b25d
19 changed files with 229 additions and 531 deletions
+4 -1
View File
@@ -135,7 +135,7 @@ func darwinOpenDir(fd syscallFd) (uintptr, string, error) {
}
var dir uintptr
for {
dir, err = syscall.Fdopendir(fd2)
dir, err = fdopendir(fd2)
if err != syscall.EINTR {
break
}
@@ -149,6 +149,9 @@ func darwinOpenDir(fd syscallFd) (uintptr, string, error) {
// Implemented in syscall/syscall_libc_darwin_*.go.
//go:linkname fdopendir syscall.fdopendir
func fdopendir(fd int) (dir uintptr, err error)
//go:linkname closedir syscall.closedir
func closedir(dir uintptr) (err error)
+7
View File
@@ -0,0 +1,7 @@
package os
import "syscall"
func pipe(p []int) error {
return syscall.Pipe(p)
}
+9
View File
@@ -0,0 +1,9 @@
//go:build (linux && !baremetal && !wasm_unknown) || wasip1 || wasip2
package os
import "syscall"
func pipe(p []int) error {
return syscall.Pipe2(p, syscall.O_CLOEXEC)
}
+1 -1
View File
@@ -70,7 +70,7 @@ func Truncate(name string, size int64) error {
func Pipe() (r *File, w *File, err error) {
var p [2]int
err = handleSyscallError(syscall.Pipe2(p[:], syscall.O_CLOEXEC))
err = handleSyscallError(pipe(p[:]))
if err != nil {
return
}