syscall_openbsd.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. "sort"
  14. "syscall"
  15. "unsafe"
  16. )
  17. // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
  18. type SockaddrDatalink struct {
  19. Len uint8
  20. Family uint8
  21. Index uint16
  22. Type uint8
  23. Nlen uint8
  24. Alen uint8
  25. Slen uint8
  26. Data [24]int8
  27. raw RawSockaddrDatalink
  28. }
  29. func anyToSockaddrGOOS(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
  30. return nil, EAFNOSUPPORT
  31. }
  32. func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
  33. func nametomib(name string) (mib []_C_int, err error) {
  34. i := sort.Search(len(sysctlMib), func(i int) bool {
  35. return sysctlMib[i].ctlname >= name
  36. })
  37. if i < len(sysctlMib) && sysctlMib[i].ctlname == name {
  38. return sysctlMib[i].ctloid, nil
  39. }
  40. return nil, EINVAL
  41. }
  42. func direntIno(buf []byte) (uint64, bool) {
  43. return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
  44. }
  45. func direntReclen(buf []byte) (uint64, bool) {
  46. return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
  47. }
  48. func direntNamlen(buf []byte) (uint64, bool) {
  49. return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
  50. }
  51. func SysctlUvmexp(name string) (*Uvmexp, error) {
  52. mib, err := sysctlmib(name)
  53. if err != nil {
  54. return nil, err
  55. }
  56. n := uintptr(SizeofUvmexp)
  57. var u Uvmexp
  58. if err := sysctl(mib, (*byte)(unsafe.Pointer(&u)), &n, nil, 0); err != nil {
  59. return nil, err
  60. }
  61. if n != SizeofUvmexp {
  62. return nil, EIO
  63. }
  64. return &u, nil
  65. }
  66. func Pipe(p []int) (err error) {
  67. return Pipe2(p, 0)
  68. }
  69. //sysnb pipe2(p *[2]_C_int, flags int) (err error)
  70. func Pipe2(p []int, flags int) error {
  71. if len(p) != 2 {
  72. return EINVAL
  73. }
  74. var pp [2]_C_int
  75. err := pipe2(&pp, flags)
  76. if err == nil {
  77. p[0] = int(pp[0])
  78. p[1] = int(pp[1])
  79. }
  80. return err
  81. }
  82. //sys Getdents(fd int, buf []byte) (n int, err error)
  83. func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
  84. n, err = Getdents(fd, buf)
  85. if err != nil || basep == nil {
  86. return
  87. }
  88. var off int64
  89. off, err = Seek(fd, 0, 1 /* SEEK_CUR */)
  90. if err != nil {
  91. *basep = ^uintptr(0)
  92. return
  93. }
  94. *basep = uintptr(off)
  95. if unsafe.Sizeof(*basep) == 8 {
  96. return
  97. }
  98. if off>>32 != 0 {
  99. // We can't stuff the offset back into a uintptr, so any
  100. // future calls would be suspect. Generate an error.
  101. // EIO was allowed by getdirentries.
  102. err = EIO
  103. }
  104. return
  105. }
  106. //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD
  107. func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  108. if raceenabled {
  109. raceReleaseMerge(unsafe.Pointer(&ioSync))
  110. }
  111. return sendfile(outfd, infd, offset, count)
  112. }
  113. // TODO
  114. func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  115. return -1, ENOSYS
  116. }
  117. func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
  118. var _p0 unsafe.Pointer
  119. var bufsize uintptr
  120. if len(buf) > 0 {
  121. _p0 = unsafe.Pointer(&buf[0])
  122. bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
  123. }
  124. r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
  125. n = int(r0)
  126. if e1 != 0 {
  127. err = e1
  128. }
  129. return
  130. }
  131. func setattrlistTimes(path string, times []Timespec, flags int) error {
  132. // used on Darwin for UtimesNano
  133. return ENOSYS
  134. }
  135. //sys ioctl(fd int, req uint, arg uintptr) (err error)
  136. //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
  137. //sys ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error)
  138. func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) {
  139. if len(fds) == 0 {
  140. return ppoll(nil, 0, timeout, sigmask)
  141. }
  142. return ppoll(&fds[0], len(fds), timeout, sigmask)
  143. }
  144. func Uname(uname *Utsname) error {
  145. mib := []_C_int{CTL_KERN, KERN_OSTYPE}
  146. n := unsafe.Sizeof(uname.Sysname)
  147. if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil {
  148. return err
  149. }
  150. mib = []_C_int{CTL_KERN, KERN_HOSTNAME}
  151. n = unsafe.Sizeof(uname.Nodename)
  152. if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil {
  153. return err
  154. }
  155. mib = []_C_int{CTL_KERN, KERN_OSRELEASE}
  156. n = unsafe.Sizeof(uname.Release)
  157. if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil {
  158. return err
  159. }
  160. mib = []_C_int{CTL_KERN, KERN_VERSION}
  161. n = unsafe.Sizeof(uname.Version)
  162. if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil {
  163. return err
  164. }
  165. // The version might have newlines or tabs in it, convert them to
  166. // spaces.
  167. for i, b := range uname.Version {
  168. if b == '\n' || b == '\t' {
  169. if i == len(uname.Version)-1 {
  170. uname.Version[i] = 0
  171. } else {
  172. uname.Version[i] = ' '
  173. }
  174. }
  175. }
  176. mib = []_C_int{CTL_HW, HW_MACHINE}
  177. n = unsafe.Sizeof(uname.Machine)
  178. if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil {
  179. return err
  180. }
  181. return nil
  182. }
  183. /*
  184. * Exposed directly
  185. */
  186. //sys Access(path string, mode uint32) (err error)
  187. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  188. //sys Chdir(path string) (err error)
  189. //sys Chflags(path string, flags int) (err error)
  190. //sys Chmod(path string, mode uint32) (err error)
  191. //sys Chown(path string, uid int, gid int) (err error)
  192. //sys Chroot(path string) (err error)
  193. //sys Close(fd int) (err error)
  194. //sys Dup(fd int) (nfd int, err error)
  195. //sys Dup2(from int, to int) (err error)
  196. //sys Dup3(from int, to int, flags int) (err error)
  197. //sys Exit(code int)
  198. //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
  199. //sys Fchdir(fd int) (err error)
  200. //sys Fchflags(fd int, flags int) (err error)
  201. //sys Fchmod(fd int, mode uint32) (err error)
  202. //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
  203. //sys Fchown(fd int, uid int, gid int) (err error)
  204. //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
  205. //sys Flock(fd int, how int) (err error)
  206. //sys Fpathconf(fd int, name int) (val int, err error)
  207. //sys Fstat(fd int, stat *Stat_t) (err error)
  208. //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
  209. //sys Fstatfs(fd int, stat *Statfs_t) (err error)
  210. //sys Fsync(fd int) (err error)
  211. //sys Ftruncate(fd int, length int64) (err error)
  212. //sysnb Getegid() (egid int)
  213. //sysnb Geteuid() (uid int)
  214. //sysnb Getgid() (gid int)
  215. //sysnb Getpgid(pid int) (pgid int, err error)
  216. //sysnb Getpgrp() (pgrp int)
  217. //sysnb Getpid() (pid int)
  218. //sysnb Getppid() (ppid int)
  219. //sys Getpriority(which int, who int) (prio int, err error)
  220. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  221. //sysnb Getrtable() (rtable int, err error)
  222. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  223. //sysnb Getsid(pid int) (sid int, err error)
  224. //sysnb Gettimeofday(tv *Timeval) (err error)
  225. //sysnb Getuid() (uid int)
  226. //sys Issetugid() (tainted bool)
  227. //sys Kill(pid int, signum syscall.Signal) (err error)
  228. //sys Kqueue() (fd int, err error)
  229. //sys Lchown(path string, uid int, gid int) (err error)
  230. //sys Link(path string, link string) (err error)
  231. //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error)
  232. //sys Listen(s int, backlog int) (err error)
  233. //sys Lstat(path string, stat *Stat_t) (err error)
  234. //sys Mkdir(path string, mode uint32) (err error)
  235. //sys Mkdirat(dirfd int, path string, mode uint32) (err error)
  236. //sys Mkfifo(path string, mode uint32) (err error)
  237. //sys Mkfifoat(dirfd int, path string, mode uint32) (err error)
  238. //sys Mknod(path string, mode uint32, dev int) (err error)
  239. //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
  240. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  241. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  242. //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error)
  243. //sys Pathconf(path string, name int) (val int, err error)
  244. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  245. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  246. //sys read(fd int, p []byte) (n int, err error)
  247. //sys Readlink(path string, buf []byte) (n int, err error)
  248. //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error)
  249. //sys Rename(from string, to string) (err error)
  250. //sys Renameat(fromfd int, from string, tofd int, to string) (err error)
  251. //sys Revoke(path string) (err error)
  252. //sys Rmdir(path string) (err error)
  253. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
  254. //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
  255. //sysnb Setegid(egid int) (err error)
  256. //sysnb Seteuid(euid int) (err error)
  257. //sysnb Setgid(gid int) (err error)
  258. //sys Setlogin(name string) (err error)
  259. //sysnb Setpgid(pid int, pgid int) (err error)
  260. //sys Setpriority(which int, who int, prio int) (err error)
  261. //sysnb Setregid(rgid int, egid int) (err error)
  262. //sysnb Setreuid(ruid int, euid int) (err error)
  263. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  264. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  265. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  266. //sysnb Setrtable(rtable int) (err error)
  267. //sysnb Setsid() (pid int, err error)
  268. //sysnb Settimeofday(tp *Timeval) (err error)
  269. //sysnb Setuid(uid int) (err error)
  270. //sys Stat(path string, stat *Stat_t) (err error)
  271. //sys Statfs(path string, stat *Statfs_t) (err error)
  272. //sys Symlink(path string, link string) (err error)
  273. //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
  274. //sys Sync() (err error)
  275. //sys Truncate(path string, length int64) (err error)
  276. //sys Umask(newmask int) (oldmask int)
  277. //sys Unlink(path string) (err error)
  278. //sys Unlinkat(dirfd int, path string, flags int) (err error)
  279. //sys Unmount(path string, flags int) (err error)
  280. //sys write(fd int, p []byte) (n int, err error)
  281. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  282. //sys munmap(addr uintptr, length uintptr) (err error)
  283. //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
  284. //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
  285. //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
  286. /*
  287. * Unimplemented
  288. */
  289. // __getcwd
  290. // __semctl
  291. // __syscall
  292. // __sysctl
  293. // adjfreq
  294. // break
  295. // clock_getres
  296. // clock_gettime
  297. // clock_settime
  298. // closefrom
  299. // execve
  300. // fhopen
  301. // fhstat
  302. // fhstatfs
  303. // fork
  304. // futimens
  305. // getfh
  306. // getgid
  307. // getitimer
  308. // getlogin
  309. // getresgid
  310. // getresuid
  311. // getthrid
  312. // ktrace
  313. // lfs_bmapv
  314. // lfs_markv
  315. // lfs_segclean
  316. // lfs_segwait
  317. // mincore
  318. // minherit
  319. // mount
  320. // mquery
  321. // msgctl
  322. // msgget
  323. // msgrcv
  324. // msgsnd
  325. // nfssvc
  326. // nnpfspioctl
  327. // preadv
  328. // profil
  329. // pwritev
  330. // quotactl
  331. // readv
  332. // reboot
  333. // renameat
  334. // rfork
  335. // sched_yield
  336. // semget
  337. // semop
  338. // setgroups
  339. // setitimer
  340. // setsockopt
  341. // shmat
  342. // shmctl
  343. // shmdt
  344. // shmget
  345. // sigaction
  346. // sigaltstack
  347. // sigpending
  348. // sigprocmask
  349. // sigreturn
  350. // sigsuspend
  351. // sysarch
  352. // syscall
  353. // threxit
  354. // thrsigdivert
  355. // thrsleep
  356. // thrwakeup
  357. // vfork
  358. // writev