]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/syscall/syscall_darwin.go
syscall: provide and use ioctlPtr for all BSD platforms
[gostls13.git] / src / syscall / syscall_darwin.go
index 162e94479fa3143a2c4cf4edcef65cfccaae92f9..2e13b57cd32e759a0df6476185af22da2c84e80b 100644 (file)
 
 package syscall
 
-import "unsafe"
+import (
+       "internal/abi"
+       "unsafe"
+)
+
+func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
+func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
+func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
+func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
+
+var dupTrampoline = abi.FuncPCABI0(libc_dup2_trampoline)
 
 type SockaddrDatalink struct {
        Len    uint8
@@ -69,22 +79,6 @@ func direntNamlen(buf []byte) (uint64, bool) {
 func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) }
 func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) }
 
-const (
-       attrBitMapCount = 5
-       attrCmnModtime  = 0x00000400
-       attrCmnAcctime  = 0x00001000
-)
-
-type attrList struct {
-       bitmapCount uint16
-       _           uint16
-       CommonAttr  uint32
-       VolAttr     uint32
-       DirAttr     uint32
-       FileAttr    uint32
-       Forkattr    uint32
-}
-
 //sysnb pipe(p *[2]int32) (err error)
 
 func Pipe(p []int) (err error) {
@@ -93,8 +87,10 @@ func Pipe(p []int) (err error) {
        }
        var q [2]int32
        err = pipe(&q)
-       p[0] = int(q[0])
-       p[1] = int(q[1])
+       if err == nil {
+               p[0] = int(q[0])
+               p[1] = int(q[1])
+       }
        return
 }
 
@@ -105,7 +101,7 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
                _p0 = unsafe.Pointer(&buf[0])
                bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
        }
