Source file src/syscall/syscall_dragonfly.go

Documentation: syscall

     1  // Copyright 2009 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  // DragonFly BSD system calls.
     6  // This file is compiled as ordinary Go code,
     7  // but it is also input to mksyscall,
     8  // which parses the //sys lines and generates system call stubs.
     9  // Note that sometimes we use a lowercase //sys name and wrap
    10  // it in our own nicer implementation, either here or in
    11  // syscall_bsd.go or syscall_unix.go.
    12  
    13  package syscall
    14  
    15  import (
    16  	"sync"
    17  	"unsafe"
    18  )
    19  
    20  // See version list in https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/sys/sys/param.h
    21  var (
    22  	osreldateOnce sync.Once
    23  	osreldate     uint32
    24  )
    25  
    26  // First __DragonFly_version after September 2019 ABI changes
    27  // http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html
    28  const _dragonflyABIChangeVersion = 500705
    29  
    30  func supportsABI(ver uint32) bool {
    31  	osreldateOnce.Do(func() { osreldate, _ = SysctlUint32("kern.osreldate") })
    32  	return osreldate >= ver
    33  }
    34  
    35  type SockaddrDatalink struct {
    36  	Len    uint8
    37  	Family uint8
    38  	Index  uint16
    39  	Type   uint8
    40  	Nlen   uint8
    41  	Alen   uint8
    42  	Slen   uint8
    43  	Data   [12]int8
    44  	Rcf    uint16
    45  	Route  [16]uint16
    46  	raw    RawSockaddrDatalink
    47  }
    48  
    49  // Translate "kern.hostname" to []_C_int{0,1,2,3}.
    50  func nametomib(name string) (mib []_C_int, err error) {
    51  	const siz = unsafe.Sizeof(mib[0])
    52  
    53  	// NOTE(rsc): It seems strange to set the buffer to have
    54  	// size CTL_MAXNAME+2 but use only CTL_MAXNAME
    55  	// as the size. I don't know why the +2 is here, but the
    56  	// kernel uses +2 for its own implementation of this function.
    57  	// I am scared that if we don't include the +2 here, the kernel
    58  	// will silently write 2 words farther than we specify
    59  	// and we'll get memory corruption.
    60  	var buf [CTL_MAXNAME + 2]_C_int
    61  	n := uintptr(CTL_MAXNAME) * siz
    62  
    63  	p := (*byte)(unsafe.Pointer(&buf[0]))
    64  	bytes, err := ByteSliceFromString(name)
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  
    69  	// Magic sysctl: "setting" 0.3 to a string name
    70  	// lets you read back the array of integers form.
    71  	if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil {
    72  		return nil, err
    73  	}
    74  	return buf[0 : n/siz], nil
    75  }
    76  
    77  func direntIno(buf []byte) (uint64, bool) {
    78  	return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
    79  }
    80  
    81  func direntReclen(buf []byte) (uint64, bool) {
    82  	namlen, ok := direntNamlen(buf)
    83  	if !ok {
    84  		return 0, false
    85  	}
    86  	return (16 + namlen + 1 + 7) &^ 7, true
    87  }
    88  
    89  func direntNamlen(buf []byte) (uint64, bool) {
    90  	return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
    91  }
    92  
    93  //sysnb pipe() (r int, w int, err error)
    94  
    95  func Pipe(p []int) (err error) {
    96  	if len(p) != 2 {
    97  		return EINVAL
    98  	}
    99  	p[0], p[1], err = pipe()
   100  	return
   101  }
   102  
   103  //sys	extpread(fd int, p []byte, flags int, offset int64) (n int, err error)
   104  func Pread(fd int, p []byte, offset int64) (n int, err error) {
   105  	return extpread(fd, p, 0, offset)
   106  }
   107  
   108  //sys	extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error)
   109  func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
   110  	return extpwrite(fd, p, 0, offset)
   111  }
   112  
   113  func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
   114  	var rsa RawSockaddrAny
   115  	var len _Socklen = SizeofSockaddrAny
   116  	nfd, err = accept4(fd, &rsa, &len, flags)
   117  	if err != nil {
   118  		return
   119  	}
   120  	if len > SizeofSockaddrAny {
   121  		panic("RawSockaddrAny too small")
   122  	}
   123  	sa, err = anyToSockaddr(&rsa)
   124  	if err != nil {
   125  		Close(nfd)
   126  		nfd = 0
   127  	}
   128  	return
   129  }
   130  
   131  func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
   132  	var _p0 unsafe.Pointer
   133  	var bufsize uintptr
   134  	if len(buf) > 0 {
   135  		_p0 = unsafe.Pointer(&buf[0])
   136  		bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
   137  	}
   138  	r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
   139  	n = int(r0)
   140  	if e1 != 0 {
   141  		err = e1
   142  	}
   143  	return
   144  }
   145  
   146  func setattrlistTimes(path string, times []Timespec) error {
   147  	// used on Darwin for UtimesNano
   148  	return ENOSYS
   149  }
   150  
   151  /*
   152   * Exposed directly
   153   */
   154  //sys	Access(path string, mode uint32) (err error)
   155  //sys	Adjtime(delta *Timeval, olddelta *Timeval) (err error)
   156  //sys	Chdir(path string) (err error)
   157  //sys	Chflags(path string, flags int) (err error)
   158  //sys	Chmod(path string, mode uint32) (err error)
   159  //sys	Chown(path string, uid int, gid int) (err error)
   160  //sys	Chroot(path string) (err error)
   161  //sys	Close(fd int) (err error)
   162  //sys	Dup(fd int) (nfd int, err error)
   163  //sys	Dup2(from int, to int) (err error)
   164  //sys	Fchdir(fd int) (err error)
   165  //sys	Fchflags(fd int, flags int) (err error)
   166  //sys	Fchmod(fd int, mode uint32) (err error)
   167  //sys	Fchown(fd int, uid int, gid int) (err error)
   168  //sys	Flock(fd int, how int) (err error)
   169  //sys	Fpathconf(fd int, name int) (val int, err error)
   170  //sys	Fstat(fd int, stat *Stat_t) (err error)
   171  //sys	Fstatfs(fd int, stat *Statfs_t) (err error)
   172  //sys	Fsync(fd int) (err error)
   173  //sys	Ftruncate(fd int, length int64) (err error)
   174  //sys	Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
   175  //sys	Getdtablesize() (size int)
   176  //sysnb	Getegid() (egid int)
   177  //sysnb	Geteuid() (uid int)
   178  //sysnb	Getgid() (gid int)
   179  //sysnb	Getpgid(pid int) (pgid int, err error)
   180  //sysnb	Getpgrp() (pgrp int)
   181  //sysnb	Getpid() (pid int)
   182  //sysnb	Getppid() (ppid int)
   183  //sys	Getpriority(which int, who int) (prio int, err error)
   184  //sysnb	Getrlimit(which int, lim *Rlimit) (err error)
   185  //sysnb	Getrusage(who int, rusage *Rusage) (err error)
   186  //sysnb	Getsid(pid int) (sid int, err error)
   187  //sysnb	Gettimeofday(tv *Timeval) (err error)
   188  //sysnb	Getuid() (uid int)
   189  //sys	Issetugid() (tainted bool)
   190  //sys	Kill(pid int, signum Signal) (err error)
   191  //sys	Kqueue() (fd int, err error)
   192  //sys	Lchown(path string, uid int, gid int) (err error)
   193  //sys	Link(path string, link string) (err error)
   194  //sys	Listen(s int, backlog int) (err error)
   195  //sys	Lstat(path string, stat *Stat_t) (err error)
   196  //sys	Mkdir(path string, mode uint32) (err error)
   197  //sys	Mkfifo(path string, mode uint32) (err error)
   198  //sys	Mknod(path string, mode uint32, dev int) (err error)
   199  //sys	Nanosleep(time *Timespec, leftover *Timespec) (err error)
   200  //sys	Open(path string, mode int, perm uint32) (fd int, err error)
   201  //sys	Pathconf(path string, name int) (val int, err error)
   202  //sys	read(fd int, p []byte) (n int, err error)
   203  //sys	Readlink(path string, buf []byte) (n int, err error)
   204  //sys	Rename(from string, to string) (err error)
   205  //sys	Revoke(path string) (err error)
   206  //sys	Rmdir(path string) (err error)
   207  //sys	Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
   208  //sys	Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
   209  //sysnb	Setegid(egid int) (err error)
   210  //sysnb	Seteuid(euid int) (err error)
   211  //sysnb	Setgid(gid int) (err error)
   212  //sys	Setlogin(name string) (err error)
   213  //sysnb	Setpgid(pid int, pgid int) (err error)
   214  //sys	Setpriority(which int, who int, prio int) (err error)
   215  //sysnb	Setregid(rgid int, egid int) (err error)
   216  //sysnb	Setreuid(ruid int, euid int) (err error)
   217  //sysnb	Setrlimit(which int, lim *Rlimit) (err error)
   218  //sysnb	Setsid() (pid int, err error)
   219  //sysnb	Settimeofday(tp *Timeval) (err error)
   220  //sysnb	Setuid(uid int) (err error)
   221  //sys	Stat(path string, stat *Stat_t) (err error)
   222  //sys	Statfs(path string, stat *Statfs_t) (err error)
   223  //sys	Symlink(path string, link string) (err error)
   224  //sys	Sync() (err error)
   225  //sys	Truncate(path string, length int64) (err error)
   226  //sys	Umask(newmask int) (oldmask int)
   227  //sys	Undelete(path string) (err error)
   228  //sys	Unlink(path string) (err error)
   229  //sys	Unmount(path string, flags int) (err error)
   230  //sys	write(fd int, p []byte) (n int, err error)
   231  //sys   mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
   232  //sys   munmap(addr uintptr, length uintptr) (err error)
   233  //sys	readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
   234  //sys	writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
   235  //sys	accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error)
   236  //sys	utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error)
   237  //sys	getcwd(buf []byte) (n int, err error) = SYS___GETCWD
   238  //sys	sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
   239  

View as plain text