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