-       r0, _, e1 := syscall(funcPC(libc_getfsstat_trampoline), uintptr(_p0), bufsize, uintptr(flags))
+       r0, _, e1 := syscall(abi.FuncPCABI0(libc_getfsstat_trampoline), uintptr(_p0), bufsize, uintptr(flags))
        n = int(r0)
        if e1 != 0 {
                err = e1
@@ -117,42 +113,7 @@ func libc_getfsstat_trampoline()
 
 //go:cgo_import_dynamic libc_getfsstat getfsstat "/usr/lib/libSystem.B.dylib"
 
-func setattrlistTimes(path string, times []Timespec) error {
-       _p0, err := BytePtrFromString(path)
-       if err != nil {
-               return err
-       }
-
-       var attrList attrList
-       attrList.bitmapCount = attrBitMapCount
-       attrList.CommonAttr = attrCmnModtime | attrCmnAcctime
-
-       // order is mtime, atime: the opposite of Chtimes
-       attributes := [2]Timespec{times[1], times[0]}
-       const options = 0
-       _, _, e1 := syscall6(
-               funcPC(libc_setattrlist_trampoline),
-               uintptr(unsafe.Pointer(_p0)),
-               uintptr(unsafe.Pointer(&attrList)),
-               uintptr(unsafe.Pointer(&attributes)),
-               uintptr(unsafe.Sizeof(attributes)),
-               uintptr(options),
-               0,
-       )
-       if e1 != 0 {
-               return e1
-       }
-       return nil
-}
-
-func libc_setattrlist_trampoline()
-
-//go:cgo_import_dynamic libc_setattrlist setattrlist "/usr/lib/libSystem.B.dylib"
-
-func utimensat(dirfd int, path string, times *[2]Timespec, flag int) error {
-       // Darwin doesn't support SYS_UTIMENSAT
-       return ENOSYS
-}
+//sys  utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
 
 /*
  * Wrapped
@@ -210,12 +171,13 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
 //sys  Mlock(b []byte) (err error)
 //sys  Mlockall(flags int) (err error)
 //sys  Mprotect(b []byte, prot int) (err error)
+//sys  msync(b []byte, flags int) (err error)
 //sys  Munlock(b []byte) (err error)
 //sys  Munlockall() (err error)
 //sys  Open(path string, mode int, perm uint32) (fd int, err error)
 //sys  Pathconf(path string, name int) (val int, err error)
-//sys  Pread(fd int, p []byte, offset int64) (n int, err error)
-//sys  Pwrite(fd int, p []byte, offset int64) (n int, err error)
+//sys  pread(fd int, p []byte, offset int64) (n int, err error)
+//sys  pwrite(fd int, p []byte, offset int64) (n int, err error)
 //sys  read(fd int, p []byte) (n int, err error)
 //sys  readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno)
 //sys  Readlink(path string, buf []byte) (n int, err error)
@@ -233,7 +195,7 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
 //sys  Setprivexec(flag int) (err error)
 //sysnb        Setregid(rgid int, egid int) (err error)
 //sysnb        Setreuid(ruid int, euid int) (err error)
-//sysnb        Setrlimit(which int, lim *Rlimit) (err error)
+//sysnb        setrlimit(which int, lim *Rlimit) (err error)
 //sysnb        Setsid() (pid int, err error)
 //sysnb        Settimeofday(tp *Timeval) (err error)
 //sysnb        Setuid(uid int) (err error)
@@ -249,12 +211,9 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
 //sys   mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
 //sys   munmap(addr uintptr, length uintptr) (err error)
 //sysnb fork() (pid int, err error)
-//sysnb ioctl(fd int, req int, arg int) (err error)
-//sysnb ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_ioctl
 //sysnb execve(path *byte, argv **byte, envp **byte) (err error)
 //sysnb exit(res int) (err error)
 //sys  sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error)
-//sys  fcntlPtr(fd int, cmd int, arg unsafe.Pointer) (val int, err error) = SYS_fcntl
 //sys   unlinkat(fd int, path string, flags int) (err error)
 //sys   openat(fd int, path string, flags int, perm uint32) (fdret int, err error)
 //sys  getcwd(buf []byte) (n int, err error)
@@ -264,8 +223,8 @@ func init() {
 }
 
 func fdopendir(fd int) (dir uintptr, err error) {
-       r0, _, e1 := syscallPtr(funcPC(libc_fdopendir_trampoline), uintptr(fd), 0, 0)
-       dir = uintptr(r0)
+       r0, _, e1 := syscallPtr(abi.FuncPCABI0(libc_fdopendir_trampoline), uintptr(fd), 0, 0)
+       dir = r0
        if e1 != 0 {
                err = errnoErr(e1)
        }
@@ -277,16 +236,7 @@ func libc_fdopendir_trampoline()
 //go:cgo_import_dynamic libc_fdopendir fdopendir "/usr/lib/libSystem.B.dylib"
 
 func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
-       r0, _, e1 := syscall(funcPC(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
-       n = int(r0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-func writelen(fd int, buf *byte, nbuf int) (n int, err error) {
-       r0, _, e1 := syscall(funcPC(libc_write_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
+       r0, _, e1 := syscall(abi.FuncPCABI0(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
        n = int(r0)
        if e1 != 0 {
                err = errnoErr(e1)
@@ -349,12 +299,7 @@ func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
                        break
                }
                // Copy entry into return buffer.
-               s := struct {
-                       ptr unsafe.Pointer
-                       siz int
-                       cap int
-               }{ptr: unsafe.Pointer(&entry), siz: reclen, cap: reclen}
-               copy(buf, *(*[]byte)(unsafe.Pointer(&s)))
+               copy(buf, unsafe.Slice((*byte)(unsafe.Pointer(&entry)), reclen))
                buf = buf[reclen:]
                n += reclen
                cnt++
@@ -376,10 +321,3 @@ func syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
 func rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
 func rawSyscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
 func syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
-
-// Find the entry point for f. See comments in runtime/proc.go for the
-// function of the same name.
-//go:nosplit
-func funcPC(f func()) uintptr {
-       return **(**uintptr)(unsafe.Pointer(&f))
-}