A lightweight mechanism to provide an *instant kickstart* to a Go web server instance upon changing any Go source files under the project directory (and its subdirectories).

syscall_dragonfly.go 11KB

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