github.com/Andyfoo/golang/x/sys@v0.0.0-20190901054642-57c1bf301704/unix/syscall_netbsd.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 // NetBSD 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 "runtime" 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 [12]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 sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) { 37 var olen uintptr 38 39 // Get a list of all sysctl nodes below the given MIB by performing 40 // a sysctl for the given MIB with CTL_QUERY appended. 41 mib = append(mib, CTL_QUERY) 42 qnode := Sysctlnode{Flags: SYSCTL_VERS_1} 43 qp := (*byte)(unsafe.Pointer(&qnode)) 44 sz := unsafe.Sizeof(qnode) 45 if err = sysctl(mib, nil, &olen, qp, sz); err != nil { 46 return nil, err 47 } 48 49 // Now that we know the size, get the actual nodes. 50 nodes = make([]Sysctlnode, olen/sz) 51 np := (*byte)(unsafe.Pointer(&nodes[0])) 52 if err = sysctl(mib, np, &olen, qp, sz); err != nil { 53 return nil, err 54 } 55 56 return nodes, nil 57 } 58 59 func nametomib(name string) (mib []_C_int, err error) { 60 // Split name into components. 61 var parts []string 62 last := 0 63 for i := 0; i < len(name); i++ { 64 if name[i] == '.' { 65 parts = append(parts, name[last:i]) 66 last = i + 1 67 } 68 } 69 parts = append(parts, name[last:]) 70 71 // Discover the nodes and construct the MIB OID. 72 for partno, part := range parts { 73 nodes, err := sysctlNodes(mib) 74 if err != nil { 75 return nil, err 76 } 77 for _, node := range nodes { 78 n := make([]byte, 0) 79 for i := range node.Name { 80 if node.Name[i] != 0 { 81 n = append(n, byte(node.Name[i])) 82 } 83 } 84 if string(n) == part { 85 mib = append(mib, _C_int(node.Num)) 86 break 87 } 88 } 89 if len(mib) != partno+1 { 90 return nil, EINVAL 91 } 92 } 93 94 return mib, nil 95 } 96 97 func direntIno(buf []byte) (uint64, bool) { 98 return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno)) 99 } 100 101 func direntReclen(buf []byte) (uint64, bool) { 102 return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen)) 103 } 104 105 func direntNamlen(buf []byte) (uint64, bool) { 106 return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) 107 } 108 109 func SysctlClockinfo(name string) (*Clockinfo, error) { 110 mib, err := sysctlmib(name) 111 if err != nil { 112 return nil, err 113 } 114 115 n := uintptr(SizeofClockinfo) 116 var ci Clockinfo 117 if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { 118 return nil, err 119 } 120 if n != SizeofClockinfo { 121 return nil, EIO 122 } 123 return &ci, nil 124 } 125 126 //sysnb pipe() (fd1 int, fd2 int, err error) 127 func Pipe(p []int) (err error) { 128 if len(p) != 2 { 129 return EINVAL 130 } 131 p[0], p[1], err = pipe() 132 return 133 } 134 135 //sys Getdents(fd int, buf []byte) (n int, err error) 136 func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { 137 n, err = Getdents(fd, buf) 138 if err != nil || basep == nil { 139 return 140 } 141 142 var off int64 143 off, err = Seek(fd, 0, 1 /* SEEK_CUR */) 144 if err != nil { 145 *basep = ^uintptr(0) 146 return 147 } 148 *basep = uintptr(off) 149 if unsafe.Sizeof(*basep) == 8 { 150 return 151 } 152 if off>>32 != 0 { 153 // We can't stuff the offset back into a uintptr, so any 154 // future calls would be suspect. Generate an error. 155 // EIO is allowed by getdirentries. 156 err = EIO 157 } 158 return 159 } 160 161 const ImplementsGetwd = true 162 163 //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD 164 165 func Getwd() (string, error) { 166 var buf [PathMax]byte 167 _, err := Getcwd(buf[0:]) 168 if err != nil { 169 return "", err 170 } 171 n := clen(buf[:]) 172 if n < 1 { 173 return "", EINVAL 174 } 175 return string(buf[:n]), nil 176 } 177 178 // TODO 179 func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 180 return -1, ENOSYS 181 } 182 183 func setattrlistTimes(path string, times []Timespec, flags int) error { 184 // used on Darwin for UtimesNano 185 return ENOSYS 186 } 187 188 //sys ioctl(fd int, req uint, arg uintptr) (err error) 189 190 func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) { 191 var value Ptmget 192 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) 193 runtime.KeepAlive(value) 194 return &value, err 195 } 196 197 func Uname(uname *Utsname) error { 198 mib := []_C_int{CTL_KERN, KERN_OSTYPE} 199 n := unsafe.Sizeof(uname.Sysname) 200 if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { 201 return err 202 } 203 204 mib = []_C_int{CTL_KERN, KERN_HOSTNAME} 205 n = unsafe.Sizeof(uname.Nodename) 206 if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { 207 return err 208 } 209 210 mib = []_C_int{CTL_KERN, KERN_OSRELEASE} 211 n = unsafe.Sizeof(uname.Release) 212 if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { 213 return err 214 } 215 216 mib = []_C_int{CTL_KERN, KERN_VERSION} 217 n = unsafe.Sizeof(uname.Version) 218 if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { 219 return err 220 } 221 222 // The version might have newlines or tabs in it, convert them to 223 // spaces. 224 for i, b := range uname.Version { 225 if b == '\n' || b == '\t' { 226 if i == len(uname.Version)-1 { 227 uname.Version[i] = 0 228 } else { 229 uname.Version[i] = ' ' 230 } 231 } 232 } 233 234 mib = []_C_int{CTL_HW, HW_MACHINE} 235 n = unsafe.Sizeof(uname.Machine) 236 if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { 237 return err 238 } 239 240 return nil 241 } 242 243 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 244 if raceenabled { 245 raceReleaseMerge(unsafe.Pointer(&ioSync)) 246 } 247 return sendfile(outfd, infd, offset, count) 248 } 249 250 /* 251 * Exposed directly 252 */ 253 //sys Access(path string, mode uint32) (err error) 254 //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) 255 //sys Chdir(path string) (err error) 256 //sys Chflags(path string, flags int) (err error) 257 //sys Chmod(path string, mode uint32) (err error) 258 //sys Chown(path string, uid int, gid int) (err error) 259 //sys Chroot(path string) (err error) 260 //sys Close(fd int) (err error) 261 //sys Dup(fd int) (nfd int, err error) 262 //sys Dup2(from int, to int) (err error) 263 //sys Exit(code int) 264 //sys ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 265 //sys ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 266 //sys ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) 267 //sys ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) 268 //sys ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 269 //sys ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 270 //sys ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) 271 //sys ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) 272 //sys ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 273 //sys ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 274 //sys ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) 275 //sys ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) 276 //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) 277 //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_POSIX_FADVISE 278 //sys Fchdir(fd int) (err error) 279 //sys Fchflags(fd int, flags int) (err error) 280 //sys Fchmod(fd int, mode uint32) (err error) 281 //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) 282 //sys Fchown(fd int, uid int, gid int) (err error) 283 //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) 284 //sys Flock(fd int, how int) (err error) 285 //sys Fpathconf(fd int, name int) (val int, err error) 286 //sys Fstat(fd int, stat *Stat_t) (err error) 287 //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) 288 //sys Fsync(fd int) (err error) 289 //sys Ftruncate(fd int, length int64) (err error) 290 //sysnb Getegid() (egid int) 291 //sysnb Geteuid() (uid int) 292 //sysnb Getgid() (gid int) 293 //sysnb Getpgid(pid int) (pgid int, err error) 294 //sysnb Getpgrp() (pgrp int) 295 //sysnb Getpid() (pid int) 296 //sysnb Getppid() (ppid int) 297 //sys Getpriority(which int, who int) (prio int, err error) 298 //sysnb Getrlimit(which int, lim *Rlimit) (err error) 299 //sysnb Getrusage(who int, rusage *Rusage) (err error) 300 //sysnb Getsid(pid int) (sid int, err error) 301 //sysnb Gettimeofday(tv *Timeval) (err error) 302 //sysnb Getuid() (uid int) 303 //sys Issetugid() (tainted bool) 304 //sys Kill(pid int, signum syscall.Signal) (err error) 305 //sys Kqueue() (fd int, err error) 306 //sys Lchown(path string, uid int, gid int) (err error) 307 //sys Link(path string, link string) (err error) 308 //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) 309 //sys Listen(s int, backlog int) (err error) 310 //sys Lstat(path string, stat *Stat_t) (err error) 311 //sys Mkdir(path string, mode uint32) (err error) 312 //sys Mkdirat(dirfd int, path string, mode uint32) (err error) 313 //sys Mkfifo(path string, mode uint32) (err error) 314 //sys Mkfifoat(dirfd int, path string, mode uint32) (err error) 315 //sys Mknod(path string, mode uint32, dev int) (err error) 316 //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) 317 //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) 318 //sys Open(path string, mode int, perm uint32) (fd int, err error) 319 //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) 320 //sys Pathconf(path string, name int) (val int, err error) 321 //sys Pread(fd int, p []byte, offset int64) (n int, err error) 322 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) 323 //sys read(fd int, p []byte) (n int, err error) 324 //sys Readlink(path string, buf []byte) (n int, err error) 325 //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) 326 //sys Rename(from string, to string) (err error) 327 //sys Renameat(fromfd int, from string, tofd int, to string) (err error) 328 //sys Revoke(path string) (err error) 329 //sys Rmdir(path string) (err error) 330 //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK 331 //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) 332 //sysnb Setegid(egid int) (err error) 333 //sysnb Seteuid(euid int) (err error) 334 //sysnb Setgid(gid int) (err error) 335 //sysnb Setpgid(pid int, pgid int) (err error) 336 //sys Setpriority(which int, who int, prio int) (err error) 337 //sysnb Setregid(rgid int, egid int) (err error) 338 //sysnb Setreuid(ruid int, euid int) (err error) 339 //sysnb Setrlimit(which int, lim *Rlimit) (err error) 340 //sysnb Setsid() (pid int, err error) 341 //sysnb Settimeofday(tp *Timeval) (err error) 342 //sysnb Setuid(uid int) (err error) 343 //sys Stat(path string, stat *Stat_t) (err error) 344 //sys Symlink(path string, link string) (err error) 345 //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) 346 //sys Sync() (err error) 347 //sys Truncate(path string, length int64) (err error) 348 //sys Umask(newmask int) (oldmask int) 349 //sys Unlink(path string) (err error) 350 //sys Unlinkat(dirfd int, path string, flags int) (err error) 351 //sys Unmount(path string, flags int) (err error) 352 //sys write(fd int, p []byte) (n int, err error) 353 //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) 354 //sys munmap(addr uintptr, length uintptr) (err error) 355 //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ 356 //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE 357 //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) 358 359 /* 360 * Unimplemented 361 */ 362 // ____semctl13 363 // __clone 364 // __fhopen40 365 // __fhstat40 366 // __fhstatvfs140 367 // __fstat30 368 // __getcwd 369 // __getfh30 370 // __getlogin 371 // __lstat30 372 // __mount50 373 // __msgctl13 374 // __msync13 375 // __ntp_gettime30 376 // __posix_chown 377 // __posix_fchown 378 // __posix_lchown 379 // __posix_rename 380 // __setlogin 381 // __shmctl13 382 // __sigaction_sigtramp 383 // __sigaltstack14 384 // __sigpending14 385 // __sigprocmask14 386 // __sigsuspend14 387 // __sigtimedwait 388 // __stat30 389 // __syscall 390 // __vfork14 391 // _ksem_close 392 // _ksem_destroy 393 // _ksem_getvalue 394 // _ksem_init 395 // _ksem_open 396 // _ksem_post 397 // _ksem_trywait 398 // _ksem_unlink 399 // _ksem_wait 400 // _lwp_continue 401 // _lwp_create 402 // _lwp_ctl 403 // _lwp_detach 404 // _lwp_exit 405 // _lwp_getname 406 // _lwp_getprivate 407 // _lwp_kill 408 // _lwp_park 409 // _lwp_self 410 // _lwp_setname 411 // _lwp_setprivate 412 // _lwp_suspend 413 // _lwp_unpark 414 // _lwp_unpark_all 415 // _lwp_wait 416 // _lwp_wakeup 417 // _pset_bind 418 // _sched_getaffinity 419 // _sched_getparam 420 // _sched_setaffinity 421 // _sched_setparam 422 // acct 423 // aio_cancel 424 // aio_error 425 // aio_fsync 426 // aio_read 427 // aio_return 428 // aio_suspend 429 // aio_write 430 // break 431 // clock_getres 432 // clock_gettime 433 // clock_settime 434 // compat_09_ogetdomainname 435 // compat_09_osetdomainname 436 // compat_09_ouname 437 // compat_10_omsgsys 438 // compat_10_osemsys 439 // compat_10_oshmsys 440 // compat_12_fstat12 441 // compat_12_getdirentries 442 // compat_12_lstat12 443 // compat_12_msync 444 // compat_12_oreboot 445 // compat_12_oswapon 446 // compat_12_stat12 447 // compat_13_sigaction13 448 // compat_13_sigaltstack13 449 // compat_13_sigpending13 450 // compat_13_sigprocmask13 451 // compat_13_sigreturn13 452 // compat_13_sigsuspend13 453 // compat_14___semctl 454 // compat_14_msgctl 455 // compat_14_shmctl 456 // compat_16___sigaction14 457 // compat_16___sigreturn14 458 // compat_20_fhstatfs 459 // compat_20_fstatfs 460 // compat_20_getfsstat 461 // compat_20_statfs 462 // compat_30___fhstat30 463 // compat_30___fstat13 464 // compat_30___lstat13 465 // compat_30___stat13 466 // compat_30_fhopen 467 // compat_30_fhstat 468 // compat_30_fhstatvfs1 469 // compat_30_getdents 470 // compat_30_getfh 471 // compat_30_ntp_gettime 472 // compat_30_socket 473 // compat_40_mount 474 // compat_43_fstat43 475 // compat_43_lstat43 476 // compat_43_oaccept 477 // compat_43_ocreat 478 // compat_43_oftruncate 479 // compat_43_ogetdirentries 480 // compat_43_ogetdtablesize 481 // compat_43_ogethostid 482 // compat_43_ogethostname 483 // compat_43_ogetkerninfo 484 // compat_43_ogetpagesize 485 // compat_43_ogetpeername 486 // compat_43_ogetrlimit 487 // compat_43_ogetsockname 488 // compat_43_okillpg 489 // compat_43_olseek 490 // compat_43_ommap 491 // compat_43_oquota 492 // compat_43_orecv 493 // compat_43_orecvfrom 494 // compat_43_orecvmsg 495 // compat_43_osend 496 // compat_43_osendmsg 497 // compat_43_osethostid 498 // compat_43_osethostname 499 // compat_43_osetrlimit 500 // compat_43_osigblock 501 // compat_43_osigsetmask 502 // compat_43_osigstack 503 // compat_43_osigvec 504 // compat_43_otruncate 505 // compat_43_owait 506 // compat_43_stat43 507 // execve 508 // extattr_delete_fd 509 // extattr_delete_file 510 // extattr_delete_link 511 // extattr_get_fd 512 // extattr_get_file 513 // extattr_get_link 514 // extattr_list_fd 515 // extattr_list_file 516 // extattr_list_link 517 // extattr_set_fd 518 // extattr_set_file 519 // extattr_set_link 520 // extattrctl 521 // fchroot 522 // fdatasync 523 // fgetxattr 524 // fktrace 525 // flistxattr 526 // fork 527 // fremovexattr 528 // fsetxattr 529 // fstatvfs1 530 // fsync_range 531 // getcontext 532 // getitimer 533 // getvfsstat 534 // getxattr 535 // ktrace 536 // lchflags 537 // lchmod 538 // lfs_bmapv 539 // lfs_markv 540 // lfs_segclean 541 // lfs_segwait 542 // lgetxattr 543 // lio_listio 544 // listxattr 545 // llistxattr 546 // lremovexattr 547 // lseek 548 // lsetxattr 549 // lutimes 550 // madvise 551 // mincore 552 // minherit 553 // modctl 554 // mq_close 555 // mq_getattr 556 // mq_notify 557 // mq_open 558 // mq_receive 559 // mq_send 560 // mq_setattr 561 // mq_timedreceive 562 // mq_timedsend 563 // mq_unlink 564 // mremap 565 // msgget 566 // msgrcv 567 // msgsnd 568 // nfssvc 569 // ntp_adjtime 570 // pmc_control 571 // pmc_get_info 572 // pollts 573 // preadv 574 // profil 575 // pselect 576 // pset_assign 577 // pset_create 578 // pset_destroy 579 // ptrace 580 // pwritev 581 // quotactl 582 // rasctl 583 // readv 584 // reboot 585 // removexattr 586 // sa_enable 587 // sa_preempt 588 // sa_register 589 // sa_setconcurrency 590 // sa_stacks 591 // sa_yield 592 // sbrk 593 // sched_yield 594 // semconfig 595 // semget 596 // semop 597 // setcontext 598 // setitimer 599 // setxattr 600 // shmat 601 // shmdt 602 // shmget 603 // sstk 604 // statvfs1 605 // swapctl 606 // sysarch 607 // syscall 608 // timer_create 609 // timer_delete 610 // timer_getoverrun 611 // timer_gettime 612 // timer_settime 613 // undelete 614 // utrace 615 // uuidgen 616 // vadvise 617 // vfork 618 // writev