syscall_openbsd.go 9.9 KB

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