syscall_openbsd.go 11 KB

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