syscall_openbsd.go 11 KB

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