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