github.com/giovannyortegon/go@v0.0.0-20220115155912-8890063f5bdd/src/pkg/mod/golang.org/x/sys@v0.0.0-20210927094055-39ccf1dd6fa6/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 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 sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) { 41 var olen uintptr 42 43 // Get a list of all sysctl nodes below the given MIB by performing 44 // a sysctl for the given MIB with CTL_QUERY appended. 45 mib = append(mib, CTL_QUERY) 46 qnode := Sysctlnode{Flags: SYSCTL_VERS_1} 47 qp := (*byte)(unsafe.Pointer(&qnode)) 48 sz := unsafe.Sizeof(qnode) 49 if err = sysctl(mib, nil, &olen, qp, sz); err != nil { 50 return nil, err 51 } 52 53 // Now that we know the size, get the actual nodes. 54 nodes = make([]Sysctlnode, olen/sz) 55 np := (*byte)(unsafe.Pointer(&nodes[0])) 56 if err = sysctl(mib, np, &olen, qp, sz); err != nil { 57 return nil, err 58 } 59 60 return nodes, nil 61 } 62 63 func nametomib(name string) (mib []_C_int, err error) { 64 // Split name into components. 65 var parts []string 66 last := 0 67 for i := 0; i < len(name); i++ { 68 if name[i] == '.' { 69 parts = append(parts, name[last:i]) 70 last = i + 1 71 } 72 } 73 parts = append(parts, name[last:]) 74 75 // Discover the nodes and construct the MIB OID. 76 for partno, part := range parts { 77 nodes, err := sysctlNodes(mib) 78 if err != nil { 79 return nil, err 80 } 81 for _, node := range nodes { 82 n := make([]byte, 0) 83 for i := range node.Name { 84 if node.Name[i] != 0 { 85 n = append(n, byte(node.Name[i])) 86 } 87 } 88 if string(n) == part { 89 mib = append(mib, _C_int(node.Num)) 90 break 91 } 92 } 93 if len(mib) != partno+1 { 94 return nil, EINVAL 95 } 96 } 97 98 return mib, nil 99 } 100 101 func direntIno(buf []byte) (uint64, bool) { 102 return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno)) 103 } 104 105 func direntReclen(buf []byte) (uint64, bool) { 106 return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen)) 107 } 108 109 func direntNamlen(buf []byte) (uint64, bool) { 110 return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) 111 } 112 113 //sysnb pipe() (fd1 int, fd2 int, err error) 114 115 func Pipe(p []int) (err error) { 116 if len(p) != 2 { 117 return EINVAL 118 } 119 p[0], p[1], err = pipe() 120 return 121 } 122 123 //sysnb pipe2(p *[2]_C_int, flags int) (err error) 124 125 func Pipe2(p []int, flags int) error { 126 if len(p) != 2 { 127 return EINVAL 128 } 129 var pp [2]_C_int 130 err := pipe2(&pp, flags) 131 p[0] = int(pp[0]) 132 p[1] = int(pp[1]) 133 return err 134 } 135 136 //sys Getdents(fd int, buf []byte) (n int, err error) 137 138 func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { 139 n, err = Getdents(fd, buf) 140 if err != nil || basep == nil { 141 return 142 } 143 144 var off int64 145 off, err = Seek(fd, 0, 1 /* SEEK_CUR */) 146 if err != nil { 147 *basep = ^uintptr(0) 148 return 149 } 150 *basep = uintptr(off) 151 if unsafe.Sizeof(*basep) == 8 { 152 return 153 } 154 if off>>32 != 0 { 155 // We can't stuff the offset back into a uintptr, so any 156 // future calls would be suspect. Generate an error. 157 // EIO is allowed by getdirentries. 158 err = EIO 159 } 160 return 161 } 162 163 //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD 164 165 // TODO 166 func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 167 return -1, ENOSYS 168 } 169 170 func setattrlistTimes(path string, times []Timespec, flags int) error { 171 // used on Darwin for UtimesNano 172 return ENOSYS 173 } 174 175 //sys ioctl(fd int, req uint, arg uintptr) (err error) 176 177 //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL 178 179 func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) { 180 var value Ptmget 181 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) 182 runtime.KeepAlive(value) 183 return &value, err 184 } 185 186 func Uname(uname *Utsname) error { 187 mib := []_C_int{CTL_KERN, KERN_OSTYPE} 188 n := unsafe.Sizeof(uname.Sysname) 189 if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { 190 return err 191 } 192 193 mib = []_C_int{CTL_KERN, KERN_HOSTNAME} 194 n = unsafe.Sizeof(uname.Nodename) 195 if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { 196 return err 197 } 198 199 mib = []_C_int{CTL_KERN, KERN_OSRELEASE} 200 n = unsafe.Sizeof(uname.Release) 201 if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { 202 return err 203 } 204 205 mib = []_C_int{CTL_KERN, KERN_VERSION} 206 n = unsafe.Sizeof(uname.Version) 207 if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { 208 return err 209 } 210 211 // The version might have newlines or tabs in it, convert them to 212 // spaces. 213 for i, b := range uname.Version { 214 if b == '\n' || b == '\t' { 215 if i == len(uname.Version)-1 { 216 uname.Version[i] = 0 217 } else { 218 uname.Version[i] = ' ' 219 } 220 } 221 } 222 223 mib = []_C_int{CTL_HW, HW_MACHINE} 224 n = unsafe.Sizeof(uname.Machine) 225 if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { 226 return err 227 } 228 229 return nil 230 } 231 232 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 233 if raceenabled { 234 raceReleaseMerge(unsafe.Pointer(&ioSync)) 235 } 236 return sendfile(outfd, infd, offset, count) 237 } 238 239 func Fstatvfs(fd int, buf *Statvfs_t) (err error) { 240 return Fstatvfs1(fd, buf, ST_WAIT) 241 } 242 243 func Statvfs(path string, buf *Statvfs_t) (err error) { 244 return Statvfs1(path, buf, ST_WAIT) 245 } 246 247 /* 248 * Exposed directly 249 */ 250 //sys Access(path string, mode uint32) (err error) 251 //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) 252 //sys Chdir(path string) (err error) 253 //sys Chflags(path string, flags int) (err error) 254 //sys Chmod(path string, mode uint32) (err error) 255 //sys Chown(path string, uid int, gid int) (err error) 256 //sys Chroot(path string) (err error) 257 //sys Close(fd int) (err error) 258 //sys Dup(fd int) (nfd int, err error) 259 //sys Dup2(from int, to int) (err error) 260 //sys Dup3(from int, to int, flags int) (err error) 261 //sys Exit(code int) 262 //sys ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 263 //sys ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 264 //sys ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error) 265 //sys ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error) 266 //sys ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 267 //sys ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 268 //sys ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error) 269 //sys ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) 270 //sys ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 271 //sys ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error) 272 //sys ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error) 273 //sys ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error) 274 //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) 275 //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_POSIX_FADVISE 276 //sys Fchdir(fd int) (err error) 277 //sys Fchflags(fd int, flags int) (err error) 278 //sys Fchmod(fd int, mode uint32) (err error) 279 //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) 280 //sys Fchown(fd int, uid int, gid int) (err error) 281 //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) 282 //sys Flock(fd int, how int) (err error) 283 //sys Fpathconf(fd int, name int) (val int, err error) 284 //sys Fstat(fd int, stat *Stat_t) (err error) 285 //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) 286 //sys Fstatvfs1(fd int, buf *Statvfs_t, flags int) (err error) = SYS_FSTATVFS1 287 //sys Fsync(fd int) (err error) 288 //sys Ftruncate(fd int, length int64) (err error) 289 //sysnb Getegid() (egid int) 290 //sysnb Geteuid() (uid int) 291 //sysnb Getgid() (gid int) 292 //sysnb Getpgid(pid int) (pgid int, err error) 293 //sysnb Getpgrp() (pgrp int) 294 //sysnb Getpid() (pid int) 295 //sysnb Getppid() (ppid int) 296 //sys Getpriority(which int, who int) (prio int, err error) 297 //sysnb Getrlimit(which int, lim *Rlimit) (err error) 298 //sysnb Getrusage(who int, rusage *Rusage) (err error) 299 //sysnb Getsid(pid int) (sid int, err error) 300 //sysnb Gettimeofday(tv *Timeval) (err error) 301 //sysnb Getuid() (uid int) 302 //sys Issetugid() (tainted bool) 303 //sys Kill(pid int, signum syscall.Signal) (err error) 304 //sys Kqueue() (fd int, err error) 305 //sys Lchown(path string, uid int, gid int) (err error) 306 //sys Link(path string, link string) (err error) 307 //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) 308 //sys Listen(s int, backlog int) (err error) 309 //sys Lstat(path string, stat *Stat_t) (err error) 310 //sys Mkdir(path string, mode uint32) (err error) 311 //sys Mkdirat(dirfd int, path string, mode uint32) (err error) 312 //sys Mkfifo(path string, mode uint32) (err error) 313 //sys Mkfifoat(dirfd int, path string, mode uint32) (err error) 314 //sys Mknod(path string, mode uint32, dev int) (err error) 315 //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) 316 //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) 317 //sys Open(path string, mode int, perm uint32) (fd int, err error) 318 //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) 319 //sys Pathconf(path string, name int) (val int, err error) 320 //sys Pread(fd int, p []byte, offset int64) (n int, err error) 321 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) 322 //sys read(fd int, p []byte) (n int, err error) 323 //sys Readlink(path string, buf []byte) (n int, err error) 324 //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) 325 //sys Rename(from string, to string) (err error) 326 //sys Renameat(fromfd int, from string, tofd int, to string) (err error) 327 //sys Revoke(path string) (err error) 328 //sys Rmdir(path string) (err error) 329 //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK 330 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) 331 //sysnb Setegid(egid int) (err error) 332 //sysnb Seteuid(euid int) (err error) 333 //sysnb Setgid(gid int) (err error) 334 //sysnb Setpgid(pid int, pgid int) (err error) 335 //sys Setpriority(which int, who int, prio int) (err error) 336 //sysnb Setregid(rgid int, egid int) (err error) 337 //sysnb Setreuid(ruid int, euid int) (err error) 338 //sysnb Setrlimit(which int, lim *Rlimit) (err error) 339 //sysnb Setsid() (pid int, err error) 340 //sysnb Settimeofday(tp *Timeval) (err error) 341 //sysnb Setuid(uid int) (err error) 342 //sys Stat(path string, stat *Stat_t) (err error) 343 //sys Statvfs1(path string, buf *Statvfs_t, flags int) (err error) = SYS_STATVFS1 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