syscall_solaris.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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 clen(n []byte) int {
  31. for i := 0; i < len(n); i++ {
  32. if n[i] == 0 {
  33. return i
  34. }
  35. }
  36. return len(n)
  37. }
  38. func direntIno(buf []byte) (uint64, bool) {
  39. return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
  40. }
  41. func direntReclen(buf []byte) (uint64, bool) {
  42. return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
  43. }
  44. func direntNamlen(buf []byte) (uint64, bool) {
  45. reclen, ok := direntReclen(buf)
  46. if !ok {
  47. return 0, false
  48. }
  49. return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
  50. }
  51. //sysnb pipe(p *[2]_C_int) (n int, err error)
  52. func Pipe(p []int) (err error) {
  53. if len(p) != 2 {
  54. return EINVAL
  55. }
  56. var pp [2]_C_int
  57. n, err := pipe(&pp)
  58. if n != 0 {
  59. return err
  60. }
  61. p[0] = int(pp[0])
  62. p[1] = int(pp[1])
  63. return nil
  64. }
  65. func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
  66. if sa.Port < 0 || sa.Port > 0xFFFF {
  67. return nil, 0, EINVAL
  68. }
  69. sa.raw.Family = AF_INET
  70. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  71. p[0] = byte(sa.Port >> 8)
  72. p[1] = byte(sa.Port)
  73. for i := 0; i < len(sa.Addr); i++ {
  74. sa.raw.Addr[i] = sa.Addr[i]
  75. }
  76. return unsafe.Pointer(&sa.raw), SizeofSockaddrInet4, nil
  77. }
  78. func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, _Socklen, error) {
  79. if sa.Port < 0 || sa.Port > 0xFFFF {
  80. return nil, 0, EINVAL
  81. }
  82. sa.raw.Family = AF_INET6
  83. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  84. p[0] = byte(sa.Port >> 8)
  85. p[1] = byte(sa.Port)
  86. sa.raw.Scope_id = sa.ZoneId
  87. for i := 0; i < len(sa.Addr); i++ {
  88. sa.raw.Addr[i] = sa.Addr[i]
  89. }
  90. return unsafe.Pointer(&sa.raw), SizeofSockaddrInet6, nil
  91. }
  92. func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
  93. name := sa.Name
  94. n := len(name)
  95. if n >= len(sa.raw.Path) {
  96. return nil, 0, EINVAL
  97. }
  98. sa.raw.Family = AF_UNIX
  99. for i := 0; i < n; i++ {
  100. sa.raw.Path[i] = int8(name[i])
  101. }
  102. // length is family (uint16), name, NUL.
  103. sl := _Socklen(2)
  104. if n > 0 {
  105. sl += _Socklen(n) + 1
  106. }
  107. if sa.raw.Path[0] == '@' {
  108. sa.raw.Path[0] = 0
  109. // Don't count trailing NUL for abstract address.
  110. sl--
  111. }
  112. return unsafe.Pointer(&sa.raw), sl, nil
  113. }
  114. //sys getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) = libsocket.getsockname
  115. func Getsockname(fd int) (sa Sockaddr, err error) {
  116. var rsa RawSockaddrAny
  117. var len _Socklen = SizeofSockaddrAny
  118. if err = getsockname(fd, &rsa, &len); err != nil {
  119. return
  120. }
  121. return anyToSockaddr(&rsa)
  122. }
  123. const ImplementsGetwd = true
  124. //sys Getcwd(buf []byte) (n int, err error)
  125. func Getwd() (wd string, err error) {
  126. var buf [PathMax]byte
  127. // Getcwd will return an error if it failed for any reason.
  128. _, err = Getcwd(buf[0:])
  129. if err != nil {
  130. return "", err
  131. }
  132. n := clen(buf[:])
  133. if n < 1 {
  134. return "", EINVAL
  135. }
  136. return string(buf[:n]), nil
  137. }
  138. /*
  139. * Wrapped
  140. */
  141. //sysnb getgroups(ngid int, gid *_Gid_t) (n int, err error)
  142. //sysnb setgroups(ngid int, gid *_Gid_t) (err error)
  143. func Getgroups() (gids []int, err error) {
  144. n, err := getgroups(0, nil)
  145. // Check for error and sanity check group count. Newer versions of
  146. // Solaris allow up to 1024 (NGROUPS_MAX).
  147. if n < 0 || n > 1024 {
  148. if err != nil {
  149. return nil, err
  150. }
  151. return nil, EINVAL
  152. } else if n == 0 {
  153. return nil, nil
  154. }
  155. a := make([]_Gid_t, n)
  156. n, err = getgroups(n, &a[0])
  157. if n == -1 {
  158. return nil, err
  159. }
  160. gids = make([]int, n)
  161. for i, v := range a[0:n] {
  162. gids[i] = int(v)
  163. }
  164. return
  165. }
  166. func Setgroups(gids []int) (err error) {
  167. if len(gids) == 0 {
  168. return setgroups(0, nil)
  169. }
  170. a := make([]_Gid_t, len(gids))
  171. for i, v := range gids {
  172. a[i] = _Gid_t(v)
  173. }
  174. return setgroups(len(a), &a[0])
  175. }
  176. func ReadDirent(fd int, buf []byte) (n int, err error) {
  177. // Final argument is (basep *uintptr) and the syscall doesn't take nil.
  178. // TODO(rsc): Can we use a single global basep for all calls?
  179. return Getdents(fd, buf, new(uintptr))
  180. }
  181. // Wait status is 7 bits at bottom, either 0 (exited),
  182. // 0x7F (stopped), or a signal number that caused an exit.
  183. // The 0x80 bit is whether there was a core dump.
  184. // An extra number (exit code, signal causing a stop)
  185. // is in the high bits.
  186. type WaitStatus uint32
  187. const (
  188. mask = 0x7F
  189. core = 0x80
  190. shift = 8
  191. exited = 0
  192. stopped = 0x7F
  193. )
  194. func (w WaitStatus) Exited() bool { return w&mask == exited }
  195. func (w WaitStatus) ExitStatus() int {
  196. if w&mask != exited {
  197. return -1
  198. }
  199. return int(w >> shift)
  200. }
  201. func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != 0 }
  202. func (w WaitStatus) Signal() syscall.Signal {
  203. sig := syscall.Signal(w & mask)
  204. if sig == stopped || sig == 0 {
  205. return -1
  206. }
  207. return sig
  208. }
  209. func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 }
  210. func (w WaitStatus) Stopped() bool { return w&mask == stopped && syscall.Signal(w>>shift) != SIGSTOP }
  211. func (w WaitStatus) Continued() bool { return w&mask == stopped && syscall.Signal(w>>shift) == SIGSTOP }
  212. func (w WaitStatus) StopSignal() syscall.Signal {
  213. if !w.Stopped() {
  214. return -1
  215. }
  216. return syscall.Signal(w>>shift) & 0xFF
  217. }
  218. func (w WaitStatus) TrapCause() int { return -1 }
  219. //sys wait4(pid int32, statusp *_C_int, options int, rusage *Rusage) (wpid int32, err error)
  220. func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (int, error) {
  221. var status _C_int
  222. rpid, err := wait4(int32(pid), &status, options, rusage)
  223. wpid := int(rpid)
  224. if wpid == -1 {
  225. return wpid, err
  226. }
  227. if wstatus != nil {
  228. *wstatus = WaitStatus(status)
  229. }
  230. return wpid, nil
  231. }
  232. //sys gethostname(buf []byte) (n int, err error)
  233. func Gethostname() (name string, err error) {
  234. var buf [MaxHostNameLen]byte
  235. n, err := gethostname(buf[:])
  236. if n != 0 {
  237. return "", err
  238. }
  239. n = clen(buf[:])
  240. if n < 1 {
  241. return "", EFAULT
  242. }
  243. return string(buf[:n]), nil
  244. }
  245. //sys utimes(path string, times *[2]Timeval) (err error)
  246. func Utimes(path string, tv []Timeval) (err error) {
  247. if tv == nil {
  248. return utimes(path, nil)
  249. }
  250. if len(tv) != 2 {
  251. return EINVAL
  252. }
  253. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  254. }
  255. //sys utimensat(fd int, path string, times *[2]Timespec, flag int) (err error)
  256. func UtimesNano(path string, ts []Timespec) error {
  257. if ts == nil {
  258. return utimensat(AT_FDCWD, path, nil, 0)
  259. }
  260. if len(ts) != 2 {
  261. return EINVAL
  262. }
  263. return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  264. }
  265. func UtimesNanoAt(dirfd int, path string, ts []Timespec, flags int) error {
  266. if ts == nil {
  267. return utimensat(dirfd, path, nil, flags)
  268. }
  269. if len(ts) != 2 {
  270. return EINVAL
  271. }
  272. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), flags)
  273. }
  274. //sys fcntl(fd int, cmd int, arg int) (val int, err error)
  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 Fchdir(fd int) (err error)
  518. //sys Fchmod(fd int, mode uint32) (err error)
  519. //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
  520. //sys Fchown(fd int, uid int, gid int) (err error)
  521. //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
  522. //sys Fdatasync(fd int) (err error)
  523. //sys Flock(fd int, how int) (err error)
  524. //sys Fpathconf(fd int, name int) (val int, err error)
  525. //sys Fstat(fd int, stat *Stat_t) (err error)
  526. //sys Fstatvfs(fd int, vfsstat *Statvfs_t) (err error)
  527. //sys Getdents(fd int, buf []byte, basep *uintptr) (n int, err error)
  528. //sysnb Getgid() (gid int)
  529. //sysnb Getpid() (pid int)
  530. //sysnb Getpgid(pid int) (pgid int, err error)
  531. //sysnb Getpgrp() (pgid int, err error)
  532. //sys Geteuid() (euid int)
  533. //sys Getegid() (egid int)
  534. //sys Getppid() (ppid int)
  535. //sys Getpriority(which int, who int) (n int, err error)
  536. //sysnb Getrlimit(which int, lim *Rlimit) (err error)
  537. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  538. //sysnb Gettimeofday(tv *Timeval) (err error)
  539. //sysnb Getuid() (uid int)
  540. //sys Kill(pid int, signum syscall.Signal) (err error)
  541. //sys Lchown(path string, uid int, gid int) (err error)
  542. //sys Link(path string, link string) (err error)
  543. //sys Listen(s int, backlog int) (err error) = libsocket.__xnet_llisten
  544. //sys Lstat(path string, stat *Stat_t) (err error)
  545. //sys Madvise(b []byte, advice int) (err error)
  546. //sys Mkdir(path string, mode uint32) (err error)
  547. //sys Mkdirat(dirfd int, path string, mode uint32) (err error)
  548. //sys Mkfifo(path string, mode uint32) (err error)
  549. //sys Mkfifoat(dirfd int, path string, mode uint32) (err error)
  550. //sys Mknod(path string, mode uint32, dev int) (err error)
  551. //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
  552. //sys Mlock(b []byte) (err error)
  553. //sys Mlockall(flags int) (err error)
  554. //sys Mprotect(b []byte, prot int) (err error)
  555. //sys Msync(b []byte, flags int) (err error)
  556. //sys Munlock(b []byte) (err error)
  557. //sys Munlockall() (err error)
  558. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  559. //sys Open(path string, mode int, perm uint32) (fd int, err error)
  560. //sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
  561. //sys Pathconf(path string, name int) (val int, err error)
  562. //sys Pause() (err error)
  563. //sys Pread(fd int, p []byte, offset int64) (n int, err error)
  564. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
  565. //sys read(fd int, p []byte) (n int, err error)
  566. //sys Readlink(path string, buf []byte) (n int, err error)
  567. //sys Rename(from string, to string) (err error)
  568. //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
  569. //sys Rmdir(path string) (err error)
  570. //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = lseek
  571. //sysnb Setegid(egid int) (err error)
  572. //sysnb Seteuid(euid int) (err error)
  573. //sysnb Setgid(gid int) (err error)
  574. //sys Sethostname(p []byte) (err error)
  575. //sysnb Setpgid(pid int, pgid int) (err error)
  576. //sys Setpriority(which int, who int, prio int) (err error)
  577. //sysnb Setregid(rgid int, egid int) (err error)
  578. //sysnb Setreuid(ruid int, euid int) (err error)
  579. //sysnb Setrlimit(which int, lim *Rlimit) (err error)
  580. //sysnb Setsid() (pid int, err error)
  581. //sysnb Setuid(uid int) (err error)
  582. //sys Shutdown(s int, how int) (err error) = libsocket.shutdown
  583. //sys Stat(path string, stat *Stat_t) (err error)
  584. //sys Statvfs(path string, vfsstat *Statvfs_t) (err error)
  585. //sys Symlink(path string, link string) (err error)
  586. //sys Sync() (err error)
  587. //sysnb Times(tms *Tms) (ticks uintptr, err error)
  588. //sys Truncate(path string, length int64) (err error)
  589. //sys Fsync(fd int) (err error)
  590. //sys Ftruncate(fd int, length int64) (err error)
  591. //sys Umask(mask int) (oldmask int)
  592. //sysnb Uname(buf *Utsname) (err error)
  593. //sys Unmount(target string, flags int) (err error) = libc.umount
  594. //sys Unlink(path string) (err error)
  595. //sys Unlinkat(dirfd int, path string, flags int) (err error)
  596. //sys Ustat(dev int, ubuf *Ustat_t) (err error)
  597. //sys Utime(path string, buf *Utimbuf) (err error)
  598. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) = libsocket.__xnet_bind
  599. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) = libsocket.__xnet_connect
  600. //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
  601. //sys munmap(addr uintptr, length uintptr) (err error)
  602. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) = libsocket.__xnet_sendto
  603. //sys socket(domain int, typ int, proto int) (fd int, err error) = libsocket.__xnet_socket
  604. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) = libsocket.__xnet_socketpair
  605. //sys write(fd int, p []byte) (n int, err error)
  606. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) = libsocket.__xnet_getsockopt
  607. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) = libsocket.getpeername
  608. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) = libsocket.setsockopt
  609. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) = libsocket.recvfrom
  610. func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
  611. r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procread)), 3, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf), 0, 0, 0)
  612. n = int(r0)
  613. if e1 != 0 {
  614. err = e1
  615. }
  616. return
  617. }
  618. func writelen(fd int, buf *byte, nbuf int) (n int, err error) {
  619. r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procwrite)), 3, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf), 0, 0, 0)
  620. n = int(r0)
  621. if e1 != 0 {
  622. err = e1
  623. }
  624. return
  625. }
  626. var mapper = &mmapper{
  627. active: make(map[*byte][]byte),
  628. mmap: mmap,
  629. munmap: munmap,
  630. }
  631. func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
  632. return mapper.Mmap(fd, offset, length, prot, flags)
  633. }
  634. func Munmap(b []byte) (err error) {
  635. return mapper.Munmap(b)
  636. }