syscall_openbsd.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. // OpenBSD 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. type SockaddrDatalink struct {
  17. Len uint8
  18. Family uint8
  19. Index uint16
  20. Type uint8
  21. Nlen uint8
  22. Alen uint8
  23. Slen uint8
  24. Data [24]int8
  25. raw RawSockaddrDatalink
  26. }
  27. func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
  28. func nametomib(name string) (mib []_C_int, err error) {
  29. // Perform lookup via a binary search
  30. left := 0
  31. right := len(sysctlMib) - 1
  32. for {
  33. idx := left + (right-left)/2
  34. switch {
  35. case name == sysctlMib[idx].ctlname:
  36. return sysctlMib[idx].ctloid, nil
  37. case name > sysctlMib[idx].ctlname:
  38. left = idx + 1
  39. default:
  40. right = idx - 1
  41. }
  42. if left > right {
  43. break
  44. }
  45. }
  46. return nil, EINVAL
  47. }
  48. // ParseDirent parses up to max directory entries in buf,
  49. // appending the names to names. It returns the number
  50. // bytes consumed from buf, the number of entries added
  51. // to names, and the new names slice.
  52. func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
  53. origlen := len(buf)
  54. for max != 0 && len(buf) > 0 {
  55. dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
  56. if dirent.Reclen == 0 {
  57. buf = nil
  58. break
  59. }
  60. buf = buf[dirent.Reclen:]
  61. if dirent.Fileno == 0 { // File absent in directory.
  62. continue
  63. }
  64. bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
  65. var name = string(bytes[0:dirent.Namlen])
  66. if name == "." || name == ".." { // Useless names
  67. continue
  68. }
  69. max--
  70. count++
  71. names = append(names, name)
  72. }
  73. return origlen - len(buf), count, names
  74. }
  75. //sysnb pipe(p *[2]_C_int) (err error)
  76. func Pipe(p []int) (err error) {
  77. if len(p) != 2 {
  78. return EINVAL
  79. }
  80. var pp [2]_C_int
  81. err = pipe(&pp)
  82. p[0] = int(pp[0])
  83. p[1] = int(pp[1])
  84. return
  85. }
  86. //sys getdents(fd int, buf []byte) (n int, err error)
  87. func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
  88. return getdents(fd, buf)
  89. }
  90. // TODO
  91. func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  92. return -1, ENOSYS
  93. }
  94. func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
  95. var _p0 unsafe.Pointer
  96. var bufsize uintptr
  97. if len(buf) > 0 {
  98. _p0 = unsafe.Pointer(&buf[0])
  99. bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
  100. }
  101. r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
  102. use(unsafe.Pointer(_p0))
  103. n = int(r0)
  104. if e1 != 0 {
  105. err = e1
  106. }
  107. return
  108. }
  109. /*
  110. * Exposed directly
  111. */
  112. //sys Access(path string, mode uint32) (err error)
  113. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  114. //sys Chdir(path string) (err error)
  115. //sys Chflags(path string, flags int) (err error)
  116. //sys Chmod(path string, mode uint32) (err error)
  117. //sys Chown(path string, uid int, gid int) (err error)
  118. //sys Chroot(path string) (err error)
  119. //sys Close(fd int) (err error)
  120. //sys Dup(fd int) (nfd int, err error)
  121. //sys Dup2(from int, to int) (err error)
  122. //sys Exit(code int)
  123. //sys Fchdir(fd int) (err error)
  124. //sys Fchflags(fd int, flags int) (err error)
  125. //sys Fchmod(fd int, mode uint32) (err error)
  126. //sys Fchown(fd int, uid int, gid int) (err error)
  127. //sys Flock(fd int, how int) (err error)
  128. //sys Fpathconf(fd int, name int) (val int, err error)
  129. //sys Fstat(fd int, stat *Stat_t) (err error)
  130. //sys Fstatfs(fd int, stat *Statfs_t) (err error)
  131. //sys Fsync(fd int) (err error)
  132. //sys Ftruncate(fd int, length int64) (err error)
  133. //sysnb Getegid() (egid int)
  134. //sysnb Geteuid() (uid int)
  135. //sysnb Getgid() (gid int)
  136. //sysnb Getpgid(pid int) (pgid int, err error)
  137. //sysnb Getpgrp() (pgrp int)
  138. //sysnb Getpid() (pid int)
  139. //sysnb Getppid() (ppid int)
  140. //sys Getpriority(which int, who int) (prio int, err error)
  141. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  142. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  143. //sysnb Getsid(pid int) (sid int, err error)
  144. //sysnb Gettimeofday(tv *Timeval) (err error)
  145. //sysnb Getuid() (uid int)
  146. //sys Issetugid() (tainted bool)
  147. //sys Kill(pid int, signum syscall.Signal) (err error)
  148. //sys Kqueue() (fd int, err error)
  149. //sys Lchown(path string, uid int, gid int) (err error)
  150. //sys Link(path string, link string) (err error)
  151. //sys Listen(s int, backlog int) (err error)
  152. //sys Lstat(path string, stat *Stat_t) (err error)
  153. //sys Mkdir(path string, mode uint32) (err error)
  154. //sys Mkfifo(path string, mode uint32) (err error)
  155. //sys Mknod(path string, mode uint32, dev int) (err error)
  156. //sys Mlock(b []byte) (err error)
  157. //sys Mlockall(flags int) (err error)
  158. //sys Mprotect(b []byte, prot int) (err error)
  159. //sys Munlock(b []byte) (err error)
  160. //sys Munlockall() (err error)
  161. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  162. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  163. //sys Pathconf(path string, name int) (val int, err error)
  164. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  165. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  166. //sys read(fd int, p []byte) (n int, err error)
  167. //sys Readlink(path string, buf []byte) (n int, err error)
  168. //sys Rename(from string, to string) (err error)
  169. //sys Revoke(path string) (err error)
  170. //sys Rmdir(path string) (err error)
  171. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  172. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  173. //sysnb Setegid(egid int) (err error)
  174. //sysnb Seteuid(euid int) (err error)
  175. //sysnb Setgid(gid int) (err error)
  176. //sys Setlogin(name string) (err error)
  177. //sysnb Setpgid(pid int, pgid int) (err error)
  178. //sys Setpriority(which int, who int, prio int) (err error)
  179. //sysnb Setregid(rgid int, egid int) (err error)
  180. //sysnb Setreuid(ruid int, euid int) (err error)
  181. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  182. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  183. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  184. //sysnb Setsid() (pid int, err error)
  185. //sysnb Settimeofday(tp *Timeval) (err error)
  186. //sysnb Setuid(uid int) (err error)
  187. //sys Stat(path string, stat *Stat_t) (err error)
  188. //sys Statfs(path string, stat *Statfs_t) (err error)
  189. //sys Symlink(path string, link string) (err error)
  190. //sys Sync() (err error)
  191. //sys Truncate(path string, length int64) (err error)
  192. //sys Umask(newmask int) (oldmask int)
  193. //sys Unlink(path string) (err error)
  194. //sys Unmount(path string, flags int) (err error)
  195. //sys write(fd int, p []byte) (n int, err error)
  196. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  197. //sys munmap(addr uintptr, length uintptr) (err error)
  198. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  199. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  200. /*
  201. * Unimplemented
  202. */
  203. // __getcwd
  204. // __semctl
  205. // __syscall
  206. // __sysctl
  207. // adjfreq
  208. // break
  209. // clock_getres
  210. // clock_gettime
  211. // clock_settime
  212. // closefrom
  213. // execve
  214. // faccessat
  215. // fchmodat
  216. // fchownat
  217. // fcntl
  218. // fhopen
  219. // fhstat
  220. // fhstatfs
  221. // fork
  222. // fstatat
  223. // futimens
  224. // getfh
  225. // getgid
  226. // getitimer
  227. // getlogin
  228. // getresgid
  229. // getresuid
  230. // getrtable
  231. // getthrid
  232. // ioctl
  233. // ktrace
  234. // lfs_bmapv
  235. // lfs_markv
  236. // lfs_segclean
  237. // lfs_segwait
  238. // linkat
  239. // mincore
  240. // minherit
  241. // mkdirat
  242. // mkfifoat
  243. // mknodat
  244. // mount
  245. // mquery
  246. // msgctl
  247. // msgget
  248. // msgrcv
  249. // msgsnd
  250. // nfssvc
  251. // nnpfspioctl
  252. // openat
  253. // poll
  254. // preadv
  255. // profil
  256. // pwritev
  257. // quotactl
  258. // readlinkat
  259. // readv
  260. // reboot
  261. // renameat
  262. // rfork
  263. // sched_yield
  264. // semget
  265. // semop
  266. // setgroups
  267. // setitimer
  268. // setrtable
  269. // setsockopt
  270. // shmat
  271. // shmctl
  272. // shmdt
  273. // shmget
  274. // sigaction
  275. // sigaltstack
  276. // sigpending
  277. // sigprocmask
  278. // sigreturn
  279. // sigsuspend
  280. // symlinkat
  281. // sysarch
  282. // syscall
  283. // threxit
  284. // thrsigdivert
  285. // thrsleep
  286. // thrwakeup
  287. // unlinkat
  288. // utimensat
  289. // vfork
  290. // writev