syscall_dragonfly.go 11 KB

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