syscall_netbsd.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. // ParseDirent parses up to max directory entries in buf,
  83. // appending the names to names. It returns the number
  84. // bytes consumed from buf, the number of entries added
  85. // to names, and the new names slice.
  86. func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
  87. origlen := len(buf)
  88. for max != 0 && len(buf) > 0 {
  89. dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
  90. if dirent.Reclen == 0 {
  91. buf = nil
  92. break
  93. }
  94. buf = buf[dirent.Reclen:]
  95. if dirent.Fileno == 0 { // File absent in directory.
  96. continue
  97. }
  98. bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
  99. var name = string(bytes[0:dirent.Namlen])
  100. if name == "." || name == ".." { // Useless names
  101. continue
  102. }
  103. max--
  104. count++
  105. names = append(names, name)
  106. }
  107. return origlen - len(buf), count, names
  108. }
  109. //sysnb pipe() (fd1 int, fd2 int, err error)
  110. func Pipe(p []int) (err error) {
  111. if len(p) != 2 {
  112. return EINVAL
  113. }
  114. p[0], p[1], err = pipe()
  115. return
  116. }
  117. //sys getdents(fd int, buf []byte) (n int, err error)
  118. func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
  119. return getdents(fd, buf)
  120. }
  121. // TODO
  122. func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  123. return -1, ENOSYS
  124. }
  125. /*
  126. * Exposed directly
  127. */
  128. //sys Access(path string, mode uint32) (err error)
  129. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  130. //sys Chdir(path string) (err error)
  131. //sys Chflags(path string, flags int) (err error)
  132. //sys Chmod(path string, mode uint32) (err error)
  133. //sys Chown(path string, uid int, gid int) (err error)
  134. //sys Chroot(path string) (err error)
  135. //sys Close(fd int) (err error)
  136. //sys Dup(fd int) (nfd int, err error)
  137. //sys Dup2(from int, to int) (err error)
  138. //sys Exit(code int)
  139. //sys Fchdir(fd int) (err error)
  140. //sys Fchflags(fd int, flags int) (err error)
  141. //sys Fchmod(fd int, mode uint32) (err error)
  142. //sys Fchown(fd int, uid int, gid int) (err error)
  143. //sys Flock(fd int, how int) (err error)
  144. //sys Fpathconf(fd int, name int) (val int, err error)
  145. //sys Fstat(fd int, stat *Stat_t) (err error)
  146. //sys Fsync(fd int) (err error)
  147. //sys Ftruncate(fd int, length int64) (err error)
  148. //sysnb Getegid() (egid int)
  149. //sysnb Geteuid() (uid int)
  150. //sysnb Getgid() (gid int)
  151. //sysnb Getpgid(pid int) (pgid int, err error)
  152. //sysnb Getpgrp() (pgrp int)
  153. //sysnb Getpid() (pid int)
  154. //sysnb Getppid() (ppid int)
  155. //sys Getpriority(which int, who int) (prio int, err error)
  156. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  157. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  158. //sysnb Getsid(pid int) (sid int, err error)
  159. //sysnb Gettimeofday(tv *Timeval) (err error)
  160. //sysnb Getuid() (uid int)
  161. //sys Issetugid() (tainted bool)
  162. //sys Kill(pid int, signum syscall.Signal) (err error)
  163. //sys Kqueue() (fd int, err error)
  164. //sys Lchown(path string, uid int, gid int) (err error)
  165. //sys Link(path string, link string) (err error)
  166. //sys Listen(s int, backlog int) (err error)
  167. //sys Lstat(path string, stat *Stat_t) (err error)
  168. //sys Mkdir(path string, mode uint32) (err error)
  169. //sys Mkfifo(path string, mode uint32) (err error)
  170. //sys Mknod(path string, mode uint32, dev int) (err error)
  171. //sys Mlock(b []byte) (err error)
  172. //sys Mlockall(flags int) (err error)
  173. //sys Mprotect(b []byte, prot int) (err error)
  174. //sys Munlock(b []byte) (err error)
  175. //sys Munlockall() (err error)
  176. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  177. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  178. //sys Pathconf(path string, name int) (val int, err error)
  179. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  180. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  181. //sys read(fd int, p []byte) (n int, err error)
  182. //sys Readlink(path string, buf []byte) (n int, err error)
  183. //sys Rename(from string, to string) (err error)
  184. //sys Revoke(path string) (err error)
  185. //sys Rmdir(path string) (err error)
  186. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  187. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  188. //sysnb Setegid(egid int) (err error)
  189. //sysnb Seteuid(euid int) (err error)
  190. //sysnb Setgid(gid int) (err error)
  191. //sysnb Setpgid(pid int, pgid int) (err error)
  192. //sys Setpriority(which int, who int, prio int) (err error)
  193. //sysnb Setregid(rgid int, egid int) (err error)
  194. //sysnb Setreuid(ruid int, euid int) (err error)
  195. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  196. //sysnb Setsid() (pid int, err error)
  197. //sysnb Settimeofday(tp *Timeval) (err error)
  198. //sysnb Setuid(uid int) (err error)
  199. //sys Stat(path string, stat *Stat_t) (err error)
  200. //sys Symlink(path string, link string) (err error)
  201. //sys Sync() (err error)
  202. //sys Truncate(path string, length int64) (err error)
  203. //sys Umask(newmask int) (oldmask int)
  204. //sys Unlink(path string) (err error)
  205. //sys Unmount(path string, flags int) (err error)
  206. //sys write(fd int, p []byte) (n int, err error)
  207. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  208. //sys munmap(addr uintptr, length uintptr) (err error)
  209. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  210. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  211. /*
  212. * Unimplemented
  213. */
  214. // ____semctl13
  215. // __clone
  216. // __fhopen40
  217. // __fhstat40
  218. // __fhstatvfs140
  219. // __fstat30
  220. // __getcwd
  221. // __getfh30
  222. // __getlogin
  223. // __lstat30
  224. // __mount50
  225. // __msgctl13
  226. // __msync13
  227. // __ntp_gettime30
  228. // __posix_chown
  229. // __posix_fadvise50
  230. // __posix_fchown
  231. // __posix_lchown
  232. // __posix_rename
  233. // __setlogin
  234. // __shmctl13
  235. // __sigaction_sigtramp
  236. // __sigaltstack14
  237. // __sigpending14
  238. // __sigprocmask14
  239. // __sigsuspend14
  240. // __sigtimedwait
  241. // __stat30
  242. // __syscall
  243. // __vfork14
  244. // _ksem_close
  245. // _ksem_destroy
  246. // _ksem_getvalue
  247. // _ksem_init
  248. // _ksem_open
  249. // _ksem_post
  250. // _ksem_trywait
  251. // _ksem_unlink
  252. // _ksem_wait
  253. // _lwp_continue
  254. // _lwp_create
  255. // _lwp_ctl
  256. // _lwp_detach
  257. // _lwp_exit
  258. // _lwp_getname
  259. // _lwp_getprivate
  260. // _lwp_kill
  261. // _lwp_park
  262. // _lwp_self
  263. // _lwp_setname
  264. // _lwp_setprivate
  265. // _lwp_suspend
  266. // _lwp_unpark
  267. // _lwp_unpark_all
  268. // _lwp_wait
  269. // _lwp_wakeup
  270. // _pset_bind
  271. // _sched_getaffinity
  272. // _sched_getparam
  273. // _sched_setaffinity
  274. // _sched_setparam
  275. // acct
  276. // aio_cancel
  277. // aio_error
  278. // aio_fsync
  279. // aio_read
  280. // aio_return
  281. // aio_suspend
  282. // aio_write
  283. // break
  284. // clock_getres
  285. // clock_gettime
  286. // clock_settime
  287. // compat_09_ogetdomainname
  288. // compat_09_osetdomainname
  289. // compat_09_ouname
  290. // compat_10_omsgsys
  291. // compat_10_osemsys
  292. // compat_10_oshmsys
  293. // compat_12_fstat12
  294. // compat_12_getdirentries
  295. // compat_12_lstat12
  296. // compat_12_msync
  297. // compat_12_oreboot
  298. // compat_12_oswapon
  299. // compat_12_stat12
  300. // compat_13_sigaction13
  301. // compat_13_sigaltstack13
  302. // compat_13_sigpending13
  303. // compat_13_sigprocmask13
  304. // compat_13_sigreturn13
  305. // compat_13_sigsuspend13
  306. // compat_14___semctl
  307. // compat_14_msgctl
  308. // compat_14_shmctl
  309. // compat_16___sigaction14
  310. // compat_16___sigreturn14
  311. // compat_20_fhstatfs
  312. // compat_20_fstatfs
  313. // compat_20_getfsstat
  314. // compat_20_statfs
  315. // compat_30___fhstat30
  316. // compat_30___fstat13
  317. // compat_30___lstat13
  318. // compat_30___stat13
  319. // compat_30_fhopen
  320. // compat_30_fhstat
  321. // compat_30_fhstatvfs1
  322. // compat_30_getdents
  323. // compat_30_getfh
  324. // compat_30_ntp_gettime
  325. // compat_30_socket
  326. // compat_40_mount
  327. // compat_43_fstat43
  328. // compat_43_lstat43
  329. // compat_43_oaccept
  330. // compat_43_ocreat
  331. // compat_43_oftruncate
  332. // compat_43_ogetdirentries
  333. // compat_43_ogetdtablesize
  334. // compat_43_ogethostid
  335. // compat_43_ogethostname
  336. // compat_43_ogetkerninfo
  337. // compat_43_ogetpagesize
  338. // compat_43_ogetpeername
  339. // compat_43_ogetrlimit
  340. // compat_43_ogetsockname
  341. // compat_43_okillpg
  342. // compat_43_olseek
  343. // compat_43_ommap
  344. // compat_43_oquota
  345. // compat_43_orecv
  346. // compat_43_orecvfrom
  347. // compat_43_orecvmsg
  348. // compat_43_osend
  349. // compat_43_osendmsg
  350. // compat_43_osethostid
  351. // compat_43_osethostname
  352. // compat_43_osetrlimit
  353. // compat_43_osigblock
  354. // compat_43_osigsetmask
  355. // compat_43_osigstack
  356. // compat_43_osigvec
  357. // compat_43_otruncate
  358. // compat_43_owait
  359. // compat_43_stat43
  360. // execve
  361. // extattr_delete_fd
  362. // extattr_delete_file
  363. // extattr_delete_link
  364. // extattr_get_fd
  365. // extattr_get_file
  366. // extattr_get_link
  367. // extattr_list_fd
  368. // extattr_list_file
  369. // extattr_list_link
  370. // extattr_set_fd
  371. // extattr_set_file
  372. // extattr_set_link
  373. // extattrctl
  374. // fchroot
  375. // fdatasync
  376. // fgetxattr
  377. // fktrace
  378. // flistxattr
  379. // fork
  380. // fremovexattr
  381. // fsetxattr
  382. // fstatvfs1
  383. // fsync_range
  384. // getcontext
  385. // getitimer
  386. // getvfsstat
  387. // getxattr
  388. // ioctl
  389. // ktrace
  390. // lchflags
  391. // lchmod
  392. // lfs_bmapv
  393. // lfs_markv
  394. // lfs_segclean
  395. // lfs_segwait
  396. // lgetxattr
  397. // lio_listio
  398. // listxattr
  399. // llistxattr
  400. // lremovexattr
  401. // lseek
  402. // lsetxattr
  403. // lutimes
  404. // madvise
  405. // mincore
  406. // minherit
  407. // modctl
  408. // mq_close
  409. // mq_getattr
  410. // mq_notify
  411. // mq_open
  412. // mq_receive
  413. // mq_send
  414. // mq_setattr
  415. // mq_timedreceive
  416. // mq_timedsend
  417. // mq_unlink
  418. // mremap
  419. // msgget
  420. // msgrcv
  421. // msgsnd
  422. // nfssvc
  423. // ntp_adjtime
  424. // pmc_control
  425. // pmc_get_info
  426. // poll
  427. // pollts
  428. // preadv
  429. // profil
  430. // pselect
  431. // pset_assign
  432. // pset_create
  433. // pset_destroy
  434. // ptrace
  435. // pwritev
  436. // quotactl
  437. // rasctl
  438. // readv
  439. // reboot
  440. // removexattr
  441. // sa_enable
  442. // sa_preempt
  443. // sa_register
  444. // sa_setconcurrency
  445. // sa_stacks
  446. // sa_yield
  447. // sbrk
  448. // sched_yield
  449. // semconfig
  450. // semget
  451. // semop
  452. // setcontext
  453. // setitimer
  454. // setxattr
  455. // shmat
  456. // shmdt
  457. // shmget
  458. // sstk
  459. // statvfs1
  460. // swapctl
  461. // sysarch
  462. // syscall
  463. // timer_create
  464. // timer_delete
  465. // timer_getoverrun
  466. // timer_gettime
  467. // timer_settime
  468. // undelete
  469. // utrace
  470. // uuidgen
  471. // vadvise
  472. // vfork
  473. // writev