syscall_openbsd.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. func direntIno(buf []byte) (uint64, bool) {
  49. return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
  50. }
  51. func direntReclen(buf []byte) (uint64, bool) {
  52. return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
  53. }
  54. func direntNamlen(buf []byte) (uint64, bool) {
  55. return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
  56. }
  57. //sysnb pipe(p *[2]_C_int) (err error)
  58. func Pipe(p []int) (err error) {
  59. if len(p) != 2 {
  60. return EINVAL
  61. }
  62. var pp [2]_C_int
  63. err = pipe(&pp)
  64. p[0] = int(pp[0])
  65. p[1] = int(pp[1])
  66. return
  67. }
  68. //sys getdents(fd int, buf []byte) (n int, err error)
  69. func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
  70. return getdents(fd, buf)
  71. }
  72. // TODO
  73. func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  74. return -1, ENOSYS
  75. }
  76. func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
  77. var _p0 unsafe.Pointer
  78. var bufsize uintptr
  79. if len(buf) > 0 {
  80. _p0 = unsafe.Pointer(&buf[0])
  81. bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
  82. }
  83. r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
  84. n = int(r0)
  85. if e1 != 0 {
  86. err = e1
  87. }
  88. return
  89. }
  90. func setattrlistTimes(path string, times []Timespec, flags int) error {
  91. // used on Darwin for UtimesNano
  92. return ENOSYS
  93. }
  94. //sys ioctl(fd int, req uint, arg uintptr) (err error)
  95. // ioctl itself should not be exposed directly, but additional get/set
  96. // functions for specific types are permissible.
  97. // IoctlSetInt performs an ioctl operation which sets an integer value
  98. // on fd, using the specified request number.
  99. func IoctlSetInt(fd int, req uint, value int) error {
  100. return ioctl(fd, req, uintptr(value))
  101. }
  102. func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
  103. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  104. }
  105. func IoctlSetTermios(fd int, req uint, value *Termios) error {
  106. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  107. }
  108. // IoctlGetInt performs an ioctl operation which gets an integer value
  109. // from fd, using the specified request number.
  110. func IoctlGetInt(fd int, req uint) (int, error) {
  111. var value int
  112. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  113. return value, err
  114. }
  115. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  116. var value Winsize
  117. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  118. return &value, err
  119. }
  120. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  121. var value Termios
  122. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  123. return &value, err
  124. }
  125. /*
  126. * Exposed directly
  127. */
  128. //sys Access(path string, mode uint32) (err error)
  129. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  130. //sys Chdir(path string) (err error)
  131. //sys Chflags(path string, flags int) (err error)
  132. //sys Chmod(path string, mode uint32) (err error)
  133. //sys Chown(path string, uid int, gid int) (err error)
  134. //sys Chroot(path string) (err error)
  135. //sys Close(fd int) (err error)
  136. //sys Dup(fd int) (nfd int, err error)
  137. //sys Dup2(from int, to int) (err error)
  138. //sys Exit(code int)
  139. //sys Fchdir(fd int) (err error)
  140. //sys Fchflags(fd int, flags int) (err error)
  141. //sys Fchmod(fd int, mode uint32) (err error)
  142. //sys Fchown(fd int, uid int, gid int) (err error)
  143. //sys Flock(fd int, how int) (err error)
  144. //sys Fpathconf(fd int, name int) (val int, err error)
  145. //sys Fstat(fd int, stat *Stat_t) (err error)
  146. //sys Fstatfs(fd int, stat *Statfs_t) (err error)
  147. //sys Fsync(fd int) (err error)
  148. //sys Ftruncate(fd int, length int64) (err error)
  149. //sysnb Getegid() (egid int)
  150. //sysnb Geteuid() (uid int)
  151. //sysnb Getgid() (gid int)
  152. //sysnb Getpgid(pid int) (pgid int, err error)
  153. //sysnb Getpgrp() (pgrp int)
  154. //sysnb Getpid() (pid int)
  155. //sysnb Getppid() (ppid int)
  156. //sys Getpriority(which int, who int) (prio int, err error)
  157. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  158. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  159. //sysnb Getsid(pid int) (sid int, err error)
  160. //sysnb Gettimeofday(tv *Timeval) (err error)
  161. //sysnb Getuid() (uid int)
  162. //sys Issetugid() (tainted bool)
  163. //sys Kill(pid int, signum syscall.Signal) (err error)
  164. //sys Kqueue() (fd int, err error)
  165. //sys Lchown(path string, uid int, gid int) (err error)
  166. //sys Link(path string, link string) (err error)
  167. //sys Listen(s int, backlog int) (err error)
  168. //sys Lstat(path string, stat *Stat_t) (err error)
  169. //sys Mkdir(path string, mode uint32) (err error)
  170. //sys Mkfifo(path string, mode uint32) (err error)
  171. //sys Mknod(path string, mode uint32, dev int) (err error)
  172. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  173. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  174. //sys Pathconf(path string, name int) (val int, err error)
  175. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  176. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  177. //sys read(fd int, p []byte) (n int, err error)
  178. //sys Readlink(path string, buf []byte) (n int, err error)
  179. //sys Rename(from string, to string) (err error)
  180. //sys Revoke(path string) (err error)
  181. //sys Rmdir(path string) (err error)
  182. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  183. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  184. //sysnb Setegid(egid int) (err error)
  185. //sysnb Seteuid(euid int) (err error)
  186. //sysnb Setgid(gid int) (err error)
  187. //sys Setlogin(name string) (err error)
  188. //sysnb Setpgid(pid int, pgid int) (err error)
  189. //sys Setpriority(which int, who int, prio int) (err error)
  190. //sysnb Setregid(rgid int, egid int) (err error)
  191. //sysnb Setreuid(ruid int, euid int) (err error)
  192. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  193. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  194. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  195. //sysnb Setsid() (pid int, err error)
  196. //sysnb Settimeofday(tp *Timeval) (err error)
  197. //sysnb Setuid(uid int) (err error)
  198. //sys Stat(path string, stat *Stat_t) (err error)
  199. //sys Statfs(path string, stat *Statfs_t) (err error)
  200. //sys Symlink(path string, link string) (err error)
  201. //sys Sync() (err error)
  202. //sys Truncate(path string, length int64) (err error)
  203. //sys Umask(newmask int) (oldmask int)
  204. //sys Unlink(path string) (err error)
  205. //sys Unmount(path string, flags int) (err error)
  206. //sys write(fd int, p []byte) (n int, err error)
  207. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  208. //sys munmap(addr uintptr, length uintptr) (err error)
  209. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  210. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  211. //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
  212. /*
  213. * Unimplemented
  214. */
  215. // __getcwd
  216. // __semctl
  217. // __syscall
  218. // __sysctl
  219. // adjfreq
  220. // break
  221. // clock_getres
  222. // clock_gettime
  223. // clock_settime
  224. // closefrom
  225. // execve
  226. // faccessat
  227. // fchmodat
  228. // fchownat
  229. // fcntl
  230. // fhopen
  231. // fhstat
  232. // fhstatfs
  233. // fork
  234. // fstatat
  235. // futimens
  236. // getfh
  237. // getgid
  238. // getitimer
  239. // getlogin
  240. // getresgid
  241. // getresuid
  242. // getrtable
  243. // getthrid
  244. // ktrace
  245. // lfs_bmapv
  246. // lfs_markv
  247. // lfs_segclean
  248. // lfs_segwait
  249. // linkat
  250. // mincore
  251. // minherit
  252. // mkdirat
  253. // mkfifoat
  254. // mknodat
  255. // mount
  256. // mquery
  257. // msgctl
  258. // msgget
  259. // msgrcv
  260. // msgsnd
  261. // nfssvc
  262. // nnpfspioctl
  263. // openat
  264. // preadv
  265. // profil
  266. // pwritev
  267. // quotactl
  268. // readlinkat
  269. // readv
  270. // reboot
  271. // renameat
  272. // rfork
  273. // sched_yield
  274. // semget
  275. // semop
  276. // setgroups
  277. // setitimer
  278. // setrtable
  279. // setsockopt
  280. // shmat
  281. // shmctl
  282. // shmdt
  283. // shmget
  284. // sigaction
  285. // sigaltstack
  286. // sigpending
  287. // sigprocmask
  288. // sigreturn
  289. // sigsuspend
  290. // symlinkat
  291. // sysarch
  292. // syscall
  293. // threxit
  294. // thrsigdivert
  295. // thrsleep
  296. // thrwakeup
  297. // unlinkat
  298. // vfork
  299. // writev