Source file src/syscall/syscall_openbsd.go

     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  func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
    18  func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
    19  func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
    20  func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
    21  func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
    22  
    23  type SockaddrDatalink struct {
    24  	Len    uint8
    25  	Family uint8
    26  	Index  uint16
    27  	Type   uint8
    28  	Nlen   uint8
    29  	Alen   uint8
    30  	Slen   uint8
    31  	Data   [24]int8
    32  	raw    RawSockaddrDatalink
    33  }
    34  
    35  func nametomib(name string) (mib []_C_int, err error) {
    36  	// Perform lookup via a binary search
    37  	left := 0
    38  	right := len(sysctlMib) - 1
    39  	for {
    40  		idx := left + (right-left)/2
    41  		switch {
    42  		case name == sysctlMib[idx].ctlname:
    43  			return sysctlMib[idx].ctloid, nil
    44  		case name > sysctlMib[idx].ctlname:
    45  			left = idx + 1
    46  		default:
    47  			right = idx - 1
    48  		}
    49  		if left > right {
    50  			break
    51  		}
    52  	}
    53  	return nil, EINVAL
    54  }
    55  
    56  func direntIno(buf []byte) (uint64, bool) {
    57  	return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
    58  }
    59  
    60  func direntReclen(buf []byte) (uint64, bool) {
    61  	return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
    62  }
    63  
    64  func direntNamlen(buf []byte) (uint64, bool) {
    65  	return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
    66  }
    67  
    68  func Pipe(p []int) error {
    69  	return Pipe2(p, 0)
    70  }
    71  
    72  //sysnb pipe2(p *[2]_C_int, flags int) (err error)
    73  
    74  func Pipe2(p []int, flags int) error {
    75  	if len(p) != 2 {
    76  		return EINVAL
    77  	}
    78  	var pp [2]_C_int
    79  	err := pipe2(&pp, flags)
    80  	if err == nil {
    81  		p[0] = int(pp[0])
    82  		p[1] = int(pp[1])
    83  	}
    84  	return err
    85  }
    86  
    87  //sys	accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error)
    88  
    89  func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
    90  	var rsa RawSockaddrAny
    91  	var len _Socklen = SizeofSockaddrAny
    92  	nfd, err = accept4(fd, &rsa, &len, flags)
    93  	if err != nil {
    94  		return
    95  	}
    96  	if len > SizeofSockaddrAny {
    97  		panic("RawSockaddrAny too small")
    98  	}
    99  	sa, err = anyToSockaddr(&rsa)
   100  	if err != nil {
   101  		Close(nfd)
   102  		nfd = 0
   103  	}
   104  	return
   105  }
   106  
   107  //sys getdents(fd int, buf []byte) (n int, err error)
   108  
   109  func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
   110  	return getdents(fd, buf)
   111  }
   112  
   113  // TODO, see golang.org/issue/5847
   114  func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
   115  	return -1, ENOSYS
   116  }
   117  
   118  func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
   119  	var _p0 unsafe.Pointer
   120  	var bufsize uintptr
   121  	if len(buf) > 0 {
   122  		_p0 = unsafe.Pointer(&buf[0])
   123  		bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
   124  	}
   125  	r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
   126  	n = int(r0)
   127  	if e1 != 0 {
   128  		err = e1
   129  	}
   130  	return
   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	dup3(from int, to int, flags int) (err error)
   147  //sys	Fchdir(fd int) (err error)
   148  //sys	Fchflags(fd int, flags int) (err error)
   149  //sys	Fchmod(fd int, mode uint32) (err error)
   150  //sys	Fchown(fd int, uid int, gid int) (err error)
   151  //sys	Flock(fd int, how int) (err error)
   152  //sys	Fpathconf(fd int, name int) (val int, err error)
   153  //sys	Fstat(fd int, stat *Stat_t) (err error)
   154  //sys	Fstatfs(fd int, stat *Statfs_t) (err error)
   155  //sys	Fsync(fd int) (err error)
   156  //sys	Ftruncate(fd int, length int64) (err error)
   157  //sysnb	Getegid() (egid int)
   158  //sysnb	Geteuid() (uid int)
   159  //sysnb	Getgid() (gid int)
   160  //sysnb	Getpgid(pid int) (pgid int, err error)
   161  //sysnb	Getpgrp() (pgrp int)
   162  //sysnb	Getpid() (pid int)
   163  //sysnb	Getppid() (ppid int)
   164  //sys	Getpriority(which int, who int) (prio int, err error)
   165  //sysnb	Getrlimit(which int, lim *Rlimit) (err error)
   166  //sysnb	Getrusage(who int, rusage *Rusage) (err error)
   167  //sysnb	Getsid(pid int) (sid int, err error)
   168  //sysnb	Gettimeofday(tv *Timeval) (err error)
   169  //sysnb	Getuid() (uid int)
   170  //sys	Issetugid() (tainted bool)
   171  //sys	Kill(pid int, signum Signal) (err error)
   172  //sys	Kqueue() (fd int, err error)
   173  //sys	Lchown(path string, uid int, gid int) (err error)
   174  //sys	Link(path string, link string) (err error)
   175  //sys	Listen(s int, backlog int) (err error)
   176  //sys	Lstat(path string, stat *Stat_t) (err error)
   177  //sys	Mkdir(path string, mode uint32) (err error)
   178  //sys	Mkfifo(path string, mode uint32) (err error)
   179  //sys	Mknod(path string, mode uint32, dev int) (err error)
   180  //sys	Nanosleep(time *Timespec, leftover *Timespec) (err error)
   181  //sys	Open(path string, mode int, perm uint32) (fd int, err error)
   182  //sys	Pathconf(path string, name int) (val int, err error)
   183  //sys	pread(fd int, p []byte, offset int64) (n int, err error)
   184  //sys	pwrite(fd int, p []byte, offset int64) (n int, err error)
   185  //sys	read(fd int, p []byte) (n int, err error)
   186  //sys	Readlink(path string, buf []byte) (n int, err error)
   187  //sys	Rename(from string, to string) (err error)
   188  //sys	Revoke(path string) (err error)
   189  //sys	Rmdir(path string) (err error)
   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	Unlink(path string) (err error)
   210  //sys	Unmount(path string, flags int) (err error)
   211  //sys	write(fd int, p []byte) (n int, err error)
   212  //sys	mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
   213  //sys	munmap(addr uintptr, length uintptr) (err error)
   214  //sys	utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error)
   215  

View as plain text