本站源代码
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.

725 lines
21KB

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