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