syscall_linux_arm64.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. // +build arm64,linux
  5. package unix
  6. import "unsafe"
  7. func EpollCreate(size int) (fd int, err error) {
  8. if size <= 0 {
  9. return -1, EINVAL
  10. }
  11. return EpollCreate1(0)
  12. }
  13. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
  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 Fstat(fd int, stat *Stat_t) (err error)
  17. //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
  18. //sys Fstatfs(fd int, buf *Statfs_t) (err error)
  19. //sys Ftruncate(fd int, length int64) (err error)
  20. //sysnb Getegid() (egid int)
  21. //sysnb Geteuid() (euid int)
  22. //sysnb Getgid() (gid int)
  23. //sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
  24. //sysnb Getuid() (uid int)
  25. //sys Listen(s int, n int) (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 Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
  30. func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
  31. var ts *Timespec
  32. if timeout != nil {
  33. ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
  34. }
  35. return Pselect(nfd, r, w, e, ts, nil)
  36. }
  37. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
  38. //sys Setfsgid(gid int) (err error)
  39. //sys Setfsuid(uid int) (err error)
  40. //sysnb Setregid(rgid int, egid int) (err error)
  41. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  42. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  43. //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
  44. //sysnb Setreuid(ruid int, euid int) (err error)
  45. //sys Shutdown(fd int, how int) (err error)
  46. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
  47. func Stat(path string, stat *Stat_t) (err error) {
  48. return Fstatat(AT_FDCWD, path, stat, 0)
  49. }
  50. func Lchown(path string, uid int, gid int) (err error) {
  51. return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
  52. }
  53. func Lstat(path string, stat *Stat_t) (err error) {
  54. return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
  55. }
  56. //sys Statfs(path string, buf *Statfs_t) (err error)
  57. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  58. //sys Truncate(path string, length int64) (err error)
  59. func Ustat(dev int, ubuf *Ustat_t) (err error) {
  60. return ENOSYS
  61. }
  62. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  63. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  64. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  65. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  66. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  67. //sysnb setgroups(n int, list *_Gid_t) (err error)
  68. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  69. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  70. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  71. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  72. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  73. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  74. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  75. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  76. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  77. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  78. //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
  79. //sysnb Gettimeofday(tv *Timeval) (err error)
  80. func setTimespec(sec, nsec int64) Timespec {
  81. return Timespec{Sec: sec, Nsec: nsec}
  82. }
  83. func setTimeval(sec, usec int64) Timeval {
  84. return Timeval{Sec: sec, Usec: usec}
  85. }
  86. func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
  87. if tv == nil {
  88. return utimensat(dirfd, path, nil, 0)
  89. }
  90. ts := []Timespec{
  91. NsecToTimespec(TimevalToNsec(tv[0])),
  92. NsecToTimespec(TimevalToNsec(tv[1])),
  93. }
  94. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  95. }
  96. func Time(t *Time_t) (Time_t, error) {
  97. var tv Timeval
  98. err := Gettimeofday(&tv)
  99. if err != nil {
  100. return 0, err
  101. }
  102. if t != nil {
  103. *t = Time_t(tv.Sec)
  104. }
  105. return Time_t(tv.Sec), nil
  106. }
  107. func Utime(path string, buf *Utimbuf) error {
  108. tv := []Timeval{
  109. {Sec: buf.Actime},
  110. {Sec: buf.Modtime},
  111. }
  112. return Utimes(path, tv)
  113. }
  114. func utimes(path string, tv *[2]Timeval) (err error) {
  115. if tv == nil {
  116. return utimensat(AT_FDCWD, path, nil, 0)
  117. }
  118. ts := []Timespec{
  119. NsecToTimespec(TimevalToNsec(tv[0])),
  120. NsecToTimespec(TimevalToNsec(tv[1])),
  121. }
  122. return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  123. }
  124. func Pipe(p []int) (err error) {
  125. if len(p) != 2 {
  126. return EINVAL
  127. }
  128. var pp [2]_C_int
  129. err = pipe2(&pp, 0)
  130. p[0] = int(pp[0])
  131. p[1] = int(pp[1])
  132. return
  133. }
  134. //sysnb pipe2(p *[2]_C_int, flags int) (err error)
  135. func Pipe2(p []int, flags int) (err error) {
  136. if len(p) != 2 {
  137. return EINVAL
  138. }
  139. var pp [2]_C_int
  140. err = pipe2(&pp, flags)
  141. p[0] = int(pp[0])
  142. p[1] = int(pp[1])
  143. return
  144. }
  145. func (r *PtraceRegs) PC() uint64 { return r.Pc }
  146. func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
  147. func (iov *Iovec) SetLen(length int) {
  148. iov.Len = uint64(length)
  149. }
  150. func (msghdr *Msghdr) SetControllen(length int) {
  151. msghdr.Controllen = uint64(length)
  152. }
  153. func (cmsg *Cmsghdr) SetLen(length int) {
  154. cmsg.Len = uint64(length)
  155. }
  156. func InotifyInit() (fd int, err error) {
  157. return InotifyInit1(0)
  158. }
  159. func Dup2(oldfd int, newfd int) (err error) {
  160. return Dup3(oldfd, newfd, 0)
  161. }
  162. func Pause() error {
  163. _, err := ppoll(nil, 0, nil, nil)
  164. return err
  165. }
  166. func Poll(fds []PollFd, timeout int) (n int, err error) {
  167. var ts *Timespec
  168. if timeout >= 0 {
  169. ts = new(Timespec)
  170. *ts = NsecToTimespec(int64(timeout) * 1e6)
  171. }
  172. if len(fds) == 0 {
  173. return ppoll(nil, 0, ts, nil)
  174. }
  175. return ppoll(&fds[0], len(fds), ts, nil)
  176. }