Source File
syscall_darwin.go
Belonging Package
golang.org/x/sys/unix
// Copyright 2009,2010 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Darwin system calls.// This file is compiled as ordinary Go code,// but it is also input to mksyscall,// which parses the //sys lines and generates system call stubs.// Note that sometimes we use a lowercase //sys name and wrap// it in our own nicer implementation, either here or in// syscall_bsd.go or syscall_unix.go.package uniximport ()const ImplementsGetwd = truefunc () (string, error) {:= make([]byte, 2048), := getAttrList(".", attrList{CommonAttr: attrCmnFullpath}, , 0)if == nil && len() == 1 && len([0]) >= 2 {:= string([0])// Sanity check that it's an absolute path and ends// in a null byte, which we then strip.if [0] == '/' && [len()-1] == 0 {return [:len()-1], nil}}// If pkg/os/getwd.go gets ENOTSUP, it will fall back to the// slow algorithm.return "", ENOTSUP}// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.type SockaddrDatalink struct {Len uint8Family uint8Index uint16Type uint8Nlen uint8Alen uint8Slen uint8Data [12]int8raw RawSockaddrDatalink}// Translate "kern.hostname" to []_C_int{0,1,2,3}.func ( string) ( []_C_int, error) {const = unsafe.Sizeof([0])// NOTE(rsc): It seems strange to set the buffer to have// size CTL_MAXNAME+2 but use only CTL_MAXNAME// as the size. I don't know why the +2 is here, but the// kernel uses +2 for its own implementation of this function.// I am scared that if we don't include the +2 here, the kernel// will silently write 2 words farther than we specify// and we'll get memory corruption.var [CTL_MAXNAME + 2]_C_int:= uintptr(CTL_MAXNAME) *:= (*byte)(unsafe.Pointer(&[0])), := ByteSliceFromString()if != nil {return nil,}// Magic sysctl: "setting" 0.3 to a string name// lets you read back the array of integers form.if = sysctl([]_C_int{0, 3}, , &, &[0], uintptr(len())); != nil {return nil,}return [0 : /], nil}func ( []byte) (uint64, bool) {return readInt(, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))}func ( []byte) (uint64, bool) {return readInt(, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))}func ( []byte) (uint64, bool) {return readInt(, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))}func ( int) ( error) { return ptrace(PT_ATTACH, , 0, 0) }func ( int) ( error) { return ptrace(PT_DETACH, , 0, 0) }const (attrBitMapCount = 5attrCmnFullpath = 0x08000000)type attrList struct {bitmapCount uint16_ uint16CommonAttr uint32VolAttr uint32DirAttr uint32FileAttr uint32Forkattr uint32}func ( string, attrList, []byte, uint) ( [][]byte, error) {if len() < 4 {return nil, errors.New("attrBuf too small")}.bitmapCount = attrBitMapCountvar *byte, = BytePtrFromString()if != nil {return nil,}if := getattrlist(, unsafe.Pointer(&), unsafe.Pointer(&[0]), uintptr(len()), int()); != nil {return nil,}:= *(*uint32)(unsafe.Pointer(&[0]))// dat is the section of attrBuf that contains valid data,// without the 4 byte length header. All attribute offsets// are relative to dat.:=if int() < len() {= [:]}= [4:] // remove length prefixfor := uint32(0); int() < len(); {:= [:]if len() < 8 {return , errors.New("truncated attribute header")}:= *(*int32)(unsafe.Pointer(&[0])):= *(*uint32)(unsafe.Pointer(&[4]))if < 0 || uint32()+ > uint32(len()) {return , errors.New("truncated results; attrBuf too small")}:= uint32() += append(, [:])=if := % 4; != 0 {+= (4 - )}}return}//sys getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error)//sysnb pipe() (r int, w int, err error)func ( []int) ( error) {if len() != 2 {return EINVAL}[0], [1], = pipe()return}func ( []Statfs_t, int) ( int, error) {var unsafe.Pointervar uintptrif len() > 0 {= unsafe.Pointer(&[0])= unsafe.Sizeof(Statfs_t{}) * uintptr(len())}return getfsstat(, , )}func ( []byte) *byte {// It's only when dest is set to NULL that the OS X implementations of// getxattr() and listxattr() return the current sizes of the named attributes.// An empty byte array is not sufficient. To maintain the same behaviour as the// linux implementation, we wrap around the system calls and pass in NULL when// dest is empty.var *byteif len() > 0 {= &[0]}return}//sys getxattr(path string, attr string, dest *byte, size int, position uint32, options int) (sz int, err error)func ( string, string, []byte) ( int, error) {return getxattr(, , xattrPointer(), len(), 0, 0)}func ( string, string, []byte) ( int, error) {return getxattr(, , xattrPointer(), len(), 0, XATTR_NOFOLLOW)}//sys fgetxattr(fd int, attr string, dest *byte, size int, position uint32, options int) (sz int, err error)func ( int, string, []byte) ( int, error) {return fgetxattr(, , xattrPointer(), len(), 0, 0)}//sys setxattr(path string, attr string, data *byte, size int, position uint32, options int) (err error)func ( string, string, []byte, int) ( error) {// The parameters for the OS X implementation vary slightly compared to the// linux system call, specifically the position parameter://// linux:// int setxattr(// const char *path,// const char *name,// const void *value,// size_t size,// int flags// );//// darwin:// int setxattr(// const char *path,// const char *name,// void *value,// size_t size,// u_int32_t position,// int options// );//// position specifies the offset within the extended attribute. In the// current implementation, only the resource fork extended attribute makes// use of this argument. For all others, position is reserved. We simply// default to setting it to zero.return setxattr(, , xattrPointer(), len(), 0, )}func ( string, string, []byte, int) ( error) {return setxattr(, , xattrPointer(), len(), 0, |XATTR_NOFOLLOW)}//sys fsetxattr(fd int, attr string, data *byte, size int, position uint32, options int) (err error)func ( int, string, []byte, int) ( error) {return fsetxattr(, , xattrPointer(), len(), 0, 0)}//sys removexattr(path string, attr string, options int) (err error)func ( string, string) ( error) {// We wrap around and explicitly zero out the options provided to the OS X// implementation of removexattr, we do so for interoperability with the// linux variant.return removexattr(, , 0)}func ( string, string) ( error) {return removexattr(, , XATTR_NOFOLLOW)}//sys fremovexattr(fd int, attr string, options int) (err error)func ( int, string) ( error) {return fremovexattr(, , 0)}//sys listxattr(path string, dest *byte, size int, options int) (sz int, err error)func ( string, []byte) ( int, error) {return listxattr(, xattrPointer(), len(), 0)}func ( string, []byte) ( int, error) {return listxattr(, xattrPointer(), len(), XATTR_NOFOLLOW)}//sys flistxattr(fd int, dest *byte, size int, options int) (sz int, err error)func ( int, []byte) ( int, error) {return flistxattr(, xattrPointer(), len(), 0)}func ( string, []Timespec, int) error {, := BytePtrFromString()if != nil {return}var attrList.bitmapCount = ATTR_BIT_MAP_COUNT.CommonAttr = ATTR_CMN_MODTIME | ATTR_CMN_ACCTIME// order is mtime, atime: the opposite of Chtimes:= [2]Timespec{[1], [0]}:= 0if &AT_SYMLINK_NOFOLLOW != 0 {|= FSOPT_NOFOLLOW}return setattrlist(,unsafe.Pointer(&),unsafe.Pointer(&),unsafe.Sizeof(),)}//sys setattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error)func ( int, string, *[2]Timespec, int) error {// Darwin doesn't support SYS_UTIMENSATreturn ENOSYS}/** Wrapped*///sys fcntl(fd int, cmd int, arg int) (val int, err error)//sys kill(pid int, signum int, posix int) (err error)func ( int, syscall.Signal) ( error) { return kill(, int(), 1) }//sys ioctl(fd int, req uint, arg uintptr) (err error)//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTLfunc ( *Utsname) error {:= []_C_int{CTL_KERN, KERN_OSTYPE}:= unsafe.Sizeof(.Sysname)if := sysctl(, &.Sysname[0], &, nil, 0); != nil {return}= []_C_int{CTL_KERN, KERN_HOSTNAME}= unsafe.Sizeof(.Nodename)if := sysctl(, &.Nodename[0], &, nil, 0); != nil {return}= []_C_int{CTL_KERN, KERN_OSRELEASE}= unsafe.Sizeof(.Release)if := sysctl(, &.Release[0], &, nil, 0); != nil {return}= []_C_int{CTL_KERN, KERN_VERSION}= unsafe.Sizeof(.Version)if := sysctl(, &.Version[0], &, nil, 0); != nil {return}// The version might have newlines or tabs in it, convert them to// spaces.for , := range .Version {if == '\n' || == '\t' {if == len(.Version)-1 {.Version[] = 0} else {.Version[] = ' '}}}= []_C_int{CTL_HW, HW_MACHINE}= unsafe.Sizeof(.Machine)if := sysctl(, &.Machine[0], &, nil, 0); != nil {return}return nil}func ( int, int, *int64, int) ( int, error) {if raceenabled {raceReleaseMerge(unsafe.Pointer(&ioSync))}var = int64()= sendfile(, , *, &, nil, 0)= int()return}//sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error)/** Exposed directly*///sys Access(path string, mode uint32) (err error)//sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)//sys Chdir(path string) (err error)//sys Chflags(path string, flags int) (err error)//sys Chmod(path string, mode uint32) (err error)//sys Chown(path string, uid int, gid int) (err error)//sys Chroot(path string) (err error)//sys ClockGettime(clockid int32, time *Timespec) (err error)//sys Close(fd int) (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 Exit(code int)//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)//sys Fchdir(fd int) (err error)//sys Fchflags(fd int, flags int) (err error)//sys Fchmod(fd int, mode uint32) (err error)//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)//sys Fchown(fd int, uid int, gid int) (err error)//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)//sys Flock(fd int, how int) (err error)//sys Fpathconf(fd int, name int) (val int, err error)//sys Fsync(fd int) (err error)//sys Ftruncate(fd int, length int64) (err error)//sys Getdtablesize() (size int)//sysnb Getegid() (egid int)//sysnb Geteuid() (uid int)//sysnb Getgid() (gid int)//sysnb Getpgid(pid int) (pgid int, err error)//sysnb Getpgrp() (pgrp int)//sysnb Getpid() (pid int)//sysnb Getppid() (ppid int)//sys Getpriority(which int, who int) (prio int, err error)//sysnb Getrlimit(which int, lim *Rlimit) (err error)//sysnb Getrusage(who int, rusage *Rusage) (err error)//sysnb Getsid(pid int) (sid int, err error)//sysnb Gettimeofday(tp *Timeval) (err error)//sysnb Getuid() (uid int)//sysnb Issetugid() (tainted bool)//sys Kqueue() (fd int, err error)//sys Lchown(path string, uid int, gid int) (err error)//sys Link(path string, link string) (err error)//sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error)//sys Listen(s int, backlog int) (err error)//sys Mkdir(path string, mode uint32) (err error)//sys Mkdirat(dirfd int, path string, mode uint32) (err error)//sys Mkfifo(path string, mode uint32) (err error)//sys Mknod(path string, mode uint32, dev int) (err error)//sys Open(path string, mode int, perm uint32) (fd int, err error)//sys Openat(dirfd int, 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 read(fd int, p []byte) (n int, err error)//sys Readlink(path string, buf []byte) (n int, err error)//sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error)//sys Rename(from string, to string) (err error)//sys Renameat(fromfd int, from string, tofd int, to string) (err error)//sys Revoke(path string) (err error)//sys Rmdir(path string) (err error)//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)//sys Setegid(egid int) (err error)//sysnb Seteuid(euid int) (err error)//sysnb Setgid(gid int) (err error)//sys Setlogin(name string) (err error)//sysnb Setpgid(pid int, pgid int) (err error)//sys Setpriority(which int, who int, prio int) (err error)//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 Setsid() (pid int, err error)//sysnb Settimeofday(tp *Timeval) (err error)//sysnb Setuid(uid int) (err error)//sys Symlink(path string, link string) (err error)//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)//sys Sync() (err error)//sys Truncate(path string, length int64) (err error)//sys Umask(newmask int) (oldmask int)//sys Undelete(path string) (err error)//sys Unlink(path string) (err error)//sys Unlinkat(dirfd int, path string, flags int) (err error)//sys Unmount(path string, flags int) (err error)//sys write(fd int, p []byte) (n int, err error)//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)//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE/** Unimplemented*/// Profil// Sigaction// Sigprocmask// Getlogin// Sigpending// Sigaltstack// Ioctl// Reboot// Execve// Vfork// Sbrk// Sstk// Ovadvise// Mincore// Setitimer// Swapon// Select// Sigsuspend// Readv// Writev// Nfssvc// Getfh// Quotactl// Mount// Csops// Waitid// Add_profil// Kdebug_trace// Sigreturn// Atsocket// Kqueue_from_portset_np// Kqueue_portset// Getattrlist// Setattrlist// Getdirentriesattr// Searchfs// Delete// Copyfile// Watchevent// Waitevent// Modwatch// Fsctl// Initgroups// Posix_spawn// Nfsclnt// Fhopen// Minherit// Semsys// Msgsys// Shmsys// Semctl// Semget// Semop// Msgctl// Msgget// Msgsnd// Msgrcv// Shmat// Shmctl// Shmdt// Shmget// Shm_open// Shm_unlink// Sem_open// Sem_close// Sem_unlink// Sem_wait// Sem_trywait// Sem_post// Sem_getvalue// Sem_init// Sem_destroy// Open_extended// Umask_extended// Stat_extended// Lstat_extended// Fstat_extended// Chmod_extended// Fchmod_extended// Access_extended// Settid// Gettid// Setsgroups// Getsgroups// Setwgroups// Getwgroups// Mkfifo_extended// Mkdir_extended// Identitysvc// Shared_region_check_np// Shared_region_map_np// __pthread_mutex_destroy// __pthread_mutex_init// __pthread_mutex_lock// __pthread_mutex_trylock// __pthread_mutex_unlock// __pthread_cond_init// __pthread_cond_destroy// __pthread_cond_broadcast// __pthread_cond_signal// Setsid_with_pid// __pthread_cond_timedwait// Aio_fsync// Aio_return// Aio_suspend// Aio_cancel// Aio_error// Aio_read// Aio_write// Lio_listio// __pthread_cond_wait// Iopolicysys// __pthread_kill// __pthread_sigmask// __sigwait// __disable_threadsignal// __pthread_markcancel// __pthread_canceled// __semwait_signal// Proc_info// sendfile// Stat64_extended// Lstat64_extended// Fstat64_extended// __pthread_chdir// __pthread_fchdir// Audit// Auditon// Getauid// Setauid// Getaudit// Setaudit// Getaudit_addr// Setaudit_addr// Auditctl// Bsdthread_create// Bsdthread_terminate// Stack_snapshot// Bsdthread_register// Workq_open// Workq_ops// __mac_execve// __mac_syscall// __mac_get_file// __mac_set_file// __mac_get_link// __mac_set_link// __mac_get_proc// __mac_set_proc// __mac_get_fd// __mac_set_fd// __mac_get_pid// __mac_get_lcid// __mac_get_lctx// __mac_set_lctx// Setlcid// Read_nocancel// Write_nocancel// Open_nocancel// Close_nocancel// Wait4_nocancel// Recvmsg_nocancel// Sendmsg_nocancel// Recvfrom_nocancel// Accept_nocancel// Fcntl_nocancel// Select_nocancel// Fsync_nocancel// Connect_nocancel// Sigsuspend_nocancel// Readv_nocancel// Writev_nocancel// Sendto_nocancel// Pread_nocancel// Pwrite_nocancel// Waitid_nocancel// Poll_nocancel// Msgsnd_nocancel// Msgrcv_nocancel// Sem_wait_nocancel// Aio_suspend_nocancel// __sigwait_nocancel// __semwait_signal_nocancel// __mac_mount// __mac_get_mount// __mac_getfsstat
The pages are generated with Golds v0.2.8-preview. (GOOS=darwin GOARCH=arm64)