...
Run Format

Source file src/syscall/syscall_openbsd.go

Documentation: syscall

     1  // Copyright 2009,2010 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  // OpenBSD 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   [24]int8
    26  	raw    RawSockaddrDatalink
    27  }
    28  
    29  func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
    30  
    31  func nametomib(name string) (mib []_C_int, err error) {
    32  
    33  	// Perform lookup via a binary search
    34  	left := 0
    35  	right := len(sysctlMib) - 1
    36  	for {
    37  		idx := left + (right-left)/2
    38  		switch {
    39  		case name == sysctlMib[idx].ctlname:
    40  			return sysctlMib[idx].ctloid, nil
    41  		case name > sysctlMib[idx].ctlname:
    42  			left = idx + 1
    43  		default:
    44  			right = idx - 1
    45  		}
    46  		if left > right {
    47  			break
    48  		}
    49  	}
    50  	return nil, EINVAL
    51  }
    52  
    53  func direntIno(buf []byte) (uint64, bool) {
    54  	return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
    55  }
    56  
    57  func direntReclen(buf []byte) (uint64, bool) {
    58  	return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
    59  }
    60  
    61  func direntNamlen(buf []byte) (uint64, bool) {
    62  	return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
    63  }
    64  
    65  func Pipe(p []int) error {
    66  	return Pipe2(p, 0)
    67  }
    68  
    69  //sysnb pipe2(p *[2]_C_int, flags int) (err error)
    70  func Pipe2(p []int, flags int) error {
    71  	if len(p) != 2 {
    72  		return EINVAL
    73  	}
    74  	var pp [2]_C_int
    75  	err := pipe2(&pp, flags)
    76  	p[0] = int(pp[0])
    77  	p[1] = int(pp[1])
    78  	return err
    79  }
    80  
    81  //sys	accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error)
    82  func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
    83  	var rsa RawSockaddrAny
    84  	var len _Socklen = SizeofSockaddrAny
    85  	nfd, err = accept4(fd, &rsa, &len, flags)
    86  	if err != nil {
    87  		return
    88  	}
    89  	if len > SizeofSockaddrAny {
    90  		panic("RawSockaddrAny too small")
    91  	}
    92  	sa, err = anyToSockaddr(&rsa)
    93  	if err != nil {
    94  		Close(nfd)
    95  		nfd = 0
    96  	}
    97  	return
    98  }
    99  
   100  //sys getdents(fd int, buf []byte) (n int, err error)
   101  func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
   102  	return getdents(fd, buf)
   103  }
   104  
   105  // TODO, see golang.org/issue/5847
   106  func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
   107  	return -1, ENOSYS
   108  }
   109  
   110  func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
   111  	var _p0 unsafe.Pointer
   112  	var bufsize uintptr
   113  	if len(buf) > 0 {
   114  		_p0 = unsafe.Pointer(&buf[0])
   115  		bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
   116  	}
   117  	r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
   118  	n = int(r0)
   119  	if e1 != 0 {
   120  		err = e1
   121  	}
   122  	return
   123  }
   124  
   125  func setattrlistTimes(path string, times []Timespec) error {
   126  	// used on Darwin for UtimesNano
   127  	return ENOSYS
   128  }
   129  
   130  /*
   131   * Exposed directly
   132   */
   133  //sys	Access(path string, mode uint32) (err error)
   134  //sys	Adjtime(delta *Timeval, olddelta *Timeval) (err error)
   135  //sys	Chdir(path string) (err error)
   136  //sys	Chflags(path string, flags int) (err error)
   137  //sys	Chmod(path string, mode uint32) (err error)
   138  //sys	Chown(path string, uid int, gid int) (err error)
   139  //sys	Chroot(path string) (err error)
   140  //sys	Close(fd int) (err error)
   141  //sys	Dup(fd int) (nfd int, err error)
   142  //sys	Dup2(from int, to int) (err error)
   143  //sys	Fchdir(fd int) (err error)
   144  //sys	Fchflags(fd int, flags int) (err error)
   145  //sys	Fchmod(fd int, mode uint32) (err error)
   146  //sys	Fchown(fd int, uid int, gid int) (err error)
   147  //sys	Flock(fd int, how int) (err error)
   148  //sys	Fpathconf(fd int, name int) (val int, err error)
   149  //sys	Fstat(fd int, stat *Stat_t) (err error)
   150  //sys	Fstatfs(fd int, stat *Statfs_t) (err error)
   151  //sys	Fsync(fd int) (err error)
   152  //sys	Ftruncate(fd int, length int64) (err error)
   153  //sysnb	Getegid() (egid int)
   154  //sysnb	Geteuid() (uid int)
   155  //sysnb	Getgid() (gid int)
   156  //sysnb	Getpgid(pid int) (pgid int, err error)
   157  //sysnb	Getpgrp() (pgrp int)
   158  //sysnb	Getpid() (pid int)
   159  //sysnb	Getppid() (ppid int)
   160  //sys	Getpriority(which int, who int) (prio int, err error)
   161  //sysnb	Getrlimit(which int, lim *Rlimit) (err error)
   162  //sysnb	Getrusage(who int, rusage *Rusage) (err error)
   163  //sysnb	Getsid(pid int) (sid int, err error)
   164  //sysnb	Gettimeofday(tv *Timeval) (err error)
   165  //sysnb	Getuid() (uid int)
   166  //sys	Issetugid() (tainted bool)
   167  //sys	Kill(pid int, signum Signal) (err error)
   168  //sys	Kqueue() (fd int, err error)
   169  //sys	Lchown(path string, uid int, gid int) (err error)
   170  //sys	Link(path string, link string) (err error)
   171  //sys	Listen(s int, backlog int) (err error)
   172  //sys	Lstat(path string, stat *Stat_t) (err error)
   173  //sys	Mkdir(path string, mode uint32) (err error)
   174  //sys	Mkfifo(path string, mode uint32) (err error)
   175  //sys	Mknod(path string, mode uint32, dev int) (err error)
   176  //sys	Nanosleep(time *Timespec, leftover *Timespec) (err error)
   177  //sys	Open(path string, mode int, perm uint32) (fd int, err error)
   178  //sys	Pathconf(path string, name int) (val int, err error)
   179  //sys	Pread(fd int, p []byte, offset int64) (n int, err error)
   180  //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error)
   181  //sys	read(fd int, p []byte) (n int, err error)
   182  //sys	Readlink(path string, buf []byte) (n int, err error)
   183  //sys	Rename(from string, to string) (err error)
   184  //sys	Revoke(path string) (err error)
   185  //sys	Rmdir(path string) (err error)
   186  //sys	Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
   187  //sys	Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
   188  //sysnb	Setegid(egid int) (err error)
   189  //sysnb	Seteuid(euid int) (err error)
   190  //sysnb	Setgid(gid int) (err error)
   191  //sys	Setlogin(name string) (err error)
   192  //sysnb	Setpgid(pid int, pgid int) (err error)
   193  //sys	Setpriority(which int, who int, prio int) (err error)
   194  //sysnb	Setregid(rgid int, egid int) (err error)
   195  //sysnb	Setreuid(ruid int, euid int) (err error)
   196  //sysnb	Setrlimit(which int, lim *Rlimit) (err error)
   197  //sysnb	Setsid() (pid int, err error)
   198  //sysnb	Settimeofday(tp *Timeval) (err error)
   199  //sysnb	Setuid(uid int) (err error)
   200  //sys	Stat(path string, stat *Stat_t) (err error)
   201  //sys	Statfs(path string, stat *Statfs_t) (err error)
   202  //sys	Symlink(path string, link string) (err error)
   203  //sys	Sync() (err error)
   204  //sys	Truncate(path string, length int64) (err error)
   205  //sys	Umask(newmask int) (oldmask int)
   206  //sys	Unlink(path string) (err error)
   207  //sys	Unmount(path string, flags int) (err error)
   208  //sys	write(fd int, p []byte) (n int, err error)
   209  //sys	mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
   210  //sys	munmap(addr uintptr, length uintptr) (err error)
   211  //sys	readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
   212  //sys	writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
   213  //sys	utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error)
   214  //sys	getcwd(buf []byte) (n int, err error) = SYS___GETCWD
   215  

View as plain text