syscall_netbsd.go 14 KB

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