syscall_dragonfly.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. // Copyright 2009 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. // DragonFly BSD 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 "unsafe"
  13. type SockaddrDatalink struct {
  14. Len uint8
  15. Family uint8
  16. Index uint16
  17. Type uint8
  18. Nlen uint8
  19. Alen uint8
  20. Slen uint8
  21. Data [12]int8
  22. Rcf uint16
  23. Route [16]uint16
  24. raw RawSockaddrDatalink
  25. }
  26. // Translate "kern.hostname" to []_C_int{0,1,2,3}.
  27. func nametomib(name string) (mib []_C_int, err error) {
  28. const siz = unsafe.Sizeof(mib[0])
  29. // NOTE(rsc): It seems strange to set the buffer to have
  30. // size CTL_MAXNAME+2 but use only CTL_MAXNAME
  31. // as the size. I don't know why the +2 is here, but the
  32. // kernel uses +2 for its own implementation of this function.
  33. // I am scared that if we don't include the +2 here, the kernel
  34. // will silently write 2 words farther than we specify
  35. // and we'll get memory corruption.
  36. var buf [CTL_MAXNAME + 2]_C_int
  37. n := uintptr(CTL_MAXNAME) * siz
  38. p := (*byte)(unsafe.Pointer(&buf[0]))
  39. bytes, err := ByteSliceFromString(name)
  40. if err != nil {
  41. return nil, err
  42. }
  43. // Magic sysctl: "setting" 0.3 to a string name
  44. // lets you read back the array of integers form.
  45. if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil {
  46. return nil, err
  47. }
  48. return buf[0 : n/siz], nil
  49. }
  50. func direntIno(buf []byte) (uint64, bool) {
  51. return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
  52. }
  53. func direntReclen(buf []byte) (uint64, bool) {
  54. namlen, ok := direntNamlen(buf)
  55. if !ok {
  56. return 0, false
  57. }
  58. return (16 + namlen + 1 + 7) &^ 7, true
  59. }
  60. func direntNamlen(buf []byte) (uint64, bool) {
  61. return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
  62. }
  63. //sysnb pipe() (r int, w int, err error)
  64. func Pipe(p []int) (err error) {
  65. if len(p) != 2 {
  66. return EINVAL
  67. }
  68. p[0], p[1], err = pipe()
  69. return
  70. }
  71. //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error)
  72. func Pread(fd int, p []byte, offset int64) (n int, err error) {
  73. return extpread(fd, p, 0, offset)
  74. }
  75. //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error)
  76. func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
  77. return extpwrite(fd, p, 0, offset)
  78. }
  79. func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
  80. var rsa RawSockaddrAny
  81. var len _Socklen = SizeofSockaddrAny
  82. nfd, err = accept4(fd, &rsa, &len, flags)
  83. if err != nil {
  84. return
  85. }
  86. if len > SizeofSockaddrAny {
  87. panic("RawSockaddrAny too small")
  88. }
  89. sa, err = anyToSockaddr(&rsa)
  90. if err != nil {
  91. Close(nfd)
  92. nfd = 0
  93. }
  94. return
  95. }
  96. func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
  97. var _p0 unsafe.Pointer
  98. var bufsize uintptr
  99. if len(buf) > 0 {
  100. _p0 = unsafe.Pointer(&buf[0])
  101. bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
  102. }
  103. r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
  104. n = int(r0)
  105. if e1 != 0 {
  106. err = e1
  107. }
  108. return
  109. }
  110. func setattrlistTimes(path string, times []Timespec, flags int) error {
  111. // used on Darwin for UtimesNano
  112. return ENOSYS
  113. }
  114. //sys ioctl(fd int, req uint, arg uintptr) (err error)
  115. // ioctl itself should not be exposed directly, but additional get/set
  116. // functions for specific types are permissible.
  117. // IoctlSetInt performs an ioctl operation which sets an integer value
  118. // on fd, using the specified request number.
  119. func IoctlSetInt(fd int, req uint, value int) error {
  120. return ioctl(fd, req, uintptr(value))
  121. }
  122. func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
  123. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  124. }
  125. func IoctlSetTermios(fd int, req uint, value *Termios) error {
  126. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  127. }
  128. // IoctlGetInt performs an ioctl operation which gets an integer value
  129. // from fd, using the specified request number.
  130. func IoctlGetInt(fd int, req uint) (int, error) {
  131. var value int
  132. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  133. return value, err
  134. }
  135. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  136. var value Winsize
  137. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  138. return &value, err
  139. }
  140. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  141. var value Termios
  142. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  143. return &value, err
  144. }
  145. /*
  146. * Exposed directly
  147. */
  148. //sys Access(path string, mode uint32) (err error)
  149. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  150. //sys Chdir(path string) (err error)
  151. //sys Chflags(path string, flags int) (err error)
  152. //sys Chmod(path string, mode uint32) (err error)
  153. //sys Chown(path string, uid int, gid int) (err error)
  154. //sys Chroot(path string) (err error)
  155. //sys Close(fd int) (err error)
  156. //sys Dup(fd int) (nfd int, err error)
  157. //sys Dup2(from int, to int) (err error)
  158. //sys Exit(code int)
  159. //sys Fchdir(fd int) (err error)
  160. //sys Fchflags(fd int, flags int) (err error)
  161. //sys Fchmod(fd int, mode uint32) (err error)
  162. //sys Fchown(fd int, uid int, gid int) (err error)
  163. //sys Flock(fd int, how int) (err error)
  164. //sys Fpathconf(fd int, name int) (val int, err error)
  165. //sys Fstat(fd int, stat *Stat_t) (err error)
  166. //sys Fstatfs(fd int, stat *Statfs_t) (err error)
  167. //sys Fsync(fd int) (err error)
  168. //sys Ftruncate(fd int, length int64) (err error)
  169. //sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
  170. //sys Getdtablesize() (size int)
  171. //sysnb Getegid() (egid int)
  172. //sysnb Geteuid() (uid int)
  173. //sysnb Getgid() (gid int)
  174. //sysnb Getpgid(pid int) (pgid int, err error)
  175. //sysnb Getpgrp() (pgrp int)
  176. //sysnb Getpid() (pid int)
  177. //sysnb Getppid() (ppid int)
  178. //sys Getpriority(which int, who int) (prio int, err error)
  179. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  180. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  181. //sysnb Getsid(pid int) (sid int, err error)
  182. //sysnb Gettimeofday(tv *Timeval) (err error)
  183. //sysnb Getuid() (uid int)
  184. //sys Issetugid() (tainted bool)
  185. //sys Kill(pid int, signum syscall.Signal) (err error)
  186. //sys Kqueue() (fd int, err error)
  187. //sys Lchown(path string, uid int, gid int) (err error)
  188. //sys Link(path string, link string) (err error)
  189. //sys Listen(s int, backlog int) (err error)
  190. //sys Lstat(path string, stat *Stat_t) (err error)
  191. //sys Mkdir(path string, mode uint32) (err error)
  192. //sys Mkfifo(path string, mode uint32) (err error)
  193. //sys Mknod(path string, mode uint32, dev int) (err error)
  194. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  195. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  196. //sys Pathconf(path string, name int) (val int, err error)
  197. //sys read(fd int, p []byte) (n int, err error)
  198. //sys Readlink(path string, buf []byte) (n int, err error)
  199. //sys Rename(from string, to string) (err error)
  200. //sys Revoke(path string) (err error)
  201. //sys Rmdir(path string) (err error)
  202. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  203. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  204. //sysnb Setegid(egid int) (err error)
  205. //sysnb Seteuid(euid int) (err error)
  206. //sysnb Setgid(gid int) (err error)
  207. //sys Setlogin(name string) (err error)
  208. //sysnb Setpgid(pid int, pgid int) (err error)
  209. //sys Setpriority(which int, who int, prio int) (err error)
  210. //sysnb Setregid(rgid int, egid int) (err error)
  211. //sysnb Setreuid(ruid int, euid int) (err error)
  212. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  213. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  214. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  215. //sysnb Setsid() (pid int, err error)
  216. //sysnb Settimeofday(tp *Timeval) (err error)
  217. //sysnb Setuid(uid int) (err error)
  218. //sys Stat(path string, stat *Stat_t) (err error)
  219. //sys Statfs(path string, stat *Statfs_t) (err error)
  220. //sys Symlink(path string, link string) (err error)
  221. //sys Sync() (err error)
  222. //sys Truncate(path string, length int64) (err error)
  223. //sys Umask(newmask int) (oldmask int)
  224. //sys Undelete(path string) (err error)
  225. //sys Unlink(path string) (err error)
  226. //sys Unmount(path string, flags int) (err error)
  227. //sys write(fd int, p []byte) (n int, err error)
  228. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  229. //sys munmap(addr uintptr, length uintptr) (err error)
  230. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  231. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  232. //sys accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error)
  233. //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
  234. /*
  235. * Unimplemented
  236. * TODO(jsing): Update this list for DragonFly.
  237. */
  238. // Profil
  239. // Sigaction
  240. // Sigprocmask
  241. // Getlogin
  242. // Sigpending
  243. // Sigaltstack
  244. // Reboot
  245. // Execve
  246. // Vfork
  247. // Sbrk
  248. // Sstk
  249. // Ovadvise
  250. // Mincore
  251. // Setitimer
  252. // Swapon
  253. // Select
  254. // Sigsuspend
  255. // Readv
  256. // Writev
  257. // Nfssvc
  258. // Getfh
  259. // Quotactl
  260. // Mount
  261. // Csops
  262. // Waitid
  263. // Add_profil
  264. // Kdebug_trace
  265. // Sigreturn
  266. // Atsocket
  267. // Kqueue_from_portset_np
  268. // Kqueue_portset
  269. // Getattrlist
  270. // Setattrlist
  271. // Getdirentriesattr
  272. // Searchfs
  273. // Delete
  274. // Copyfile
  275. // Watchevent
  276. // Waitevent
  277. // Modwatch
  278. // Getxattr
  279. // Fgetxattr
  280. // Setxattr
  281. // Fsetxattr
  282. // Removexattr
  283. // Fremovexattr
  284. // Listxattr
  285. // Flistxattr
  286. // Fsctl
  287. // Initgroups
  288. // Posix_spawn
  289. // Nfsclnt
  290. // Fhopen
  291. // Minherit
  292. // Semsys
  293. // Msgsys
  294. // Shmsys
  295. // Semctl
  296. // Semget
  297. // Semop
  298. // Msgctl
  299. // Msgget
  300. // Msgsnd
  301. // Msgrcv
  302. // Shmat
  303. // Shmctl
  304. // Shmdt
  305. // Shmget
  306. // Shm_open
  307. // Shm_unlink
  308. // Sem_open
  309. // Sem_close
  310. // Sem_unlink
  311. // Sem_wait
  312. // Sem_trywait
  313. // Sem_post
  314. // Sem_getvalue
  315. // Sem_init
  316. // Sem_destroy
  317. // Open_extended
  318. // Umask_extended
  319. // Stat_extended
  320. // Lstat_extended
  321. // Fstat_extended
  322. // Chmod_extended
  323. // Fchmod_extended
  324. // Access_extended
  325. // Settid
  326. // Gettid
  327. // Setsgroups
  328. // Getsgroups
  329. // Setwgroups
  330. // Getwgroups
  331. // Mkfifo_extended
  332. // Mkdir_extended
  333. // Identitysvc
  334. // Shared_region_check_np
  335. // Shared_region_map_np
  336. // __pthread_mutex_destroy
  337. // __pthread_mutex_init
  338. // __pthread_mutex_lock
  339. // __pthread_mutex_trylock
  340. // __pthread_mutex_unlock
  341. // __pthread_cond_init
  342. // __pthread_cond_destroy
  343. // __pthread_cond_broadcast
  344. // __pthread_cond_signal
  345. // Setsid_with_pid
  346. // __pthread_cond_timedwait
  347. // Aio_fsync
  348. // Aio_return
  349. // Aio_suspend
  350. // Aio_cancel
  351. // Aio_error
  352. // Aio_read
  353. // Aio_write
  354. // Lio_listio
  355. // __pthread_cond_wait
  356. // Iopolicysys
  357. // __pthread_kill
  358. // __pthread_sigmask
  359. // __sigwait
  360. // __disable_threadsignal
  361. // __pthread_markcancel
  362. // __pthread_canceled
  363. // __semwait_signal
  364. // Proc_info
  365. // Stat64_extended
  366. // Lstat64_extended
  367. // Fstat64_extended
  368. // __pthread_chdir
  369. // __pthread_fchdir
  370. // Audit
  371. // Auditon
  372. // Getauid
  373. // Setauid
  374. // Getaudit
  375. // Setaudit
  376. // Getaudit_addr
  377. // Setaudit_addr
  378. // Auditctl
  379. // Bsdthread_create
  380. // Bsdthread_terminate
  381. // Stack_snapshot
  382. // Bsdthread_register
  383. // Workq_open
  384. // Workq_ops
  385. // __mac_execve
  386. // __mac_syscall
  387. // __mac_get_file
  388. // __mac_set_file
  389. // __mac_get_link
  390. // __mac_set_link
  391. // __mac_get_proc
  392. // __mac_set_proc
  393. // __mac_get_fd
  394. // __mac_set_fd
  395. // __mac_get_pid
  396. // __mac_get_lcid
  397. // __mac_get_lctx
  398. // __mac_set_lctx
  399. // Setlcid
  400. // Read_nocancel
  401. // Write_nocancel
  402. // Open_nocancel
  403. // Close_nocancel
  404. // Wait4_nocancel
  405. // Recvmsg_nocancel
  406. // Sendmsg_nocancel
  407. // Recvfrom_nocancel
  408. // Accept_nocancel
  409. // Fcntl_nocancel
  410. // Select_nocancel
  411. // Fsync_nocancel
  412. // Connect_nocancel
  413. // Sigsuspend_nocancel
  414. // Readv_nocancel
  415. // Writev_nocancel
  416. // Sendto_nocancel
  417. // Pread_nocancel
  418. // Pwrite_nocancel
  419. // Waitid_nocancel
  420. // Msgsnd_nocancel
  421. // Msgrcv_nocancel
  422. // Sem_wait_nocancel
  423. // Aio_suspend_nocancel
  424. // __sigwait_nocancel
  425. // __semwait_signal_nocancel
  426. // __mac_mount
  427. // __mac_get_mount
  428. // __mac_getfsstat