syscall_linux_arm.go 7.9 KB

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