You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

732 lines
20 KiB

  1. // Copyright 2009 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. // Solaris 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_solaris.go or syscall_unix.go.
  11. package unix
  12. import (
  13. "syscall"
  14. "unsafe"
  15. )
  16. // Implemented in runtime/syscall_solaris.go.
  17. type syscallFunc uintptr
  18. func rawSysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
  19. func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
  20. type SockaddrDatalink struct {
  21. Family uint16
  22. Index uint16
  23. Type uint8
  24. Nlen uint8
  25. Alen uint8
  26. Slen uint8
  27. Data [244]int8
  28. raw RawSockaddrDatalink
  29. }
  30. func direntIno(buf []byte) (uint64, bool) {
  31. return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
  32. }
  33. func direntReclen(buf []byte) (uint64, bool) {
  34. return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
  35. }
  36. func direntNamlen(buf []byte) (uint64, bool) {
  37. reclen, ok := direntReclen(buf)
  38. if !ok {
  39. return 0, false
  40. }
  41. return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
  42. }
  43. //sysnb pipe(p *[2]_C_int) (n int, err error)
  44. func Pipe(p []int) (err error) {
  45. if len(p) != 2 {
  46. return EINVAL
  47. }
  48. var pp [2]_C_int
  49. n, err := pipe(&pp)
  50. if n != 0 {
  51. return err
  52. }
  53. p[0] = int(pp[0])
  54. p[1] = int(pp[1])
  55. return nil
  56. }
  57. func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
  58. if sa.Port < 0 || sa.Port > 0xFFFF {
  59. return nil, 0, EINVAL
  60. }
  61. sa.raw.Family = AF_INET
  62. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  63. p[0] = byte(sa.Port >> 8)
  64. p[1] = byte(sa.Port)
  65. for i := 0; i < len(sa.Addr); i++ {
  66. sa.raw.Addr[i] = sa.Addr[i]
  67. }
  68. return unsafe.Pointer(&sa.raw), SizeofSockaddrInet4, nil
  69. }
  70. func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, _Socklen, error) {
  71. if sa.Port < 0 || sa.Port > 0xFFFF {
  72. return nil, 0, EINVAL
  73. }
  74. sa.raw.Family = AF_INET6
  75. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  76. p[0] = byte(sa.Port >> 8)
  77. p[1] = byte(sa.Port)
  78. sa.raw.Scope_id = sa.ZoneId
  79. for i := 0; i < len(sa.Addr); i++ {
  80. sa.raw.Addr[i] = sa.Addr[i]
  81. }
  82. return unsafe.Pointer(&sa.raw), SizeofSockaddrInet6, nil
  83. }
  84. func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
  85. name := sa.Name
  86. n := len(name)
  87. if n >= len(sa.raw.Path) {
  88. return nil, 0, EINVAL
  89. }
  90. sa.raw.Family = AF_UNIX
  91. for i := 0; i < n; i++ {
  92. sa.raw.Path[i] = int8(name[i])
  93. }
  94. // length is family (uint16), name, NUL.
  95. sl := _Socklen(2)
  96. if n > 0 {
  97. sl += _Socklen(n) + 1
  98. }
  99. if sa.raw.Path[0] == '@' {
  100. sa.raw.Path[0] = 0
  101. // Don't count trailing NUL for abstract address.
  102. sl--
  103. }
  104. return unsafe.Pointer(&sa.raw), sl, nil
  105. }
  106. //sys getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) = libsocket.getsockname
  107. func Getsockname(fd int) (sa Sockaddr, err error) {
  108. var rsa RawSockaddrAny
  109. var len _Socklen = SizeofSockaddrAny
  110. if err = getsockname(fd, &rsa, &len); err != nil {
  111. return
  112. }
  113. return anyToSockaddr(&rsa)
  114. }
  115. // GetsockoptString returns the string value of the socket option opt for the
  116. // socket associated with fd at the given socket level.
  117. func GetsockoptString(fd, level, opt int) (string, error) {
  118. buf := make([]byte, 256)
  119. vallen := _Socklen(len(buf))
  120. err := getsockopt(fd, level, opt, unsafe.Pointer(&buf[0]), &vallen)
  121. if err != nil {
  122. return "", err
  123. }
  124. return string(buf[:vallen-1]), nil
  125. }
  126. const ImplementsGetwd = true
  127. //sys Getcwd(buf []byte) (n int, err error)
  128. func Getwd() (wd string, err error) {
  129. var buf [PathMax]byte
  130. // Getcwd will return an error if it failed for any reason.
  131. _, err = Getcwd(buf[0:])
  132. if err != nil {
  133. return "", err
  134. }
  135. n := clen(buf[:])
  136. if n < 1 {
  137. return "", EINVAL
  138. }
  139. return string(buf[:n]), nil
  140. }
  141. /*
  142. * Wrapped
  143. */
  144. //sysnb getgroups(ngid int, gid *_Gid_t) (n int, err error)
  145. //sysnb setgroups(ngid int, gid *_Gid_t) (err error)
  146. func Getgroups() (gids []int, err error) {
  147. n, err := getgroups(0, nil)
  148. // Check for error and sanity check group count. Newer versions of
  149. // Solaris allow up to 1024 (NGROUPS_MAX).
  150. if n < 0 || n > 1024 {
  151. if err != nil {
  152. return nil, err
  153. }
  154. return nil, EINVAL
  155. } else if n == 0 {
  156. return nil, nil
  157. }
  158. a := make([]_Gid_t, n)
  159. n, err = getgroups(n, &a[0])
  160. if n == -1 {
  161. return nil, err
  162. }
  163. gids = make([]int, n)
  164. for i, v := range a[0:n] {
  165. gids[i] = int(v)
  166. }
  167. return
  168. }
  169. func Setgroups(gids []int) (err error) {
  170. if len(gids) == 0 {
  171. return setgroups(0, nil)
  172. }
  173. a := make([]_Gid_t, len(gids))
  174. for i, v := range gids {
  175. a[i] = _Gid_t(v)
  176. }
  177. return setgroups(len(a), &a[0])
  178. }
  179. func ReadDirent(fd int, buf []byte) (n int, err error) {
  180. // Final argument is (basep *uintptr) and the syscall doesn't take nil.
  181. // TODO(rsc): Can we use a single global basep for all calls?
  182. return Getdents(fd, buf, new(uintptr))
  183. }
  184. // Wait status is 7 bits at bottom, either 0 (exited),
  185. // 0x7F (stopped), or a signal number that caused an exit.
  186. // The 0x80 bit is whether there was a core dump.
  187. // An extra number (exit code, signal causing a stop)
  188. // is in the high bits.
  189. type WaitStatus uint32
  190. const (
  191. mask = 0x7F
  192. core = 0x80
  193. shift = 8
  194. exited = 0
  195. stopped = 0x7F
  196. )
  197. func (w WaitStatus) Exited() bool { return w&mask == exited }
  198. func (w WaitStatus) ExitStatus() int {
  199. if w&mask != exited {
  200. return -1
  201. }
  202. return int(w >> shift)
  203. }
  204. func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != 0 }
  205. func (w WaitStatus) Signal() syscall.Signal {
  206. sig := syscall.Signal(w & mask)
  207. if sig == stopped || sig == 0 {
  208. return -1
  209. }
  210. return sig
  211. }
  212. func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 }
  213. func (w WaitStatus) Stopped() bool { return w&mask == stopped && syscall.Signal(w>>shift) != SIGSTOP }
  214. func (w WaitStatus) Continued() bool { return w&mask == stopped && syscall.Signal(w>>shift) == SIGSTOP }
  215. func (w WaitStatus) StopSignal() syscall.Signal {
  216. if !w.Stopped() {
  217. return -1
  218. }
  219. return syscall.Signal(w>>shift) & 0xFF
  220. }
  221. func (w WaitStatus) TrapCause() int { return -1 }
  222. //sys wait4(pid int32, statusp *_C_int, options int, rusage *Rusage) (wpid int32, err error)
  223. func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (int, error) {
  224. var status _C_int
  225. rpid, err := wait4(int32(pid), &status, options, rusage)
  226. wpid := int(rpid)
  227. if wpid == -1 {
  228. return wpid, err
  229. }
  230. if wstatus != nil {
  231. *wstatus = WaitStatus(status)
  232. }
  233. return wpid, nil
  234. }
  235. //sys gethostname(buf []byte) (n int, err error)
  236. func Gethostname() (name string, err error) {
  237. var buf [MaxHostNameLen]byte
  238. n, err := gethostname(buf[:])
  239. if n != 0 {
  240. return "", err
  241. }
  242. n = clen(buf[:])
  243. if n < 1 {
  244. return "", EFAULT
  245. }
  246. return string(buf[:n]), nil
  247. }
  248. //sys utimes(path string, times *[2]Timeval) (err error)
  249. func Utimes(path string, tv []Timeval) (err error) {
  250. if tv == nil {
  251. return utimes(path, nil)
  252. }
  253. if len(tv) != 2 {
  254. return EINVAL
  255. }
  256. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  257. }
  258. //sys utimensat(fd int, path string, times *[2]Timespec, flag int) (err error)
  259. func UtimesNano(path string, ts []Timespec) error {
  260. if ts == nil {
  261. return utimensat(AT_FDCWD, path, nil, 0)
  262. }
  263. if len(ts) != 2 {
  264. return EINVAL
  265. }
  266. return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  267. }
  268. func UtimesNanoAt(dirfd int, path string, ts []Timespec, flags int) error {
  269. if ts == nil {
  270. return utimensat(dirfd, path, nil, flags)
  271. }
  272. if len(ts) != 2 {
  273. return EINVAL
  274. }
  275. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), flags)
  276. }
  277. //sys fcntl(fd int, cmd int, arg int) (val int, err error)
  278. // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
  279. func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {
  280. _, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procfcntl)), 3, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(lk)), 0, 0, 0)
  281. if e1 != 0 {
  282. return e1
  283. }
  284. return nil
  285. }
  286. //sys futimesat(fildes int, path *byte, times *[2]Timeval) (err error)
  287. func Futimesat(dirfd int, path string, tv []Timeval) error {
  288. pathp, err := BytePtrFromString(path)
  289. if err != nil {
  290. return err
  291. }
  292. if tv == nil {
  293. return futimesat(dirfd, pathp, nil)
  294. }
  295. if len(tv) != 2 {
  296. return EINVAL
  297. }
  298. return futimesat(dirfd, pathp, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  299. }
  300. // Solaris doesn't have an futimes function because it allows NULL to be
  301. // specified as the path for futimesat. However, Go doesn't like
  302. // NULL-style string interfaces, so this simple wrapper is provided.
  303. func Futimes(fd int, tv []Timeval) error {
  304. if tv == nil {
  305. return futimesat(fd, nil, nil)
  306. }
  307. if len(tv) != 2 {
  308. return EINVAL
  309. }
  310. return futimesat(fd, nil, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  311. }
  312. func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
  313. switch rsa.Addr.Family {
  314. case AF_UNIX:
  315. pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
  316. sa := new(SockaddrUnix)
  317. // Assume path ends at NUL.
  318. // This is not technically the Solaris semantics for
  319. // abstract Unix domain sockets -- they are supposed
  320. // to be uninterpreted fixed-size binary blobs -- but
  321. // everyone uses this convention.
  322. n := 0
  323. for n < len(pp.Path) && pp.Path[n] != 0 {
  324. n++
  325. }
  326. bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
  327. sa.Name = string(bytes)
  328. return sa, nil
  329. case AF_INET:
  330. pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
  331. sa := new(SockaddrInet4)
  332. p := (*[2]byte)(unsafe.Pointer(&pp.Port))
  333. sa.Port = int(p[0])<<8 + int(p[1])
  334. for i := 0; i < len(sa.Addr); i++ {
  335. sa.Addr[i] = pp.Addr[i]
  336. }
  337. return sa, nil
  338. case AF_INET6:
  339. pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa))
  340. sa := new(SockaddrInet6)
  341. p := (*[2]byte)(unsafe.Pointer(&pp.Port))
  342. sa.Port = int(p[0])<<8 + int(p[1])
  343. sa.ZoneId = pp.Scope_id
  344. for i := 0; i < len(sa.Addr); i++ {
  345. sa.Addr[i] = pp.Addr[i]
  346. }
  347. return sa, nil
  348. }
  349. return nil, EAFNOSUPPORT
  350. }
  351. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) = libsocket.accept
  352. func Accept(fd int) (nfd int, sa Sockaddr, err error) {
  353. var rsa RawSockaddrAny
  354. var len _Socklen = SizeofSockaddrAny
  355. nfd, err = accept(fd, &rsa, &len)
  356. if nfd == -1 {
  357. return
  358. }
  359. sa, err = anyToSockaddr(&rsa)
  360. if err != nil {
  361. Close(nfd)
  362. nfd = 0
  363. }
  364. return
  365. }
  366. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) = libsocket.__xnet_recvmsg
  367. func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) {
  368. var msg Msghdr
  369. var rsa RawSockaddrAny
  370. msg.Name = (*byte)(unsafe.Pointer(&rsa))
  371. msg.Namelen = uint32(SizeofSockaddrAny)
  372. var iov Iovec
  373. if len(p) > 0 {
  374. iov.Base = (*int8)(unsafe.Pointer(&p[0]))
  375. iov.SetLen(len(p))
  376. }
  377. var dummy int8
  378. if len(oob) > 0 {
  379. // receive at least one normal byte
  380. if len(p) == 0 {
  381. iov.Base = &dummy
  382. iov.SetLen(1)
  383. }
  384. msg.Accrightslen = int32(len(oob))
  385. }
  386. msg.Iov = &iov
  387. msg.Iovlen = 1
  388. if n, err = recvmsg(fd, &msg, flags); n == -1 {
  389. return
  390. }
  391. oobn = int(msg.Accrightslen)
  392. // source address is only specified if the socket is unconnected
  393. if rsa.Addr.Family != AF_UNSPEC {
  394. from, err = anyToSockaddr(&rsa)
  395. }
  396. return
  397. }
  398. func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) {
  399. _, err = SendmsgN(fd, p, oob, to, flags)
  400. return
  401. }
  402. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) = libsocket.__xnet_sendmsg
  403. func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) {
  404. var ptr unsafe.Pointer
  405. var salen _Socklen
  406. if to != nil {
  407. ptr, salen, err = to.sockaddr()
  408. if err != nil {
  409. return 0, err
  410. }
  411. }
  412. var msg Msghdr
  413. msg.Name = (*byte)(unsafe.Pointer(ptr))
  414. msg.Namelen = uint32(salen)
  415. var iov Iovec
  416. if len(p) > 0 {
  417. iov.Base = (*int8)(unsafe.Pointer(&p[0]))
  418. iov.SetLen(len(p))
  419. }
  420. var dummy int8
  421. if len(oob) > 0 {
  422. // send at least one normal byte
  423. if len(p) == 0 {
  424. iov.Base = &dummy
  425. iov.SetLen(1)
  426. }
  427. msg.Accrightslen = int32(len(oob))
  428. }
  429. msg.Iov = &iov
  430. msg.Iovlen = 1
  431. if n, err = sendmsg(fd, &msg, flags); err != nil {
  432. return 0, err
  433. }
  434. if len(oob) > 0 && len(p) == 0 {
  435. n = 0
  436. }
  437. return n, nil
  438. }
  439. //sys acct(path *byte) (err error)
  440. func Acct(path string) (err error) {
  441. if len(path) == 0 {
  442. // Assume caller wants to disable accounting.
  443. return acct(nil)
  444. }
  445. pathp, err := BytePtrFromString(path)
  446. if err != nil {
  447. return err
  448. }
  449. return acct(pathp)
  450. }
  451. //sys __makedev(version int, major uint, minor uint) (val uint64)
  452. func Mkdev(major, minor uint32) uint64 {
  453. return __makedev(NEWDEV, uint(major), uint(minor))
  454. }
  455. //sys __major(version int, dev uint64) (val uint)
  456. func Major(dev uint64) uint32 {
  457. return uint32(__major(NEWDEV, dev))
  458. }
  459. //sys __minor(version int, dev uint64) (val uint)
  460. func Minor(dev uint64) uint32 {
  461. return uint32(__minor(NEWDEV, dev))
  462. }
  463. /*
  464. * Expose the ioctl function
  465. */
  466. //sys ioctl(fd int, req uint, arg uintptr) (err error)
  467. func IoctlSetInt(fd int, req uint, value int) (err error) {
  468. return ioctl(fd, req, uintptr(value))
  469. }
  470. func IoctlSetWinsize(fd int, req uint, value *Winsize) (err error) {
  471. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  472. }
  473. func IoctlSetTermios(fd int, req uint, value *Termios) (err error) {
  474. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  475. }
  476. func IoctlSetTermio(fd int, req uint, value *Termio) (err error) {
  477. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  478. }
  479. func IoctlGetInt(fd int, req uint) (int, error) {
  480. var value int
  481. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  482. return value, err
  483. }
  484. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  485. var value Winsize
  486. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  487. return &value, err
  488. }
  489. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  490. var value Termios
  491. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  492. return &value, err
  493. }
  494. func IoctlGetTermio(fd int, req uint) (*Termio, error) {
  495. var value Termio
  496. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  497. return &value, err
  498. }
  499. //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error)
  500. func Poll(fds []PollFd, timeout int) (n int, err error) {
  501. if len(fds) == 0 {
  502. return poll(nil, 0, timeout)
  503. }
  504. return poll(&fds[0], len(fds), timeout)
  505. }
  506. /*
  507. * Exposed directly
  508. */
  509. //sys Access(path string, mode uint32) (err error)
  510. //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
  511. //sys Chdir(path string) (err error)
  512. //sys Chmod(path string, mode uint32) (err error)
  513. //sys Chown(path string, uid int, gid int) (err error)
  514. //sys Chroot(path string) (err error)
  515. //sys Close(fd int) (err error)
  516. //sys Creat(path string, mode uint32) (fd int, err error)
  517. //sys Dup(fd int) (nfd int, err error)
  518. //sys Dup2(oldfd int, newfd int) (err error)
  519. //sys Exit(code int)
  520. //sys Fchdir(fd int) (err error)
  521. //sys Fchmod(fd int, mode uint32) (err error)
  522. //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
  523. //sys Fchown(fd int, uid int, gid int) (err error)
  524. //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
  525. //sys Fdatasync(fd int) (err error)
  526. //sys Flock(fd int, how int) (err error)
  527. //sys Fpathconf(fd int, name int) (val int, err error)
  528. //sys Fstat(fd int, stat *Stat_t) (err error)
  529. //sys Fstatvfs(fd int, vfsstat *Statvfs_t) (err error)
  530. //sys Getdents(fd int, buf []byte, basep *uintptr) (n int, err error)
  531. //sysnb Getgid() (gid int)
  532. //sysnb Getpid() (pid int)
  533. //sysnb Getpgid(pid int) (pgid int, err error)
  534. //sysnb Getpgrp() (pgid int, err error)
  535. //sys Geteuid() (euid int)
  536. //sys Getegid() (egid int)
  537. //sys Getppid() (ppid int)
  538. //sys Getpriority(which int, who int) (n int, err error)
  539. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  540. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  541. //sysnb Gettimeofday(tv *Timeval) (err error)
  542. //sysnb Getuid() (uid int)
  543. //sys Kill(pid int, signum syscall.Signal) (err error)
  544. //sys Lchown(path string, uid int, gid int) (err error)
  545. //sys Link(path string, link string) (err error)
  546. //sys Listen(s int, backlog int) (err error) = libsocket.__xnet_llisten
  547. //sys Lstat(path string, stat *Stat_t) (err error)
  548. //sys Madvise(b []byte, advice int) (err error)
  549. //sys Mkdir(path string, mode uint32) (err error)
  550. //sys Mkdirat(dirfd int, path string, mode uint32) (err error)
  551. //sys Mkfifo(path string, mode uint32) (err error)
  552. //sys Mkfifoat(dirfd int, path string, mode uint32) (err error)
  553. //sys Mknod(path string, mode uint32, dev int) (err error)
  554. //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
  555. //sys Mlock(b []byte) (err error)
  556. //sys Mlockall(flags int) (err error)
  557. //sys Mprotect(b []byte, prot int) (err error)
  558. //sys Msync(b []byte, flags int) (err error)
  559. //sys Munlock(b []byte) (err error)
  560. //sys Munlockall() (err error)
  561. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  562. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  563. //sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
  564. //sys Pathconf(path string, name int) (val int, err error)
  565. //sys Pause() (err error)
  566. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  567. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  568. //sys read(fd int, p []byte) (n int, err error)
  569. //sys Readlink(path string, buf []byte) (n int, err error)
  570. //sys Rename(from string, to string) (err error)
  571. //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
  572. //sys Rmdir(path string) (err error)
  573. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = lseek
  574. //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
  575. //sysnb Setegid(egid int) (err error)
  576. //sysnb Seteuid(euid int) (err error)
  577. //sysnb Setgid(gid int) (err error)
  578. //sys Sethostname(p []byte) (err error)
  579. //sysnb Setpgid(pid int, pgid int) (err error)
  580. //sys Setpriority(which int, who int, prio int) (err error)
  581. //sysnb Setregid(rgid int, egid int) (err error)
  582. //sysnb Setreuid(ruid int, euid int) (err error)
  583. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  584. //sysnb Setsid() (pid int, err error)
  585. //sysnb Setuid(uid int) (err error)
  586. //sys Shutdown(s int, how int) (err error) = libsocket.shutdown
  587. //sys Stat(path string, stat *Stat_t) (err error)
  588. //sys Statvfs(path string, vfsstat *Statvfs_t) (err error)
  589. //sys Symlink(path string, link string) (err error)
  590. //sys Sync() (err error)
  591. //sysnb Times(tms *Tms) (ticks uintptr, err error)
  592. //sys Truncate(path string, length int64) (err error)
  593. //sys Fsync(fd int) (err error)
  594. //sys Ftruncate(fd int, length int64) (err error)
  595. //sys Umask(mask int) (oldmask int)
  596. //sysnb Uname(buf *Utsname) (err error)
  597. //sys Unmount(target string, flags int) (err error) = libc.umount
  598. //sys Unlink(path string) (err error)
  599. //sys Unlinkat(dirfd int, path string, flags int) (err error)
  600. //sys Ustat(dev int, ubuf *Ustat_t) (err error)
  601. //sys Utime(path string, buf *Utimbuf) (err error)
  602. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) = libsocket.__xnet_bind
  603. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) = libsocket.__xnet_connect
  604. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  605. //sys munmap(addr uintptr, length uintptr) (err error)
  606. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) = libsocket.__xnet_sendto
  607. //sys socket(domain int, typ int, proto int) (fd int, err error) = libsocket.__xnet_socket
  608. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) = libsocket.__xnet_socketpair
  609. //sys write(fd int, p []byte) (n int, err error)
  610. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) = libsocket.__xnet_getsockopt
  611. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) = libsocket.getpeername
  612. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) = libsocket.setsockopt
  613. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) = libsocket.recvfrom
  614. func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
  615. r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procread)), 3, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf), 0, 0, 0)
  616. n = int(r0)
  617. if e1 != 0 {
  618. err = e1
  619. }
  620. return
  621. }
  622. func writelen(fd int, buf *byte, nbuf int) (n int, err error) {
  623. r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procwrite)), 3, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf), 0, 0, 0)
  624. n = int(r0)
  625. if e1 != 0 {
  626. err = e1
  627. }
  628. return
  629. }
  630. var mapper = &mmapper{
  631. active: make(map[*byte][]byte),
  632. mmap: mmap,
  633. munmap: munmap,
  634. }
  635. func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
  636. return mapper.Mmap(fd, offset, length, prot, flags)
  637. }
  638. func Munmap(b []byte) (err error) {
  639. return mapper.Munmap(b)
  640. }