syscall_linux_mipsx.go 7.1 KB

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