syscall_dragonfly.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. // FreeBSD 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. // ParseDirent parses up to max directory entries in buf,
  51. // appending the names to names. It returns the number
  52. // bytes consumed from buf, the number of entries added
  53. // to names, and the new names slice.
  54. func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
  55. origlen := len(buf)
  56. for max != 0 && len(buf) > 0 {
  57. dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
  58. reclen := int(16+dirent.Namlen+1+7) & ^7
  59. buf = buf[reclen:]
  60. if dirent.Fileno == 0 { // File absent in directory.
  61. continue
  62. }
  63. bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
  64. var name = string(bytes[0:dirent.Namlen])
  65. if name == "." || name == ".." { // Useless names
  66. continue
  67. }
  68. max--
  69. count++
  70. names = append(names, name)
  71. }
  72. return origlen - len(buf), count, names
  73. }
  74. //sysnb pipe() (r int, w int, err error)
  75. func Pipe(p []int) (err error) {
  76. if len(p) != 2 {
  77. return EINVAL
  78. }
  79. p[0], p[1], err = pipe()
  80. return
  81. }
  82. //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error)
  83. func Pread(fd int, p []byte, offset int64) (n int, err error) {
  84. return extpread(fd, p, 0, offset)
  85. }
  86. //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error)
  87. func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
  88. return extpwrite(fd, p, 0, offset)
  89. }
  90. func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
  91. var _p0 unsafe.Pointer
  92. var bufsize uintptr
  93. if len(buf) > 0 {
  94. _p0 = unsafe.Pointer(&buf[0])
  95. bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
  96. }
  97. r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
  98. n = int(r0)
  99. if e1 != 0 {
  100. err = e1
  101. }
  102. return
  103. }
  104. /*
  105. * Exposed directly
  106. */
  107. //sys Access(path string, mode uint32) (err error)
  108. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  109. //sys Chdir(path string) (err error)
  110. //sys Chflags(path string, flags int) (err error)
  111. //sys Chmod(path string, mode uint32) (err error)
  112. //sys Chown(path string, uid int, gid int) (err error)
  113. //sys Chroot(path string) (err error)
  114. //sys Close(fd int) (err error)
  115. //sys Dup(fd int) (nfd int, err error)
  116. //sys Dup2(from int, to int) (err error)
  117. //sys Exit(code int)
  118. //sys Fchdir(fd int) (err error)
  119. //sys Fchflags(fd int, flags int) (err error)
  120. //sys Fchmod(fd int, mode uint32) (err error)
  121. //sys Fchown(fd int, uid int, gid int) (err error)
  122. //sys Flock(fd int, how int) (err error)
  123. //sys Fpathconf(fd int, name int) (val int, err error)
  124. //sys Fstat(fd int, stat *Stat_t) (err error)
  125. //sys Fstatfs(fd int, stat *Statfs_t) (err error)
  126. //sys Fsync(fd int) (err error)
  127. //sys Ftruncate(fd int, length int64) (err error)
  128. //sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
  129. //sys Getdtablesize() (size int)
  130. //sysnb Getegid() (egid int)
  131. //sysnb Geteuid() (uid int)
  132. //sysnb Getgid() (gid int)
  133. //sysnb Getpgid(pid int) (pgid int, err error)
  134. //sysnb Getpgrp() (pgrp int)
  135. //sysnb Getpid() (pid int)
  136. //sysnb Getppid() (ppid int)
  137. //sys Getpriority(which int, who int) (prio int, err error)
  138. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  139. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  140. //sysnb Getsid(pid int) (sid int, err error)
  141. //sysnb Gettimeofday(tv *Timeval) (err error)
  142. //sysnb Getuid() (uid int)
  143. //sys Issetugid() (tainted bool)
  144. //sys Kill(pid int, signum syscall.Signal) (err error)
  145. //sys Kqueue() (fd int, err error)
  146. //sys Lchown(path string, uid int, gid int) (err error)
  147. //sys Link(path string, link string) (err error)
  148. //sys Listen(s int, backlog int) (err error)
  149. //sys Lstat(path string, stat *Stat_t) (err error)
  150. //sys Mkdir(path string, mode uint32) (err error)
  151. //sys Mkfifo(path string, mode uint32) (err error)
  152. //sys Mknod(path string, mode uint32, dev int) (err error)
  153. //sys Mlock(b []byte) (err error)
  154. //sys Mlockall(flags int) (err error)
  155. //sys Mprotect(b []byte, prot int) (err error)
  156. //sys Munlock(b []byte) (err error)
  157. //sys Munlockall() (err error)
  158. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  159. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  160. //sys Pathconf(path string, name int) (val int, err error)
  161. //sys read(fd int, p []byte) (n int, err error)
  162. //sys Readlink(path string, buf []byte) (n int, err error)
  163. //sys Rename(from string, to string) (err error)
  164. //sys Revoke(path string) (err error)
  165. //sys Rmdir(path string) (err error)
  166. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  167. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  168. //sysnb Setegid(egid int) (err error)
  169. //sysnb Seteuid(euid int) (err error)
  170. //sysnb Setgid(gid int) (err error)
  171. //sys Setlogin(name string) (err error)
  172. //sysnb Setpgid(pid int, pgid int) (err error)
  173. //sys Setpriority(which int, who int, prio int) (err error)
  174. //sysnb Setregid(rgid int, egid int) (err error)
  175. //sysnb Setreuid(ruid int, euid int) (err error)
  176. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  177. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  178. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  179. //sysnb Setsid() (pid int, err error)
  180. //sysnb Settimeofday(tp *Timeval) (err error)
  181. //sysnb Setuid(uid int) (err error)
  182. //sys Stat(path string, stat *Stat_t) (err error)
  183. //sys Statfs(path string, stat *Statfs_t) (err error)
  184. //sys Symlink(path string, link string) (err error)
  185. //sys Sync() (err error)
  186. //sys Truncate(path string, length int64) (err error)
  187. //sys Umask(newmask int) (oldmask int)
  188. //sys Undelete(path string) (err error)
  189. //sys Unlink(path string) (err error)
  190. //sys Unmount(path string, flags int) (err error)
  191. //sys write(fd int, p []byte) (n int, err error)
  192. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  193. //sys munmap(addr uintptr, length uintptr) (err error)
  194. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  195. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  196. /*
  197. * Unimplemented
  198. * TODO(jsing): Update this list for DragonFly.
  199. */
  200. // Profil
  201. // Sigaction
  202. // Sigprocmask
  203. // Getlogin
  204. // Sigpending
  205. // Sigaltstack
  206. // Ioctl
  207. // Reboot
  208. // Execve
  209. // Vfork
  210. // Sbrk
  211. // Sstk
  212. // Ovadvise
  213. // Mincore
  214. // Setitimer
  215. // Swapon
  216. // Select
  217. // Sigsuspend
  218. // Readv
  219. // Writev
  220. // Nfssvc
  221. // Getfh
  222. // Quotactl
  223. // Mount
  224. // Csops
  225. // Waitid
  226. // Add_profil
  227. // Kdebug_trace
  228. // Sigreturn
  229. // Mmap
  230. // Atsocket
  231. // Kqueue_from_portset_np
  232. // Kqueue_portset
  233. // Getattrlist
  234. // Setattrlist
  235. // Getdirentriesattr
  236. // Searchfs
  237. // Delete
  238. // Copyfile
  239. // Poll
  240. // Watchevent
  241. // Waitevent
  242. // Modwatch
  243. // Getxattr
  244. // Fgetxattr
  245. // Setxattr
  246. // Fsetxattr
  247. // Removexattr
  248. // Fremovexattr
  249. // Listxattr
  250. // Flistxattr
  251. // Fsctl
  252. // Initgroups
  253. // Posix_spawn
  254. // Nfsclnt
  255. // Fhopen
  256. // Minherit
  257. // Semsys
  258. // Msgsys
  259. // Shmsys
  260. // Semctl
  261. // Semget
  262. // Semop
  263. // Msgctl
  264. // Msgget
  265. // Msgsnd
  266. // Msgrcv
  267. // Shmat
  268. // Shmctl
  269. // Shmdt
  270. // Shmget
  271. // Shm_open
  272. // Shm_unlink
  273. // Sem_open
  274. // Sem_close
  275. // Sem_unlink
  276. // Sem_wait
  277. // Sem_trywait
  278. // Sem_post
  279. // Sem_getvalue
  280. // Sem_init
  281. // Sem_destroy
  282. // Open_extended
  283. // Umask_extended
  284. // Stat_extended
  285. // Lstat_extended
  286. // Fstat_extended
  287. // Chmod_extended
  288. // Fchmod_extended
  289. // Access_extended
  290. // Settid
  291. // Gettid
  292. // Setsgroups
  293. // Getsgroups
  294. // Setwgroups
  295. // Getwgroups
  296. // Mkfifo_extended
  297. // Mkdir_extended
  298. // Identitysvc
  299. // Shared_region_check_np
  300. // Shared_region_map_np
  301. // __pthread_mutex_destroy
  302. // __pthread_mutex_init
  303. // __pthread_mutex_lock
  304. // __pthread_mutex_trylock
  305. // __pthread_mutex_unlock
  306. // __pthread_cond_init
  307. // __pthread_cond_destroy
  308. // __pthread_cond_broadcast
  309. // __pthread_cond_signal
  310. // Setsid_with_pid
  311. // __pthread_cond_timedwait
  312. // Aio_fsync
  313. // Aio_return
  314. // Aio_suspend
  315. // Aio_cancel
  316. // Aio_error
  317. // Aio_read
  318. // Aio_write
  319. // Lio_listio
  320. // __pthread_cond_wait
  321. // Iopolicysys
  322. // __pthread_kill
  323. // __pthread_sigmask
  324. // __sigwait
  325. // __disable_threadsignal
  326. // __pthread_markcancel
  327. // __pthread_canceled
  328. // __semwait_signal
  329. // Proc_info
  330. // Stat64_extended
  331. // Lstat64_extended
  332. // Fstat64_extended
  333. // __pthread_chdir
  334. // __pthread_fchdir
  335. // Audit
  336. // Auditon
  337. // Getauid
  338. // Setauid
  339. // Getaudit
  340. // Setaudit
  341. // Getaudit_addr
  342. // Setaudit_addr
  343. // Auditctl
  344. // Bsdthread_create
  345. // Bsdthread_terminate
  346. // Stack_snapshot
  347. // Bsdthread_register
  348. // Workq_open
  349. // Workq_ops
  350. // __mac_execve
  351. // __mac_syscall
  352. // __mac_get_file
  353. // __mac_set_file
  354. // __mac_get_link
  355. // __mac_set_link
  356. // __mac_get_proc
  357. // __mac_set_proc
  358. // __mac_get_fd
  359. // __mac_set_fd
  360. // __mac_get_pid
  361. // __mac_get_lcid
  362. // __mac_get_lctx
  363. // __mac_set_lctx
  364. // Setlcid
  365. // Read_nocancel
  366. // Write_nocancel
  367. // Open_nocancel
  368. // Close_nocancel
  369. // Wait4_nocancel
  370. // Recvmsg_nocancel
  371. // Sendmsg_nocancel
  372. // Recvfrom_nocancel
  373. // Accept_nocancel
  374. // Msync_nocancel
  375. // Fcntl_nocancel
  376. // Select_nocancel
  377. // Fsync_nocancel
  378. // Connect_nocancel
  379. // Sigsuspend_nocancel
  380. // Readv_nocancel
  381. // Writev_nocancel
  382. // Sendto_nocancel
  383. // Pread_nocancel
  384. // Pwrite_nocancel
  385. // Waitid_nocancel
  386. // Poll_nocancel
  387. // Msgsnd_nocancel
  388. // Msgrcv_nocancel
  389. // Sem_wait_nocancel
  390. // Aio_suspend_nocancel
  391. // __sigwait_nocancel
  392. // __semwait_signal_nocancel
  393. // __mac_mount
  394. // __mac_get_mount
  395. // __mac_getfsstat