// Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build darwin
+// +build arm arm64
+
 package poll
 
 import (
 
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build darwin
+// +build arm arm64
+
 package os
 
 import (
 
        names = make([]string, 0, size)
        var dirent syscall.Dirent
-       var entptr *syscall.Dirent
-       for len(names) < size || n == -1 {
-               if res := readdir_r(d.dir, &dirent, &entptr); res != 0 {
+       var entptr uintptr
+       for len(names) < size {
+               if res := readdir_r(d.dir, uintptr(unsafe.Pointer(&dirent)), uintptr(unsafe.Pointer(&entptr))); res != 0 {
                        return names, wrapSyscallError("readdir", syscall.Errno(res))
                }
-               if entptr == nil { // EOF
+               if entptr == 0 { // EOF
                        break
                }
                if dirent.Ino == 0 {
 func closedir(dir uintptr) (err error)
 
 //go:linkname readdir_r syscall.readdir_r
-func readdir_r(dir uintptr, entry *syscall.Dirent, result **syscall.Dirent) (res int)
+func readdir_r(dir, entry, result uintptr) (res int)
 
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build aix dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
+// +build aix darwin,!arm,!arm64 dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
 
 package os
 
 
 }
 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
 
        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()
 
        POPL    BP
        RET
 
-// syscallPtr is like syscall except the libc function reports an
-// error by returning NULL and setting errno.
+// Not used on 386.
 TEXT runtime·syscallPtr(SB),NOSPLIT,$0
-       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
+       MOVL    $0xf1, 0xf1  // crash
        RET
 
 // syscall6 calls a function in libc on behalf of the syscall package.
 
        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()
 
        POPQ    BP
        RET
 
-// 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
+// Not used on amd64.
+TEXT runtime·syscallXPtr(SB),NOSPLIT,$0
+       MOVL    $0xf1, 0xf1  // crash
        RET
 
 // syscall6 calls a function in libc on behalf of the syscall package.
 
        RET
 
 // syscallPtr is like syscall except the libc function reports an
-// error by returning NULL and setting errno.
+// error by returning NULL.
 TEXT runtime·syscallPtr(SB),NOSPLIT,$0
        MOVW.W  R0, -4(R13)     // push structure pointer
        MOVW    0(R0), R12      // fn
 
 ok:
        RET
 
-// syscallPtr is like syscallX except that the libc function reports an
-// error by returning NULL and setting errno.
-TEXT runtime·syscallPtr(SB),NOSPLIT,$0
+// syscallXPtr is like syscallX except that the libc function reports an
+// error by returning NULL.
+TEXT runtime·syscallXPtr(SB),NOSPLIT,$0
        SUB     $16, RSP        // push structure pointer
        MOVD    R0, (RSP)
 
 
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin dragonfly freebsd netbsd openbsd
+// +build darwin,!arm,!arm64 dragonfly freebsd netbsd openbsd
 
 package syscall_test
 
 
                        $text .= "//go:linkname $funcname $funcname\n";
                        # Tell the linker that funcname can be found in libSystem using varname without the libc_ prefix.
                        my $basename = substr $funcname, 5;
-                       if($basename eq "readdir_r" && ($ENV{'GOARCH'} eq "386" || $ENV{'GOARCH'} eq "amd64")) {
-                           # Hack to make sure we get the 64-bit inode version on darwin/macOS.
-                           $basename .= "\$INODE64"
-                       }
                        $text .= "//go:cgo_import_dynamic $funcname $basename \"/usr/lib/libSystem.B.dylib\"\n";
                }
        }
 
 //sys  Chown(path string, uid int, gid int) (err error)
 //sys  Chroot(path string) (err error)
 //sys  Close(fd int) (err error)
-//sys  closedir(dir uintptr) (err error)
 //sys  Dup(fd int) (nfd int, err error)
 //sys  Dup2(from int, to int) (err error)
 //sys  Exchangedata(path1 string, path2 string, options 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)
 //sys  Rename(from string, to string) (err error)
 //sys  Revoke(path string) (err error)
        return
 }
 
-func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
-       // Simulate Getdirentries using fdopendir/readdir_r/closedir.
-       const ptrSize = unsafe.Sizeof(uintptr(0))
-       fd2, err := Dup(fd)
-       if err != nil {
-               return 0, err
-       }
-       d, err := fdopendir(fd2)
-       if err != nil {
-               Close(fd2)
-               return 0, err
-       }
-       defer closedir(d)
-       // We keep the number of records already returned in *basep.
-       // It's not the full required semantics, but should handle the case
-       // of calling Getdirentries repeatedly.
-       // It won't handle assigning the results of lseek to *basep, or handle
-       // the directory being edited underfoot.
-       skip := *basep
-       *basep = 0
-       for {
-               var entry Dirent
-               var entryp *Dirent
-               e := readdir_r(d, &entry, &entryp)
-               if e != 0 {
-                       return n, errnoErr(e)
-               }
-               if entryp == nil {
-                       break
-               }
-               if skip > 0 {
-                       skip--
-                       *basep++
-                       continue
-               }
-               reclen := int(entry.Reclen)
-               if reclen > len(buf) {
-                       // Not enough room. Return for now.
-                       // *basep will let us know where we should start up again.
-                       // Note: this strategy for suspending in the middle and
-                       // restarting is O(n^2) in the length of the directory. Oh well.
-                       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)))
-               buf = buf[reclen:]
-               n += reclen
-               *basep++
-       }
-       return n, nil
-}
-
 // Implemented in the runtime package (runtime/sys_darwin.go)
 func syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
 func syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
 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.
 
 
 //sys  Fstat(fd int, stat *Stat_t) (err error) = SYS_fstat64
 //sys  Fstatfs(fd int, stat *Statfs_t) (err error) = SYS_fstatfs64
