syscall_netbsd.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. // NetBSD system calls.
  5. // This file is compiled as ordinary Go code,
  6. // but it is also input to mksyscall,
  7. // which parses the //sys lines and generates system call stubs.
  8. // Note that sometimes we use a lowercase //sys name and wrap
  9. // it in our own nicer implementation, either here or in
  10. // syscall_bsd.go or syscall_unix.go.
  11. package unix
  12. import (
  13. "syscall"
  14. "unsafe"
  15. )
  16. type SockaddrDatalink struct {
  17. Len uint8
  18. Family uint8
  19. Index uint16
  20. Type uint8
  21. Nlen uint8
  22. Alen uint8
  23. Slen uint8
  24. Data [12]int8
  25. raw RawSockaddrDatalink
  26. }
  27. func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
  28. func sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) {
  29. var olen uintptr
  30. // Get a list of all sysctl nodes below the given MIB by performing
  31. // a sysctl for the given MIB with CTL_QUERY appended.
  32. mib = append(mib, CTL_QUERY)
  33. qnode := Sysctlnode{Flags: SYSCTL_VERS_1}
  34. qp := (*byte)(unsafe.Pointer(&qnode))
  35. sz := unsafe.Sizeof(qnode)
  36. if err = sysctl(mib, nil, &olen, qp, sz); err != nil {
  37. return nil, err
  38. }
  39. // Now that we know the size, get the actual nodes.
  40. nodes = make([]Sysctlnode, olen/sz)
  41. np := (*byte)(unsafe.Pointer(&nodes[0]))
  42. if err = sysctl(mib, np, &olen, qp, sz); err != nil {
  43. return nil, err
  44. }
  45. return nodes, nil
  46. }
  47. func nametomib(name string) (mib []_C_int, err error) {
  48. // Split name into components.
  49. var parts []string
  50. last := 0
  51. for i := 0; i < len(name); i++ {
  52. if name[i] == '.' {
  53. parts = append(parts, name[last:i])
  54. last = i + 1
  55. }
  56. }
  57. parts = append(parts, name[last:])
  58. // Discover the nodes and construct the MIB OID.
  59. for partno, part := range parts {
  60. nodes, err := sysctlNodes(mib)
  61. if err != nil {
  62. return nil, err
  63. }
  64. for _, node := range nodes {
  65. n := make([]byte, 0)
  66. for i := range node.Name {
  67. if node.Name[i] != 0 {
  68. n = append(n, byte(node.Name[i]))
  69. }
  70. }
  71. if string(n) == part {
  72. mib = append(mib, _C_int(node.Num))
  73. break
  74. }
  75. }
  76. if len(mib) != partno+1 {
  77. return nil, EINVAL
  78. }
  79. }
  80. return mib, nil
  81. }
  82. func direntIno(buf []byte) (uint64, bool) {
  83. return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
  84. }
  85. func direntReclen(buf []byte) (uint64, bool) {
  86. return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
  87. }
  88. func direntNamlen(buf []byte) (uint64, bool) {
  89. return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
  90. }
  91. //sysnb pipe() (fd1 int, fd2 int, err error)
  92. func Pipe(p []int) (err error) {
  93. if len(p) != 2 {
  94. return EINVAL
  95. }
  96. p[0], p[1], err = pipe()
  97. return
  98. }
  99. //sys getdents(fd int, buf []byte) (n int, err error)
  100. func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
  101. return getdents(fd, buf)
  102. }
  103. // TODO
  104. func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  105. return -1, ENOSYS
  106. }
  107. func setattrlistTimes(path string, times []Timespec, flags int) error {
  108. // used on Darwin for UtimesNano
  109. return ENOSYS
  110. }
  111. //sys ioctl(fd int, req uint, arg uintptr) (err error)
  112. // ioctl itself should not be exposed directly, but additional get/set
  113. // functions for specific types are permissible.
  114. // IoctlSetInt performs an ioctl operation which sets an integer value
  115. // on fd, using the specified request number.
  116. func IoctlSetInt(fd int, req uint, value int) error {
  117. return ioctl(fd, req, uintptr(value))
  118. }
  119. func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
  120. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  121. }
  122. func IoctlSetTermios(fd int, req uint, value *Termios) error {
  123. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  124. }
  125. // IoctlGetInt performs an ioctl operation which gets an integer value
  126. // from fd, using the specified request number.
  127. func IoctlGetInt(fd int, req uint) (int, error) {
  128. var value int
  129. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  130. return value, err
  131. }
  132. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  133. var value Winsize
  134. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  135. return &value, err
  136. }
  137. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  138. var value Termios
  139. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  140. return &value, err
  141. }
  142. /*
  143. * Exposed directly
  144. */
  145. //sys Access(path string, mode uint32) (err error)
  146. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  147. //sys Chdir(path string) (err error)
  148. //sys Chflags(path string, flags int) (err error)
  149. //sys Chmod(path string, mode uint32) (err error)
  150. //sys Chown(path string, uid int, gid int) (err error)
  151. //sys Chroot(path string) (err error)
  152. //sys Close(fd int) (err error)
  153. //sys Dup(fd int) (nfd int, err error)
  154. //sys Dup2(from int, to int) (err error)
  155. //sys Exit(code int)
  156. //sys Fchdir(fd int) (err error)
  157. //sys Fchflags(fd int, flags int) (err error)
  158. //sys Fchmod(fd int, mode uint32) (err error)
  159. //sys Fchown(fd int, uid int, gid int) (err error)
  160. //sys Flock(fd int, how int) (err error)
  161. //sys Fpathconf(fd int, name int) (val int, err error)
  162. //sys Fstat(fd int, stat *Stat_t) (err error)
  163. //sys Fsync(fd int) (err error)
  164. //sys Ftruncate(fd int, length int64) (err error)
  165. //sysnb Getegid() (egid int)
  166. //sysnb Geteuid() (uid int)
  167. //sysnb Getgid() (gid int)
  168. //sysnb Getpgid(pid int) (pgid int, err error)
  169. //sysnb Getpgrp() (pgrp int)
  170. //sysnb Getpid() (pid int)
  171. //sysnb Getppid() (ppid int)
  172. //sys Getpriority(which int, who int) (prio int, err error)
  173. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  174. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  175. //sysnb Getsid(pid int) (sid int, err error)
  176. //sysnb Gettimeofday(tv *Timeval) (err error)
  177. //sysnb Getuid() (uid int)
  178. //sys Issetugid() (tainted bool)
  179. //sys Kill(pid int, signum syscall.Signal) (err error)
  180. //sys Kqueue() (fd int, err error)
  181. //sys Lchown(path string, uid int, gid int) (err error)
  182. //sys Link(path string, link string) (err error)
  183. //sys Listen(s int, backlog int) (err error)
  184. //sys Lstat(path string, stat *Stat_t) (err error)
  185. //sys Mkdir(path string, mode uint32) (err error)
  186. //sys Mkfifo(path string, mode uint32) (err error)
  187. //sys Mknod(path string, mode uint32, dev int) (err error)
  188. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  189. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  190. //sys Pathconf(path string, name int) (val int, err error)
  191. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  192. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  193. //sys read(fd int, p []byte) (n int, err error)
  194. //sys Readlink(path string, buf []byte) (n int, err error)
  195. //sys Rename(from string, to string) (err error)
  196. //sys Revoke(path string) (err error)
  197. //sys Rmdir(path string) (err error)
  198. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  199. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  200. //sysnb Setegid(egid int) (err error)
  201. //sysnb Seteuid(euid int) (err error)
  202. //sysnb Setgid(gid int) (err error)
  203. //sysnb Setpgid(pid int, pgid int) (err error)
  204. //sys Setpriority(which int, who int, prio int) (err error)
  205. //sysnb Setregid(rgid int, egid int) (err error)
  206. //sysnb Setreuid(ruid int, euid int) (err error)
  207. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  208. //sysnb Setsid() (pid int, err error)
  209. //sysnb Settimeofday(tp *Timeval) (err error)
  210. //sysnb Setuid(uid int) (err error)
  211. //sys Stat(path string, stat *Stat_t) (err error)
  212. //sys Symlink(path string, link string) (err error)
  213. //sys Sync() (err error)
  214. //sys Truncate(path string, length int64) (err error)
  215. //sys Umask(newmask int) (oldmask int)
  216. //sys Unlink(path string) (err error)
  217. //sys Unmount(path string, flags int) (err error)
  218. //sys write(fd int, p []byte) (n int, err error)
  219. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  220. //sys munmap(addr uintptr, length uintptr) (err error)
  221. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  222. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  223. //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
  224. /*
  225. * Unimplemented
  226. */
  227. // ____semctl13
  228. // __clone
  229. // __fhopen40
  230. // __fhstat40
  231. // __fhstatvfs140
  232. // __fstat30
  233. // __getcwd
  234. // __getfh30
  235. // __getlogin
  236. // __lstat30
  237. // __mount50
  238. // __msgctl13
  239. // __msync13
  240. // __ntp_gettime30
  241. // __posix_chown
  242. // __posix_fadvise50
  243. // __posix_fchown
  244. // __posix_lchown
  245. // __posix_rename
  246. // __setlogin
  247. // __shmctl13
  248. // __sigaction_sigtramp
  249. // __sigaltstack14
  250. // __sigpending14
  251. // __sigprocmask14
  252. // __sigsuspend14
  253. // __sigtimedwait
  254. // __stat30
  255. // __syscall
  256. // __vfork14
  257. // _ksem_close
  258. // _ksem_destroy
  259. // _ksem_getvalue
  260. // _ksem_init
  261. // _ksem_open
  262. // _ksem_post
  263. // _ksem_trywait
  264. // _ksem_unlink
  265. // _ksem_wait
  266. // _lwp_continue
  267. // _lwp_create
  268. // _lwp_ctl
  269. // _lwp_detach
  270. // _lwp_exit
  271. // _lwp_getname
  272. // _lwp_getprivate
  273. // _lwp_kill
  274. // _lwp_park
  275. // _lwp_self
  276. // _lwp_setname
  277. // _lwp_setprivate
  278. // _lwp_suspend
  279. // _lwp_unpark
  280. // _lwp_unpark_all
  281. // _lwp_wait
  282. // _lwp_wakeup
  283. // _pset_bind
  284. // _sched_getaffinity
  285. // _sched_getparam
  286. // _sched_setaffinity
  287. // _sched_setparam
  288. // acct
  289. // aio_cancel
  290. // aio_error
  291. // aio_fsync
  292. // aio_read
  293. // aio_return
  294. // aio_suspend
  295. // aio_write
  296. // break
  297. // clock_getres
  298. // clock_gettime
  299. // clock_settime
  300. // compat_09_ogetdomainname
  301. // compat_09_osetdomainname
  302. // compat_09_ouname
  303. // compat_10_omsgsys
  304. // compat_10_osemsys
  305. // compat_10_oshmsys
  306. // compat_12_fstat12
  307. // compat_12_getdirentries
  308. // compat_12_lstat12
  309. // compat_12_msync
  310. // compat_12_oreboot
  311. // compat_12_oswapon
  312. // compat_12_stat12
  313. // compat_13_sigaction13
  314. // compat_13_sigaltstack13
  315. // compat_13_sigpending13
  316. // compat_13_sigprocmask13
  317. // compat_13_sigreturn13
  318. // compat_13_sigsuspend13
  319. // compat_14___semctl
  320. // compat_14_msgctl
  321. // compat_14_shmctl
  322. // compat_16___sigaction14
  323. // compat_16___sigreturn14
  324. // compat_20_fhstatfs
  325. // compat_20_fstatfs
  326. // compat_20_getfsstat
  327. // compat_20_statfs
  328. // compat_30___fhstat30
  329. // compat_30___fstat13
  330. // compat_30___lstat13
  331. // compat_30___stat13
  332. // compat_30_fhopen
  333. // compat_30_fhstat
  334. // compat_30_fhstatvfs1
  335. // compat_30_getdents
  336. // compat_30_getfh
  337. // compat_30_ntp_gettime
  338. // compat_30_socket
  339. // compat_40_mount
  340. // compat_43_fstat43
  341. // compat_43_lstat43
  342. // compat_43_oaccept
  343. // compat_43_ocreat
  344. // compat_43_oftruncate
  345. // compat_43_ogetdirentries
  346. // compat_43_ogetdtablesize
  347. // compat_43_ogethostid
  348. // compat_43_ogethostname
  349. // compat_43_ogetkerninfo
  350. // compat_43_ogetpagesize
  351. // compat_43_ogetpeername
  352. // compat_43_ogetrlimit
  353. // compat_43_ogetsockname
  354. // compat_43_okillpg
  355. // compat_43_olseek
  356. // compat_43_ommap
  357. // compat_43_oquota
  358. // compat_43_orecv
  359. // compat_43_orecvfrom
  360. // compat_43_orecvmsg
  361. // compat_43_osend
  362. // compat_43_osendmsg
  363. // compat_43_osethostid
  364. // compat_43_osethostname
  365. // compat_43_osetrlimit
  366. // compat_43_osigblock
  367. // compat_43_osigsetmask
  368. // compat_43_osigstack
  369. // compat_43_osigvec
  370. // compat_43_otruncate
  371. // compat_43_owait
  372. // compat_43_stat43
  373. // execve
  374. // extattr_delete_fd
  375. // extattr_delete_file
  376. // extattr_delete_link
  377. // extattr_get_fd
  378. // extattr_get_file
  379. // extattr_get_link
  380. // extattr_list_fd
  381. // extattr_list_file
  382. // extattr_list_link
  383. // extattr_set_fd
  384. // extattr_set_file
  385. // extattr_set_link
  386. // extattrctl
  387. // fchroot
  388. // fdatasync
  389. // fgetxattr
  390. // fktrace
  391. // flistxattr
  392. // fork
  393. // fremovexattr
  394. // fsetxattr
  395. // fstatvfs1
  396. // fsync_range
  397. // getcontext
  398. // getitimer
  399. // getvfsstat
  400. // getxattr
  401. // ktrace
  402. // lchflags
  403. // lchmod
  404. // lfs_bmapv
  405. // lfs_markv
  406. // lfs_segclean
  407. // lfs_segwait
  408. // lgetxattr
  409. // lio_listio
  410. // listxattr
  411. // llistxattr
  412. // lremovexattr
  413. // lseek
  414. // lsetxattr
  415. // lutimes
  416. // madvise
  417. // mincore
  418. // minherit
  419. // modctl
  420. // mq_close
  421. // mq_getattr
  422. // mq_notify
  423. // mq_open
  424. // mq_receive
  425. // mq_send
  426. // mq_setattr
  427. // mq_timedreceive
  428. // mq_timedsend
  429. // mq_unlink
  430. // mremap
  431. // msgget
  432. // msgrcv
  433. // msgsnd
  434. // nfssvc
  435. // ntp_adjtime
  436. // pmc_control
  437. // pmc_get_info
  438. // pollts
  439. // preadv
  440. // profil
  441. // pselect
  442. // pset_assign
  443. // pset_create
  444. // pset_destroy
  445. // ptrace
  446. // pwritev
  447. // quotactl
  448. // rasctl
  449. // readv
  450. // reboot
  451. // removexattr
  452. // sa_enable
  453. // sa_preempt
  454. // sa_register
  455. // sa_setconcurrency
  456. // sa_stacks
  457. // sa_yield
  458. // sbrk
  459. // sched_yield
  460. // semconfig
  461. // semget
  462. // semop
  463. // setcontext
  464. // setitimer
  465. // setxattr
  466. // shmat
  467. // shmdt
  468. // shmget
  469. // sstk
  470. // statvfs1
  471. // swapctl
  472. // sysarch
  473. // syscall
  474. // timer_create
  475. // timer_delete
  476. // timer_getoverrun
  477. // timer_gettime
  478. // timer_settime
  479. // undelete
  480. // utrace
  481. // uuidgen
  482. // vadvise
  483. // vfork
  484. // writev