syscall_linux_ppc.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // Copyright 2021 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 && ppc
  5. // +build linux,ppc
  6. package unix
  7. import (
  8. "syscall"
  9. "unsafe"
  10. )
  11. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
  12. //sys Fchown(fd int, uid int, gid int) (err error)
  13. //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64
  14. //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64
  15. //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64
  16. //sysnb Getegid() (egid int)
  17. //sysnb Geteuid() (euid int)
  18. //sysnb Getgid() (gid int)
  19. //sysnb Getuid() (uid int)
  20. //sys Ioperm(from int, num int, on int) (err error)
  21. //sys Iopl(level int) (err error)
  22. //sys Lchown(path string, uid int, gid int) (err error)
  23. //sys Listen(s int, n int) (err error)
  24. //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64
  25. //sys Pause() (err error)
  26. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  27. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  28. //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
  29. //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
  30. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64
  31. //sys setfsgid(gid int) (prev int, err error)
  32. //sys setfsuid(uid int) (prev int, err error)
  33. //sysnb Setregid(rgid int, egid int) (err error)
  34. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  35. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  36. //sysnb Setreuid(ruid int, euid int) (err error)
  37. //sys Shutdown(fd int, how int) (err error)
  38. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
  39. //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
  40. //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
  41. //sys Ustat(dev int, ubuf *Ustat_t) (err error)
  42. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  43. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  44. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  45. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  46. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  47. //sysnb setgroups(n int, list *_Gid_t) (err error)
  48. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  49. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  50. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  51. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  52. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  53. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  54. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  55. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  56. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  57. //sys sendmsg(s int, msg *Msghdr, flags int) (n 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. func Fadvise(fd int, offset int64, length int64, advice int) (err error) {
  64. _, _, e1 := Syscall6(SYS_FADVISE64_64, uintptr(fd), uintptr(advice), uintptr(offset>>32), uintptr(offset), uintptr(length>>32), uintptr(length))
  65. if e1 != 0 {
  66. err = errnoErr(e1)
  67. }
  68. return
  69. }
  70. func seek(fd int, offset int64, whence int) (int64, syscall.Errno) {
  71. var newoffset int64
  72. offsetLow := uint32(offset & 0xffffffff)
  73. offsetHigh := uint32((offset >> 32) & 0xffffffff)
  74. _, _, err := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offsetHigh), uintptr(offsetLow), uintptr(unsafe.Pointer(&newoffset)), uintptr(whence), 0)
  75. return newoffset, err
  76. }
  77. func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
  78. newoffset, errno := seek(fd, offset, whence)
  79. if errno != 0 {
  80. return 0, errno
  81. }
  82. return newoffset, nil
  83. }
  84. func Fstatfs(fd int, buf *Statfs_t) (err error) {
  85. _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
  86. if e != 0 {
  87. err = e
  88. }
  89. return
  90. }
  91. func Statfs(path string, buf *Statfs_t) (err error) {
  92. pathp, err := BytePtrFromString(path)
  93. if err != nil {
  94. return err
  95. }
  96. _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
  97. if e != 0 {
  98. err = e
  99. }
  100. return
  101. }
  102. //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
  103. func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
  104. page := uintptr(offset / 4096)
  105. if offset != int64(page)*4096 {
  106. return 0, EINVAL
  107. }
  108. return mmap2(addr, length, prot, flags, fd, page)
  109. }
  110. func setTimespec(sec, nsec int64) Timespec {
  111. return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
  112. }
  113. func setTimeval(sec, usec int64) Timeval {
  114. return Timeval{Sec: int32(sec), Usec: int32(usec)}
  115. }
  116. type rlimit32 struct {
  117. Cur uint32
  118. Max uint32
  119. }
  120. //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_UGETRLIMIT
  121. const rlimInf32 = ^uint32(0)
  122. const rlimInf64 = ^uint64(0)
  123. func Getrlimit(resource int, rlim *Rlimit) (err error) {
  124. err = Prlimit(0, resource, nil, rlim)
  125. if err != ENOSYS {
  126. return err
  127. }
  128. rl := rlimit32{}
  129. err = getrlimit(resource, &rl)
  130. if err != nil {
  131. return
  132. }
  133. if rl.Cur == rlimInf32 {
  134. rlim.Cur = rlimInf64
  135. } else {
  136. rlim.Cur = uint64(rl.Cur)
  137. }
  138. if rl.Max == rlimInf32 {
  139. rlim.Max = rlimInf64
  140. } else {
  141. rlim.Max = uint64(rl.Max)
  142. }
  143. return
  144. }
  145. //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
  146. func Setrlimit(resource int, rlim *Rlimit) (err error) {
  147. err = Prlimit(0, resource, rlim, nil)
  148. if err != ENOSYS {
  149. return err
  150. }
  151. rl := rlimit32{}
  152. if rlim.Cur == rlimInf64 {
  153. rl.Cur = rlimInf32
  154. } else if rlim.Cur < uint64(rlimInf32) {
  155. rl.Cur = uint32(rlim.Cur)
  156. } else {
  157. return EINVAL
  158. }
  159. if rlim.Max == rlimInf64 {
  160. rl.Max = rlimInf32
  161. } else if rlim.Max < uint64(rlimInf32) {
  162. rl.Max = uint32(rlim.Max)
  163. } else {
  164. return EINVAL
  165. }
  166. return setrlimit(resource, &rl)
  167. }
  168. func (r *PtraceRegs) PC() uint32 { return r.Nip }
  169. func (r *PtraceRegs) SetPC(pc uint32) { r.Nip = pc }
  170. func (iov *Iovec) SetLen(length int) {
  171. iov.Len = uint32(length)
  172. }
  173. func (msghdr *Msghdr) SetControllen(length int) {
  174. msghdr.Controllen = uint32(length)
  175. }
  176. func (msghdr *Msghdr) SetIovlen(length int) {
  177. msghdr.Iovlen = uint32(length)
  178. }
  179. func (cmsg *Cmsghdr) SetLen(length int) {
  180. cmsg.Len = uint32(length)
  181. }
  182. func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
  183. rsa.Service_name_len = uint32(length)
  184. }
  185. //sys syncFileRange2(fd int, flags int, off int64, n int64) (err error) = SYS_SYNC_FILE_RANGE2
  186. func SyncFileRange(fd int, off int64, n int64, flags int) error {
  187. // The sync_file_range and sync_file_range2 syscalls differ only in the
  188. // order of their arguments.
  189. return syncFileRange2(fd, flags, off, n)
  190. }
  191. //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
  192. func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
  193. cmdlineLen := len(cmdline)
  194. if cmdlineLen > 0 {
  195. // Account for the additional NULL byte added by
  196. // BytePtrFromString in kexecFileLoad. The kexec_file_load
  197. // syscall expects a NULL-terminated string.
  198. cmdlineLen++
  199. }
  200. return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
  201. }