+//sys  Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) = SYS___getdirentries64
 //sysnb        Gettimeofday(tp *Timeval) (err error)
 //sys  Lstat(path string, stat *Stat_t) (err error) = SYS_lstat64
 //sys  Stat(path string, stat *Stat_t) (err error) = SYS_stat64
 //go:linkname libc_sendfile libc_sendfile
 //go:cgo_import_dynamic libc_sendfile sendfile "/usr/lib/libSystem.B.dylib"
 
-func fdopendir(fd int) (dir uintptr, err error) {
-       r0, _, e1 := syscallPtr(funcPC(libc_fdopendir_trampoline), uintptr(fd), 0, 0)
-       dir = uintptr(r0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-func libc_fdopendir_trampoline()
-
-//go:linkname libc_fdopendir libc_fdopendir
-//go:cgo_import_dynamic libc_fdopendir fdopendir "/usr/lib/libSystem.B.dylib"
-
 // Implemented in the runtime package (runtime/sys_darwin_32.go)
 func syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
 
 
 
 //sys  Fstat(fd int, stat *Stat_t) (err error) = SYS_fstat64
 //sys  Fstatfs(fd int, stat *Statfs_t) (err error) = SYS_fstatfs64
+//sys  Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) = SYS___getdirentries64
 //sysnb        Gettimeofday(tp *Timeval) (err error)
 //sys  Lstat(path string, stat *Stat_t) (err error) = SYS_lstat64
 //sys  Stat(path string, stat *Stat_t) (err error) = SYS_stat64
 //go:linkname libc_sendfile libc_sendfile
 //go:cgo_import_dynamic libc_sendfile sendfile "/usr/lib/libSystem.B.dylib"
 
-func fdopendir(fd int) (dir uintptr, err error) {
-       r0, _, e1 := syscallPtr(funcPC(libc_fdopendir_trampoline), uintptr(fd), 0, 0)
-       dir = uintptr(r0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-func libc_fdopendir_trampoline()
-
-//go:linkname libc_fdopendir libc_fdopendir
-//go:cgo_import_dynamic libc_fdopendir fdopendir$INODE64 "/usr/lib/libSystem.B.dylib"
-
 // Implemented in the runtime package (runtime/sys_darwin_64.go)
 func syscallX(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
 
 
        return Timeval{Sec: int32(sec), Usec: int32(usec)}
 }
 
+//sys  closedir(dir uintptr) (err error)
 //sys  Fstat(fd int, stat *Stat_t) (err error)
 //sys  Fstatfs(fd int, stat *Statfs_t) (err error)
 //sysnb        Gettimeofday(tp *Timeval) (err error)
 //sys  Lstat(path string, stat *Stat_t) (err error)
+//sys  readdir_r(dir uintptr, entry uintptr, result uintptr) (res int)
 //sys  Stat(path string, stat *Stat_t) (err error)
 //sys  Statfs(path string, stat *Statfs_t) (err error)
 //sys   fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
 
+func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
+       return 0, ENOSYS
+}
+
 func SetKevent(k *Kevent_t, fd, mode, flags int) {
        k.Ident = uint32(fd)
        k.Filter = int16(mode)
 //go:cgo_import_dynamic libc_fdopendir fdopendir "/usr/lib/libSystem.B.dylib"
 
 // Implemented in the runtime package (runtime/sys_darwin_32.go)
+func syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
 func syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
 
 func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic
 
        return Timeval{Sec: int64(sec), Usec: int32(usec)}
 }
 
+//sys  closedir(dir uintptr) (err error)
 //sys  Fstat(fd int, stat *Stat_t) (err error)
 //sys  Fstatfs(fd int, stat *Statfs_t) (err error)
 //sysnb        Gettimeofday(tp *Timeval) (err error)
 //sys  Lstat(path string, stat *Stat_t) (err error)
+//sys  readdir_r(dirp uintptr, entry uintptr, result uintptr) (res int)
 //sys  Stat(path string, stat *Stat_t) (err error)
 //sys  Statfs(path string, stat *Statfs_t) (err error)
 //sys   fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
 
+func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
+       return 0, ENOSYS
+}
+
 func SetKevent(k *Kevent_t, fd, mode, flags int) {
        k.Ident = uint64(fd)
        k.Filter = int16(mode)
 //go:cgo_import_dynamic libc_sendfile sendfile "/usr/lib/libSystem.B.dylib"
 
 func fdopendir(fd int) (dir uintptr, err error) {
-       r0, _, e1 := syscallPtr(funcPC(libc_fdopendir_trampoline), uintptr(fd), 0, 0)
+       r0, _, e1 := syscallXPtr(funcPC(libc_fdopendir_trampoline), uintptr(fd), 0, 0)
        dir = uintptr(r0)
        if e1 != 0 {
                err = errnoErr(e1)
 
 // Implemented in the runtime package (runtime/sys_darwin_64.go)
 func syscallX(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
+func syscallXPtr(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
 
 func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic
 
 //go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func closedir(dir uintptr) (err error) {
-       _, _, e1 := syscall(funcPC(libc_closedir_trampoline), uintptr(dir), 0, 0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-func libc_closedir_trampoline()
-
-//go:linkname libc_closedir libc_closedir
-//go:cgo_import_dynamic libc_closedir closedir "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Dup(fd int) (nfd int, err error) {
        r0, _, e1 := syscall(funcPC(libc_dup_trampoline), uintptr(fd), 0, 0)
        nfd = int(r0)
 //go:cgo_import_dynamic libc_read read "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno) {
-       r0, _, _ := syscall(funcPC(libc_readdir_r_trampoline), uintptr(dir), uintptr(unsafe.Pointer(entry)), uintptr(unsafe.Pointer(result)))
-       res = Errno(r0)
-       return
-}
-
-func libc_readdir_r_trampoline()
-
-//go:linkname libc_readdir_r libc_readdir_r
-//go:cgo_import_dynamic libc_readdir_r readdir_r$INODE64 "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Readlink(path string, buf []byte) (n int, err error) {
        var _p0 *byte
        _p0, err = BytePtrFromString(path)
 //go:cgo_import_dynamic libc_fstatfs64 fstatfs64 "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
+       var _p0 unsafe.Pointer
+       if len(buf) > 0 {
+               _p0 = unsafe.Pointer(&buf[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := syscall6(funcPC(libc___getdirentries64_trampoline), uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0)
+       n = int(r0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+func libc___getdirentries64_trampoline()
+
+//go:linkname libc___getdirentries64 libc___getdirentries64
+//go:cgo_import_dynamic libc___getdirentries64 __getdirentries64 "/usr/lib/libSystem.B.dylib"
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Gettimeofday(tp *Timeval) (err error) {
        _, _, e1 := rawSyscall(funcPC(libc_gettimeofday_trampoline), uintptr(unsafe.Pointer(tp)), 0, 0)
        if e1 != 0 {
 
        JMP     libc_setattrlist(SB)
 TEXT ·libc_sendfile_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_sendfile(SB)
-TEXT ·libc_fdopendir_trampoline(SB),NOSPLIT,$0-0
-       JMP     libc_fdopendir(SB)
 TEXT ·libc_getgroups_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_getgroups(SB)
 TEXT ·libc_setgroups_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_chroot(SB)
 TEXT ·libc_close_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_close(SB)
-TEXT ·libc_closedir_trampoline(SB),NOSPLIT,$0-0
-       JMP     libc_closedir(SB)
 TEXT ·libc_dup_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_dup(SB)
 TEXT ·libc_dup2_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_pwrite(SB)
 TEXT ·libc_read_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_read(SB)
-TEXT ·libc_readdir_r_trampoline(SB),NOSPLIT,$0-0
-       JMP     libc_readdir_r(SB)
 TEXT ·libc_readlink_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_readlink(SB)
 TEXT ·libc_rename_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_fstat64(SB)
 TEXT ·libc_fstatfs64_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_fstatfs64(SB)
+TEXT ·libc___getdirentries64_trampoline(SB),NOSPLIT,$0-0
+       JMP     libc___getdirentries64(SB)
 TEXT ·libc_gettimeofday_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_gettimeofday(SB)
 TEXT ·libc_lstat64_trampoline(SB),NOSPLIT,$0-0
 
 //go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func closedir(dir uintptr) (err error) {
-       _, _, e1 := syscall(funcPC(libc_closedir_trampoline), uintptr(dir), 0, 0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-func libc_closedir_trampoline()
-
-//go:linkname libc_closedir libc_closedir
-//go:cgo_import_dynamic libc_closedir closedir "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Dup(fd int) (nfd int, err error) {
        r0, _, e1 := syscall(funcPC(libc_dup_trampoline), uintptr(fd), 0, 0)
        nfd = int(r0)
 //go:cgo_import_dynamic libc_read read "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno) {
-       r0, _, _ := syscall(funcPC(libc_readdir_r_trampoline), uintptr(dir), uintptr(unsafe.Pointer(entry)), uintptr(unsafe.Pointer(result)))
-       res = Errno(r0)
-       return
-}
-
-func libc_readdir_r_trampoline()
-
-//go:linkname libc_readdir_r libc_readdir_r
-//go:cgo_import_dynamic libc_readdir_r readdir_r$INODE64 "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Readlink(path string, buf []byte) (n int, err error) {
        var _p0 *byte
        _p0, err = BytePtrFromString(path)
 //go:cgo_import_dynamic libc_fstatfs64 fstatfs64 "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
+       var _p0 unsafe.Pointer
+       if len(buf) > 0 {
+               _p0 = unsafe.Pointer(&buf[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := syscall6(funcPC(libc___getdirentries64_trampoline), uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0)
+       n = int(r0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+func libc___getdirentries64_trampoline()
+
+//go:linkname libc___getdirentries64 libc___getdirentries64
+//go:cgo_import_dynamic libc___getdirentries64 __getdirentries64 "/usr/lib/libSystem.B.dylib"
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Gettimeofday(tp *Timeval) (err error) {
        _, _, e1 := rawSyscall(funcPC(libc_gettimeofday_trampoline), uintptr(unsafe.Pointer(tp)), 0, 0)
        if e1 != 0 {
 
        JMP     libc_setattrlist(SB)
 TEXT ·libc_sendfile_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_sendfile(SB)
-TEXT ·libc_fdopendir_trampoline(SB),NOSPLIT,$0-0
-       JMP     libc_fdopendir(SB)
 TEXT ·libc_getgroups_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_getgroups(SB)
 TEXT ·libc_setgroups_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_chroot(SB)
 TEXT ·libc_close_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_close(SB)
-TEXT ·libc_closedir_trampoline(SB),NOSPLIT,$0-0
-       JMP     libc_closedir(SB)
 TEXT ·libc_dup_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_dup(SB)
 TEXT ·libc_dup2_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_pwrite(SB)
 TEXT ·libc_read_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_read(SB)
-TEXT ·libc_readdir_r_trampoline(SB),NOSPLIT,$0-0
-       JMP     libc_readdir_r(SB)
 TEXT ·libc_readlink_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_readlink(SB)
 TEXT ·libc_rename_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_fstat64(SB)
 TEXT ·libc_fstatfs64_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_fstatfs64(SB)
+TEXT ·libc___getdirentries64_trampoline(SB),NOSPLIT,$0-0
+       JMP     libc___getdirentries64(SB)
 TEXT ·libc_gettimeofday_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_gettimeofday(SB)
 TEXT ·libc_lstat64_trampoline(SB),NOSPLIT,$0-0
 
 //go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func closedir(dir uintptr) (err error) {
-       _, _, e1 := syscall(funcPC(libc_closedir_trampoline), uintptr(dir), 0, 0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-func libc_closedir_trampoline()
-
-//go:linkname libc_closedir libc_closedir
-//go:cgo_import_dynamic libc_closedir closedir "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Dup(fd int) (nfd int, err error) {
        r0, _, e1 := syscall(funcPC(libc_dup_trampoline), uintptr(fd), 0, 0)
        nfd = int(r0)
 //go:cgo_import_dynamic libc_read read "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno) {
-       r0, _, _ := syscall(funcPC(libc_readdir_r_trampoline), uintptr(dir), uintptr(unsafe.Pointer(entry)), uintptr(unsafe.Pointer(result)))
-       res = Errno(r0)
-       return
-}
-
-func libc_readdir_r_trampoline()
-
-//go:linkname libc_readdir_r libc_readdir_r
-//go:cgo_import_dynamic libc_readdir_r readdir_r "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Readlink(path string, buf []byte) (n int, err error) {
        var _p0 *byte
        _p0, err = BytePtrFromString(path)
 //go:cgo_import_dynamic libc_openat openat "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func closedir(dir uintptr) (err error) {
+       _, _, e1 := syscall(funcPC(libc_closedir_trampoline), uintptr(dir), 0, 0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+func libc_closedir_trampoline()
+
+//go:linkname libc_closedir libc_closedir
+//go:cgo_import_dynamic libc_closedir closedir "/usr/lib/libSystem.B.dylib"
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Fstat(fd int, stat *Stat_t) (err error) {
        _, _, e1 := syscall(funcPC(libc_fstat_trampoline), uintptr(fd), uintptr(unsafe.Pointer(stat)), 0)
        if e1 != 0 {
 //go:cgo_import_dynamic libc_lstat lstat "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func readdir_r(dir uintptr, entry uintptr, result uintptr) (res int) {
+       r0, _, _ := syscall(funcPC(libc_readdir_r_trampoline), uintptr(dir), uintptr(entry), uintptr(result))
+       res = int(r0)
+       return
+}
+
+func libc_readdir_r_trampoline()
+
+//go:linkname libc_readdir_r libc_readdir_r
+//go:cgo_import_dynamic libc_readdir_r readdir_r "/usr/lib/libSystem.B.dylib"
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Stat(path string, stat *Stat_t) (err error) {
        var _p0 *byte
        _p0, err = BytePtrFromString(path)
 
 //go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func closedir(dir uintptr) (err error) {
-       _, _, e1 := syscall(funcPC(libc_closedir_trampoline), uintptr(dir), 0, 0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-func libc_closedir_trampoline()
-
-//go:linkname libc_closedir libc_closedir
-//go:cgo_import_dynamic libc_closedir closedir "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Dup(fd int) (nfd int, err error) {
        r0, _, e1 := syscall(funcPC(libc_dup_trampoline), uintptr(fd), 0, 0)
        nfd = int(r0)
 //go:cgo_import_dynamic libc_read read "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno) {
-       r0, _, _ := syscall(funcPC(libc_readdir_r_trampoline), uintptr(dir), uintptr(unsafe.Pointer(entry)), uintptr(unsafe.Pointer(result)))
-       res = Errno(r0)
-       return
-}
-
-func libc_readdir_r_trampoline()
-
-//go:linkname libc_readdir_r libc_readdir_r
-//go:cgo_import_dynamic libc_readdir_r readdir_r "/usr/lib/libSystem.B.dylib"
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Readlink(path string, buf []byte) (n int, err error) {
        var _p0 *byte
        _p0, err = BytePtrFromString(path)
 //go:cgo_import_dynamic libc_openat openat "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func closedir(dir uintptr) (err error) {
+       _, _, e1 := syscall(funcPC(libc_closedir_trampoline), uintptr(dir), 0, 0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+func libc_closedir_trampoline()
+
+//go:linkname libc_closedir libc_closedir
+//go:cgo_import_dynamic libc_closedir closedir "/usr/lib/libSystem.B.dylib"
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Fstat(fd int, stat *Stat_t) (err error) {
        _, _, e1 := syscall(funcPC(libc_fstat_trampoline), uintptr(fd), uintptr(unsafe.Pointer(stat)), 0)
        if e1 != 0 {
 //go:cgo_import_dynamic libc_lstat lstat "/usr/lib/libSystem.B.dylib"
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func readdir_r(dirp uintptr, entry uintptr, result uintptr) (res int) {
+       r0, _, _ := syscall(funcPC(libc_readdir_r_trampoline), uintptr(dirp), uintptr(entry), uintptr(result))
+       res = int(r0)
+       return
+}
+
+func libc_readdir_r_trampoline()
+
+//go:linkname libc_readdir_r libc_readdir_r
+//go:cgo_import_dynamic libc_readdir_r readdir_r "/usr/lib/libSystem.B.dylib"
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Stat(path string, stat *Stat_t) (err error) {
        var _p0 *byte
        _p0, err = BytePtrFromString(path)