syscall_openbsd.go 7.9 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. n = int(r0)
  103. if e1 != 0 {
  104. err = e1
  105. }
  106. return
  107. }
  108. /*
  109. * Exposed directly
  110. */
  111. //sys Access(path string, mode uint32) (err error)
  112. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  113. //sys Chdir(path string) (err error)
  114. //sys Chflags(path string, flags int) (err error)
  115. //sys Chmod(path string, mode uint32) (err error)
  116. //sys Chown(path string, uid int, gid int) (err error)
  117. //sys Chroot(path string) (err error)
  118. //sys Close(fd int) (err error)
  119. //sys Dup(fd int) (nfd int, err error)
  120. //sys Dup2(from int, to int) (err error)
  121. //sys Exit(code int)
  122. //sys Fchdir(fd int) (err error)
  123. //sys Fchflags(fd int, flags int) (err error)
  124. //sys Fchmod(fd int, mode uint32) (err error)
  125. //sys Fchown(fd int, uid int, gid int) (err error)
  126. //sys Flock(fd int, how int) (err error)
  127. //sys Fpathconf(fd int, name int) (val int, err error)
  128. //sys Fstat(fd int, stat *Stat_t) (err error)
  129. //sys Fstatfs(fd int, stat *Statfs_t) (err error)
  130. //sys Fsync(fd int) (err error)
  131. //sys Ftruncate(fd int, length int64) (err error)
  132. //sysnb Getegid() (egid int)
  133. //sysnb Geteuid() (uid int)
  134. //sysnb Getgid() (gid int)
  135. //sysnb Getpgid(pid int) (pgid int, err error)
  136. //sysnb Getpgrp() (pgrp int)
  137. //sysnb Getpid() (pid int)
  138. //sysnb Getppid() (ppid int)
  139. //sys Getpriority(which int, who int) (prio int, err error)
  140. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  141. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  142. //sysnb Getsid(pid int) (sid int, err error)
  143. //sysnb Gettimeofday(tv *Timeval) (err error)
  144. //sysnb Getuid() (uid int)
  145. //sys Issetugid() (tainted bool)
  146. //sys Kill(pid int, signum syscall.Signal) (err error)
  147. //sys Kqueue() (fd int, err error)
  148. //sys Lchown(path string, uid int, gid int) (err error)
  149. //sys Link(path string, link string) (err error)
  150. //sys Listen(s int, backlog int) (err error)
  151. //sys Lstat(path string, stat *Stat_t) (err error)
  152. //sys Mkdir(path string, mode uint32) (err error)
  153. //sys Mkfifo(path string, mode uint32) (err error)
  154. //sys Mknod(path string, mode uint32, dev int) (err error)
  155. //sys Mlock(b []byte) (err error)
  156. //sys Mlockall(flags int) (err error)
  157. //sys Mprotect(b []byte, prot int) (err error)
  158. //sys Munlock(b []byte) (err error)
  159. //sys Munlockall() (err error)
  160. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  161. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  162. //sys Pathconf(path string, name int) (val int, err error)
  163. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  164. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  165. //sys read(fd int, p []byte) (n int, err error)
  166. //sys Readlink(path string, buf []byte) (n int, err error)
  167. //sys Rename(from string, to string) (err error)
  168. //sys Revoke(path string) (err error)
  169. //sys Rmdir(path string) (err error)
  170. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  171. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  172. //sysnb Setegid(egid int) (err error)
  173. //sysnb Seteuid(euid int) (err error)
  174. //sysnb Setgid(gid int) (err error)
  175. //sys Setlogin(name string) (err error)
  176. //sysnb Setpgid(pid int, pgid int) (err error)
  177. //sys Setpriority(which int, who int, prio int) (err error)
  178. //sysnb Setregid(rgid int, egid int) (err error)
  179. //sysnb Setreuid(ruid int, euid int) (err error)
  180. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  181. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  182. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  183. //sysnb Setsid() (pid int, err error)
  184. //sysnb Settimeofday(tp *Timeval) (err error)
  185. //sysnb Setuid(uid int) (err error)
  186. //sys Stat(path string, stat *Stat_t) (err error)
  187. //sys Statfs(path string, stat *Statfs_t) (err error)
  188. //sys Symlink(path string, link string) (err error)
  189. //sys Sync() (err error)
  190. //sys Truncate(path string, length int64) (err error)
  191. //sys Umask(newmask int) (oldmask int)
  192. //sys Unlink(path string) (err error)
  193. //sys Unmount(path string, flags int) (err error)
  194. //sys write(fd int, p []byte) (n int, err error)
  195. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  196. //sys munmap(addr uintptr, length uintptr) (err error)
  197. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  198. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  199. /*
  200. * Unimplemented
  201. */
  202. // __getcwd
  203. // __semctl
  204. // __syscall
  205. // __sysctl
  206. // adjfreq
  207. // break
  208. // clock_getres
  209. // clock_gettime
  210. // clock_settime
  211. // closefrom
  212. // execve
  213. // faccessat
  214. // fchmodat
  215. // fchownat
  216. // fcntl
  217. // fhopen
  218. // fhstat
  219. // fhstatfs
  220. // fork
  221. // fstatat
  222. // futimens
  223. // getfh
  224. // getgid
  225. // getitimer
  226. // getlogin
  227. // getresgid
  228. // getresuid
  229. // getrtable
  230. // getthrid
  231. // ioctl
  232. // ktrace
  233. // lfs_bmapv
  234. // lfs_markv
  235. // lfs_segclean
  236. // lfs_segwait
  237. // linkat
  238. // mincore
  239. // minherit
  240. // mkdirat
  241. // mkfifoat
  242. // mknodat
  243. // mount
  244. // mquery
  245. // msgctl
  246. // msgget
  247. // msgrcv
  248. // msgsnd
  249. // nfssvc
  250. // nnpfspioctl
  251. // openat
  252. // poll
  253. // preadv
  254. // profil
  255. // pwritev
  256. // quotactl
  257. // readlinkat
  258. // readv
  259. // reboot
  260. // renameat
  261. // rfork
  262. // sched_yield
  263. // semget
  264. // semop
  265. // setgroups
  266. // setitimer
  267. // setrtable
  268. // setsockopt
  269. // shmat
  270. // shmctl
  271. // shmdt
  272. // shmget
  273. // sigaction
  274. // sigaltstack
  275. // sigpending
  276. // sigprocmask
  277. // sigreturn
  278. // sigsuspend
  279. // symlinkat
  280. // sysarch
  281. // syscall
  282. // threxit
  283. // thrsigdivert
  284. // thrsleep
  285. // thrwakeup
  286. // unlinkat
  287. // utimensat
  288. // vfork
  289. // writev