syscall_linux_mipsx.go 7.2 KB

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