syscall_solaris.go 21 KB

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