syscall_linux_mipsx.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. //go:build linux && (mips || mipsle)
  5. // +build linux
  6. // +build mips mipsle
  7. package unix
  8. import (
  9. "syscall"
  10. "unsafe"
  11. )
  12. func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
  13. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
  14. //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
  15. //sys Fchown(fd int, uid int, gid int) (err error)
  16. //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
  17. //sysnb Getegid() (egid int)
  18. //sysnb Geteuid() (euid int)
  19. //sysnb Getgid() (gid int)
  20. //sysnb Getuid() (uid int)
  21. //sys Lchown(path string, uid int, gid int) (err error)
  22. //sys Listen(s int, n int) (err error)
  23. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  24. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  25. //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
  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) (prev int, err error)
  29. //sys setfsuid(uid int) (prev 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. //sys Ioperm(from int, num int, on int) (err error)
  56. //sys Iopl(level int) (err error)
  57. //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error)
  58. //sysnb Gettimeofday(tv *Timeval) (err error)
  59. //sysnb Time(t *Time_t) (tt Time_t, err error)
  60. //sys Utime(path string, buf *Utimbuf) (err error)
  61. //sys utimes(path string, times *[2]Timeval) (err error)
  62. //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
  63. //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
  64. //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64
  65. //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
  66. //sys Pause() (err error)
  67. func Fstatfs(fd int, buf *Statfs_t) (err error) {
  68. _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
  69. if e != 0 {
  70. err = errnoErr(e)
  71. }
  72. return
  73. }
  74. func Statfs(path string, buf *Statfs_t) (err error) {
  75. p, err := BytePtrFromString(path)
  76. if err != nil {
  77. return err
  78. }
  79. _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(p)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
  80. if e != 0 {
  81. err = errnoErr(e)
  82. }
  83. return
  84. }
  85. func Seek(fd int, offset int64, whence int) (off int64, err error) {
  86. _, _, e := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offset>>32), uintptr(offset), uintptr(unsafe.Pointer(&off)), uintptr(whence), 0)
  87. if e != 0 {
  88. err = errnoErr(e)
  89. }
  90. return
  91. }
  92. func setTimespec(sec, nsec int64) Timespec {
  93. return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
  94. }
  95. func setTimeval(sec, usec int64) Timeval {
  96. return Timeval{Sec: int32(sec), Usec: int32(usec)}
  97. }
  98. //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
  99. func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
  100. page := uintptr(offset / 4096)
  101. if offset != int64(page)*4096 {
  102. return 0, EINVAL
  103. }
  104. return mmap2(addr, length, prot, flags, fd, page)
  105. }
  106. const rlimInf32 = ^uint32(0)
  107. const rlimInf64 = ^uint64(0)
  108. type rlimit32 struct {
  109. Cur uint32
  110. Max uint32
  111. }
  112. //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT
  113. func Getrlimit(resource int, rlim *Rlimit) (err error) {
  114. err = Prlimit(0, resource, nil, rlim)
  115. if err != ENOSYS {
  116. return err
  117. }
  118. rl := rlimit32{}
  119. err = getrlimit(resource, &rl)
  120. if err != nil {
  121. return
  122. }
  123. if rl.Cur == rlimInf32 {
  124. rlim.Cur = rlimInf64
  125. } else {
  126. rlim.Cur = uint64(rl.Cur)
  127. }
  128. if rl.Max == rlimInf32 {
  129. rlim.Max = rlimInf64
  130. } else {
  131. rlim.Max = uint64(rl.Max)
  132. }
  133. return
  134. }
  135. //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
  136. func Setrlimit(resource int, rlim *Rlimit) (err error) {
  137. err = Prlimit(0, resource, rlim, nil)
  138. if err != ENOSYS {
  139. return err
  140. }
  141. rl := rlimit32{}
  142. if rlim.Cur == rlimInf64 {
  143. rl.Cur = rlimInf32
  144. } else if rlim.Cur < uint64(rlimInf32) {
  145. rl.Cur = uint32(rlim.Cur)
  146. } else {
  147. return EINVAL
  148. }
  149. if rlim.Max == rlimInf64 {
  150. rl.Max = rlimInf32
  151. } else if rlim.Max < uint64(rlimInf32) {
  152. rl.Max = uint32(rlim.Max)
  153. } else {
  154. return EINVAL
  155. }
  156. return setrlimit(resource, &rl)
  157. }
  158. func (r *PtraceRegs) PC() uint64 { return r.Epc }
  159. func (r *PtraceRegs) SetPC(pc uint64) { r.Epc = pc }
  160. func (iov *Iovec) SetLen(length int) {
  161. iov.Len = uint32(length)
  162. }
  163. func (msghdr *Msghdr) SetControllen(length int) {
  164. msghdr.Controllen = uint32(length)
  165. }
  166. func (msghdr *Msghdr) SetIovlen(length int) {
  167. msghdr.Iovlen = uint32(length)
  168. }
  169. func (cmsg *Cmsghdr) SetLen(length int) {
  170. cmsg.Len = uint32(length)
  171. }
  172. func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
  173. rsa.Service_name_len = uint32(length)
  174. }