...
Run Format

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

View as plain text