gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

syscall_openbsd.go (11651B)


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