github.com/go-xe2/third@v1.0.3/golang.org/x/sys/unix/syscall_openbsd.go (about)

     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 unix
    14  
    15  import (
    16  	"sort"
    17  	"syscall"
    18  	"unsafe"
    19  )
    20  
    21  // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
    22  type SockaddrDatalink struct {
    23  	Len    uint8
    24  	Family uint8
    25  	Index  uint16
    26  	Type   uint8
    27  	Nlen   uint8
    28  	Alen   uint8
    29  	Slen   uint8
    30  	Data   [24]int8
    31  	raw    RawSockaddrDatalink
    32  }
    33  
    34  func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
    35  
    36  func nametomib(name string) (mib []_C_int, err error) {
    37  	i := sort.Search(len(sysctlMib), func(i int) bool {
    38  		return sysctlMib[i].ctlname >= name
    39  	})
    40  	if i < len(sysctlMib) && sysctlMib[i].ctlname == name {
    41  		return sysctlMib[i].ctloid, nil
    42  	}
    43  	return nil, EINVAL
    44  }
    45  
    46  func SysctlUvmexp(name string) (*Uvmexp, error) {
    47  	mib, err := sysctlmib(name)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  
    52  	n := uintptr(SizeofUvmexp)
    53  	var u Uvmexp
    54  	if err := sysctl(mib, (*byte)(unsafe.Pointer(&u)), &n, nil, 0); err != nil {
    55  		return nil, err
    56  	}
    57  	if n != SizeofUvmexp {
    58  		return nil, EIO
    59  	}
    60  	return &u, nil
    61  }
    62  
    63  //sysnb pipe(p *[2]_C_int) (err error)
    64  func Pipe(p []int) (err error) {
    65  	if len(p) != 2 {
    66  		return EINVAL
    67  	}
    68  	var pp [2]_C_int
    69  	err = pipe(&pp)
    70  	p[0] = int(pp[0])
    71  	p[1] = int(pp[1])
    72  	return
    73  }
    74  
    75  //sys getdents(fd int, buf []byte) (n int, err error)
    76  func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
    77  	return getdents(fd, buf)
    78  }
    79  
    80  const ImplementsGetwd = true
    81  
    82  //sys	Getcwd(buf []byte) (n int, err error) = SYS___GETCWD
    83  
    84  func Getwd() (string, error) {
    85  	var buf [PathMax]byte
    86  	_, err := Getcwd(buf[0:])
    87  	if err != nil {
    88  		return "", err
    89  	}
    90  	n := clen(buf[:])
    91  	if n < 1 {
    92  		return "", EINVAL
    93  	}
    94  	return string(buf[:n]), nil
    95  }
    96  
    97  func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
    98  	if raceenabled {
    99  		raceReleaseMerge(unsafe.Pointer(&ioSync))
   100  	}
   101  	return sendfile(outfd, infd, offset, count)
   102  }
   103  
   104  // TODO
   105  func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
   106  	return -1, ENOSYS
   107  }
   108  
   109  func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
   110  	var _p0 unsafe.Pointer
   111  	var bufsize uintptr
   112  	if len(buf) > 0 {
   113  		_p0 = unsafe.Pointer(&buf[0])
   114  		bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
   115  	}
   116  	r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
   117  	n = int(r0)
   118  	if e1 != 0 {
   119  		err = e1
   120  	}
   121  	return
   122  }
   123  
   124  func setattrlistTimes(path string, times []Timespec, flags int) error {
   125  	// used on Darwin for UtimesNano
   126  	return ENOSYS
   127  }
   128  
   129  //sys	ioctl(fd int, req uint, arg uintptr) (err error)
   130  
   131  // ioctl itself should not be exposed directly, but additional get/set
   132  // functions for specific types are permissible.
   133  
   134  // IoctlSetInt performs an ioctl operation which sets an integer value
   135  // on fd, using the specified request number.
   136  func IoctlSetInt(fd int, req uint, value int) error {
   137  	return ioctl(fd, req, uintptr(value))
   138  }
   139  
   140  func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
   141  	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
   142  }
   143  
   144  func ioctlSetTermios(fd int, req uint, value *Termios) error {
   145  	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
   146  }
   147  
   148  // IoctlGetInt performs an ioctl operation which gets an integer value
   149  // from fd, using the specified request number.
   150  func IoctlGetInt(fd int, req uint) (int, error) {
   151  	var value int
   152  	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
   153  	return value, err
   154  }
   155  
   156  func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
   157  	var value Winsize
   158  	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
   159  	return &value, err
   160  }
   161  
   162  func IoctlGetTermios(fd int, req uint) (*Termios, error) {
   163  	var value Termios
   164  	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
   165  	return &value, err
   166  }
   167  
   168  //sys	ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error)
   169  
   170  func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) {
   171  	if len(fds) == 0 {
   172  		return ppoll(nil, 0, timeout, sigmask)
   173  	}
   174  	return ppoll(&fds[0], len(fds), timeout, sigmask)
   175  }
   176  
   177  func Uname(uname *Utsname) error {
   178  	mib := []_C_int{CTL_KERN, KERN_OSTYPE}
   179  	n := unsafe.Sizeof(uname.Sysname)
   180  	if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil {
   181  		return err
   182  	}
   183  
   184  	mib = []_C_int{CTL_KERN, KERN_HOSTNAME}
   185  	n = unsafe.Sizeof(uname.Nodename)
   186  	if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil {
   187  		return err
   188  	}
   189  
   190  	mib = []_C_int{CTL_KERN, KERN_OSRELEASE}
   191  	n = unsafe.Sizeof(uname.Release)
   192  	if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil {
   193  		return err
   194  	}
   195  
   196  	mib = []_C_int{CTL_KERN, KERN_VERSION}
   197  	n = unsafe.Sizeof(uname.Version)
   198  	if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil {
   199  		return err
   200  	}
   201  
   202  	// The version might have newlines or tabs in it, convert them to
   203  	// spaces.
   204  	for i, b := range uname.Version {
   205  		if b == '\n' || b == '\t' {
   206  			if i == len(uname.Version)-1 {
   207  				uname.Version[i] = 0
   208  			} else {
   209  				uname.Version[i] = ' '
   210  			}
   211  		}
   212  	}
   213  
   214  	mib = []_C_int{CTL_HW, HW_MACHINE}
   215  	n = unsafe.Sizeof(uname.Machine)
   216  	if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil {
   217  		return err
   218  	}
   219  
   220  	return nil
   221  }
   222  
   223  /*
   224   * Exposed directly
   225   */
   226  //sys	Access(path string, mode uint32) (err error)
   227  //sys	Adjtime(delta *Timeval, olddelta *Timeval) (err error)
   228  //sys	Chdir(path string) (err error)
   229  //sys	Chflags(path string, flags int) (err error)
   230  //sys	Chmod(path string, mode uint32) (err error)
   231  //sys	Chown(path string, uid int, gid int) (err error)
   232  //sys	Chroot(path string) (err error)
   233  //sys	Close(fd int) (err error)
   234  //sys	Dup(fd int) (nfd int, err error)
   235  //sys	Dup2(from int, to int) (err error)
   236  //sys	Exit(code int)
   237  //sys	Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
   238  //sys	Fchdir(fd int) (err error)
   239  //sys	Fchflags(fd int, flags int) (err error)
   240  //sys	Fchmod(fd int, mode uint32) (err error)
   241  //sys	Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
   242  //sys	Fchown(fd int, uid int, gid int) (err error)
   243  //sys	Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
   244  //sys	Flock(fd int, how int) (err error)
   245  //sys	Fpathconf(fd int, name int) (val int, err error)
   246  //sys	Fstat(fd int, stat *Stat_t) (err error)
   247  //sys	Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
   248  //sys	Fstatfs(fd int, stat *Statfs_t) (err error)
   249  //sys	Fsync(fd int) (err error)
   250  //sys	Ftruncate(fd int, length int64) (err error)
   251  //sysnb	Getegid() (egid int)
   252  //sysnb	Geteuid() (uid int)
   253  //sysnb	Getgid() (gid int)
   254  //sysnb	Getpgid(pid int) (pgid int, err error)
   255  //sysnb	Getpgrp() (pgrp int)
   256  //sysnb	Getpid() (pid int)
   257  //sysnb	Getppid() (ppid int)
   258  //sys	Getpriority(which int, who int) (prio int, err error)
   259  //sysnb	Getrlimit(which int, lim *Rlimit) (err error)
   260  //sysnb	Getrtable() (rtable int, err error)
   261  //sysnb	Getrusage(who int, rusage *Rusage) (err error)
   262  //sysnb	Getsid(pid int) (sid int, err error)
   263  //sysnb	Gettimeofday(tv *Timeval) (err error)
   264  //sysnb	Getuid() (uid int)
   265  //sys	Issetugid() (tainted bool)
   266  //sys	Kill(pid int, signum syscall.Signal) (err error)
   267  //sys	Kqueue() (fd int, err error)
   268  //sys	Lchown(path string, uid int, gid int) (err error)
   269  //sys	Link(path string, link string) (err error)
   270  //sys	Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error)
   271  //sys	Listen(s int, backlog int) (err error)
   272  //sys	Lstat(path string, stat *Stat_t) (err error)
   273  //sys	Mkdir(path string, mode uint32) (err error)
   274  //sys	Mkdirat(dirfd int, path string, mode uint32) (err error)
   275  //sys	Mkfifo(path string, mode uint32) (err error)
   276  //sys	Mkfifoat(dirfd int, path string, mode uint32) (err error)
   277  //sys	Mknod(path string, mode uint32, dev int) (err error)
   278  //sys	Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
   279  //sys	Nanosleep(time *Timespec, leftover *Timespec) (err error)
   280  //sys	Open(path string, mode int, perm uint32) (fd int, err error)
   281  //sys	Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error)
   282  //sys	Pathconf(path string, name int) (val int, err error)
   283  //sys	Pread(fd int, p []byte, offset int64) (n int, err error)
   284  //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error)
   285  //sys	read(fd int, p []byte) (n int, err error)
   286  //sys	Readlink(path string, buf []byte) (n int, err error)
   287  //sys	Readlinkat(dirfd int, path string, buf []byte) (n int, err error)
   288  //sys	Rename(from string, to string) (err error)
   289  //sys	Renameat(fromfd int, from string, tofd int, to string) (err error)
   290  //sys	Revoke(path string) (err error)
   291  //sys	Rmdir(path string) (err error)
   292  //sys	Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
   293  //sys	Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
   294  //sysnb	Setegid(egid int) (err error)
   295  //sysnb	Seteuid(euid int) (err error)
   296  //sysnb	Setgid(gid int) (err error)
   297  //sys	Setlogin(name string) (err error)
   298  //sysnb	Setpgid(pid int, pgid int) (err error)
   299  //sys	Setpriority(which int, who int, prio int) (err error)
   300  //sysnb	Setregid(rgid int, egid int) (err error)
   301  //sysnb	Setreuid(ruid int, euid int) (err error)
   302  //sysnb	Setresgid(rgid int, egid int, sgid int) (err error)
   303  //sysnb	Setresuid(ruid int, euid int, suid int) (err error)
   304  //sysnb	Setrlimit(which int, lim *Rlimit) (err error)
   305  //sysnb	Setrtable(rtable int) (err error)
   306  //sysnb	Setsid() (pid int, err error)
   307  //sysnb	Settimeofday(tp *Timeval) (err error)
   308  //sysnb	Setuid(uid int) (err error)
   309  //sys	Stat(path string, stat *Stat_t) (err error)
   310  //sys	Statfs(path string, stat *Statfs_t) (err error)
   311  //sys	Symlink(path string, link string) (err error)
   312  //sys	Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
   313  //sys	Sync() (err error)
   314  //sys	Truncate(path string, length int64) (err error)
   315  //sys	Umask(newmask int) (oldmask int)
   316  //sys	Unlink(path string) (err error)
   317  //sys	Unlinkat(dirfd int, path string, flags int) (err error)
   318  //sys	Unmount(path string, flags int) (err error)
   319  //sys	write(fd int, p []byte) (n int, err error)
   320  //sys	mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
   321  //sys	munmap(addr uintptr, length uintptr) (err error)
   322  //sys	readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
   323  //sys	writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
   324  //sys	utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
   325  
   326  /*
   327   * Unimplemented
   328   */
   329  // __getcwd
   330  // __semctl
   331  // __syscall
   332  // __sysctl
   333  // adjfreq
   334  // break
   335  // clock_getres
   336  // clock_gettime
   337  // clock_settime
   338  // closefrom
   339  // execve
   340  // fcntl
   341  // fhopen
   342  // fhstat
   343  // fhstatfs
   344  // fork
   345  // futimens
   346  // getfh
   347  // getgid
   348  // getitimer
   349  // getlogin
   350  // getresgid
   351  // getresuid
   352  // getthrid
   353  // ktrace
   354  // lfs_bmapv
   355  // lfs_markv
   356  // lfs_segclean
   357  // lfs_segwait
   358  // mincore
   359  // minherit
   360  // mount
   361  // mquery
   362  // msgctl
   363  // msgget
   364  // msgrcv
   365  // msgsnd
   366  // nfssvc
   367  // nnpfspioctl
   368  // preadv
   369  // profil
   370  // pwritev
   371  // quotactl
   372  // readv
   373  // reboot
   374  // renameat
   375  // rfork
   376  // sched_yield
   377  // semget
   378  // semop
   379  // setgroups
   380  // setitimer
   381  // setsockopt
   382  // shmat
   383  // shmctl
   384  // shmdt
   385  // shmget
   386  // sigaction
   387  // sigaltstack
   388  // sigpending
   389  // sigprocmask
   390  // sigreturn
   391  // sigsuspend
   392  // sysarch
   393  // syscall
   394  // threxit
   395  // thrsigdivert
   396  // thrsleep
   397  // thrwakeup
   398  // vfork
   399  // writev