syscall_linux_arm64.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // Copyright 2015 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 arm64 && linux
  5. // +build arm64,linux
  6. package unix
  7. import "unsafe"
  8. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
  9. //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
  10. //sys Fchown(fd int, uid int, gid int) (err error)
  11. //sys Fstat(fd int, stat *Stat_t) (err error)
  12. //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
  13. //sys Fstatfs(fd int, buf *Statfs_t) (err error)
  14. //sys Ftruncate(fd int, length int64) (err error)
  15. //sysnb Getegid() (egid int)
  16. //sysnb Geteuid() (euid int)
  17. //sysnb Getgid() (gid int)
  18. //sysnb getrlimit(resource int, rlim *Rlimit) (err error)
  19. //sysnb Getuid() (uid int)
  20. //sys Listen(s int, n int) (err error)
  21. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  22. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  23. //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
  24. //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
  25. func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
  26. var ts *Timespec
  27. if timeout != nil {
  28. ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
  29. }
  30. return Pselect(nfd, r, w, e, ts, nil)
  31. }
  32. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
  33. //sys setfsgid(gid int) (prev int, err error)
  34. //sys setfsuid(uid int) (prev int, err error)
  35. //sysnb Setregid(rgid int, egid int) (err error)
  36. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  37. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  38. //sysnb setrlimit(resource int, rlim *Rlimit) (err error)
  39. //sysnb Setreuid(ruid int, euid int) (err error)
  40. //sys Shutdown(fd int, how int) (err error)
  41. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
  42. func Stat(path string, stat *Stat_t) (err error) {
  43. return Fstatat(AT_FDCWD, path, stat, 0)
  44. }
  45. func Lchown(path string, uid int, gid int) (err error) {
  46. return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
  47. }
  48. func Lstat(path string, stat *Stat_t) (err error) {
  49. return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
  50. }
  51. //sys Statfs(path string, buf *Statfs_t) (err error)
  52. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  53. //sys Truncate(path string, length int64) (err error)
  54. func Ustat(dev int, ubuf *Ustat_t) (err error) {
  55. return ENOSYS
  56. }
  57. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  58. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  59. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  60. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  61. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  62. //sysnb setgroups(n int, list *_Gid_t) (err error)
  63. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  64. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  65. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  66. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  67. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  68. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  69. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  70. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  71. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  72. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  73. //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
  74. //sysnb Gettimeofday(tv *Timeval) (err error)
  75. func setTimespec(sec, nsec int64) Timespec {
  76. return Timespec{Sec: sec, Nsec: nsec}
  77. }
  78. func setTimeval(sec, usec int64) Timeval {
  79. return Timeval{Sec: sec, Usec: usec}
  80. }
  81. func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
  82. if tv == nil {
  83. return utimensat(dirfd, path, nil, 0)
  84. }
  85. ts := []Timespec{
  86. NsecToTimespec(TimevalToNsec(tv[0])),
  87. NsecToTimespec(TimevalToNsec(tv[1])),
  88. }
  89. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  90. }
  91. func Time(t *Time_t) (Time_t, error) {
  92. var tv Timeval
  93. err := Gettimeofday(&tv)
  94. if err != nil {
  95. return 0, err
  96. }
  97. if t != nil {
  98. *t = Time_t(tv.Sec)
  99. }
  100. return Time_t(tv.Sec), nil
  101. }
  102. func Utime(path string, buf *Utimbuf) error {
  103. tv := []Timeval{
  104. {Sec: buf.Actime},
  105. {Sec: buf.Modtime},
  106. }
  107. return Utimes(path, tv)
  108. }
  109. func utimes(path string, tv *[2]Timeval) (err error) {
  110. if tv == nil {
  111. return utimensat(AT_FDCWD, path, nil, 0)
  112. }
  113. ts := []Timespec{
  114. NsecToTimespec(TimevalToNsec(tv[0])),
  115. NsecToTimespec(TimevalToNsec(tv[1])),
  116. }
  117. return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  118. }
  119. // Getrlimit prefers the prlimit64 system call. See issue 38604.
  120. func Getrlimit(resource int, rlim *Rlimit) error {
  121. err := Prlimit(0, resource, nil, rlim)
  122. if err != ENOSYS {
  123. return err
  124. }
  125. return getrlimit(resource, rlim)
  126. }
  127. // Setrlimit prefers the prlimit64 system call. See issue 38604.
  128. func Setrlimit(resource int, rlim *Rlimit) error {
  129. err := Prlimit(0, resource, rlim, nil)
  130. if err != ENOSYS {
  131. return err
  132. }
  133. return setrlimit(resource, rlim)
  134. }
  135. func (r *PtraceRegs) PC() uint64 { return r.Pc }
  136. func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
  137. func (iov *Iovec) SetLen(length int) {
  138. iov.Len = uint64(length)
  139. }
  140. func (msghdr *Msghdr) SetControllen(length int) {
  141. msghdr.Controllen = uint64(length)
  142. }
  143. func (msghdr *Msghdr) SetIovlen(length int) {
  144. msghdr.Iovlen = uint64(length)
  145. }
  146. func (cmsg *Cmsghdr) SetLen(length int) {
  147. cmsg.Len = uint64(length)
  148. }
  149. func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
  150. rsa.Service_name_len = uint64(length)
  151. }
  152. func Pause() error {
  153. _, err := ppoll(nil, 0, nil, nil)
  154. return err
  155. }
  156. //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
  157. func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
  158. cmdlineLen := len(cmdline)
  159. if cmdlineLen > 0 {
  160. // Account for the additional NULL byte added by
  161. // BytePtrFromString in kexecFileLoad. The kexec_file_load
  162. // syscall expects a NULL-terminated string.
  163. cmdlineLen++
  164. }
  165. return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
  166. }