syscall_linux_mipsx.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // Copyright 2016 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. // +build linux
  5. // +build mips mipsle
  6. package unix
  7. import (
  8. "syscall"
  9. "unsafe"
  10. )
  11. func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
  12. //sys Dup2(oldfd int, newfd int) (err error)
  13. //sys Fchown(fd int, uid int, gid int) (err error)
  14. //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
  15. //sysnb Getegid() (egid int)
  16. //sysnb Geteuid() (euid int)
  17. //sysnb Getgid() (gid int)
  18. //sysnb Getuid() (uid int)
  19. //sys Lchown(path string, uid int, gid int) (err error)
  20. //sys Listen(s int, n int) (err error)
  21. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  22. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  23. //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
  24. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
  25. //sys Setfsgid(gid int) (err error)
  26. //sys Setfsuid(uid int) (err error)
  27. //sysnb Setregid(rgid int, egid int) (err error)
  28. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  29. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  30. //sysnb Setreuid(ruid int, euid int) (err error)
  31. //sys Shutdown(fd int, how int) (err error)
  32. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
  33. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  34. //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
  35. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  36. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  37. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  38. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  39. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  40. //sysnb setgroups(n int, list *_Gid_t) (err error)
  41. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  42. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  43. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  44. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  45. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  46. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  47. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  48. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  49. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  50. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  51. //sysnb InotifyInit() (fd int, err error)
  52. //sys Ioperm(from int, num int, on int) (err error)
  53. //sys Iopl(level int) (err error)
  54. //sysnb Gettimeofday(tv *Timeval) (err error)
  55. //sysnb Time(t *Time_t) (tt Time_t, err error)
  56. //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
  57. //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
  58. //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
  59. //sys Utime(path string, buf *Utimbuf) (err error)
  60. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
  61. //sys Pause() (err error)
  62. func Fstatfs(fd int, buf *Statfs_t) (err error) {
  63. _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
  64. if e != 0 {
  65. err = errnoErr(e)
  66. }
  67. return
  68. }
  69. func Statfs(path string, buf *Statfs_t) (err error) {
  70. p, err := BytePtrFromString(path)
  71. if err != nil {
  72. return err
  73. }
  74. _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(p)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
  75. if e != 0 {
  76. err = errnoErr(e)
  77. }
  78. return
  79. }
  80. func Seek(fd int, offset int64, whence int) (off int64, err error) {
  81. _, _, e := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offset>>32), uintptr(offset), uintptr(unsafe.Pointer(&off)), uintptr(whence), 0)
  82. if e != 0 {
  83. err = errnoErr(e)
  84. }
  85. return
  86. }
  87. func setTimespec(sec, nsec int64) Timespec {
  88. return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
  89. }
  90. func setTimeval(sec, usec int64) Timeval {
  91. return Timeval{Sec: int32(sec), Usec: int32(usec)}
  92. }
  93. //sysnb pipe2(p *[2]_C_int, flags int) (err error)
  94. func Pipe2(p []int, flags int) (err error) {
  95. if len(p) != 2 {
  96. return EINVAL
  97. }
  98. var pp [2]_C_int
  99. err = pipe2(&pp, flags)
  100. p[0] = int(pp[0])
  101. p[1] = int(pp[1])
  102. return
  103. }
  104. func Pipe(p []int) (err error) {
  105. if len(p) != 2 {
  106. return EINVAL
  107. }
  108. var pp [2]_C_int
  109. err = pipe2(&pp, 0)
  110. p[0] = int(pp[0])
  111. p[1] = int(pp[1])
  112. return
  113. }
  114. //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
  115. func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
  116. page := uintptr(offset / 4096)
  117. if offset != int64(page)*4096 {
  118. return 0, EINVAL
  119. }
  120. return mmap2(addr, length, prot, flags, fd, page)
  121. }
  122. const rlimInf32 = ^uint32(0)
  123. const rlimInf64 = ^uint64(0)
  124. type rlimit32 struct {
  125. Cur uint32
  126. Max uint32
  127. }
  128. //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT
  129. func Getrlimit(resource int, rlim *Rlimit) (err error) {
  130. err = prlimit(0, resource, nil, rlim)
  131. if err != ENOSYS {
  132. return err
  133. }
  134. rl := rlimit32{}
  135. err = getrlimit(resource, &rl)
  136. if err != nil {
  137. return
  138. }
  139. if rl.Cur == rlimInf32 {
  140. rlim.Cur = rlimInf64
  141. } else {
  142. rlim.Cur = uint64(rl.Cur)
  143. }
  144. if rl.Max == rlimInf32 {
  145. rlim.Max = rlimInf64
  146. } else {
  147. rlim.Max = uint64(rl.Max)
  148. }
  149. return
  150. }
  151. //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
  152. func Setrlimit(resource int, rlim *Rlimit) (err error) {
  153. err = prlimit(0, resource, rlim, nil)
  154. if err != ENOSYS {
  155. return err
  156. }
  157. rl := rlimit32{}
  158. if rlim.Cur == rlimInf64 {
  159. rl.Cur = rlimInf32
  160. } else if rlim.Cur < uint64(rlimInf32) {
  161. rl.Cur = uint32(rlim.Cur)
  162. } else {
  163. return EINVAL
  164. }
  165. if rlim.Max == rlimInf64 {
  166. rl.Max = rlimInf32
  167. } else if rlim.Max < uint64(rlimInf32) {
  168. rl.Max = uint32(rlim.Max)
  169. } else {
  170. return EINVAL
  171. }
  172. return setrlimit(resource, &rl)
  173. }
  174. func (r *PtraceRegs) PC() uint64 { return r.Epc }
  175. func (r *PtraceRegs) SetPC(pc uint64) { r.Epc = pc }
  176. func (iov *Iovec) SetLen(length int) {
  177. iov.Len = uint32(length)
  178. }
  179. func (msghdr *Msghdr) SetControllen(length int) {
  180. msghdr.Controllen = uint32(length)
  181. }
  182. func (cmsg *Cmsghdr) SetLen(length int) {
  183. cmsg.Len = uint32(length)
  184. }
  185. //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error)
  186. func Poll(fds []PollFd, timeout int) (n int, err error) {
  187. if len(fds) == 0 {
  188. return poll(nil, 0, timeout)
  189. }
  190. return poll(&fds[0], len(fds), timeout)
  191. }