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