syscall_linux_arm64.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
  7. //sys Fchown(fd int, uid int, gid int) (err error)
  8. //sys Fstat(fd int, stat *Stat_t) (err error)
  9. //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
  10. //sys Fstatfs(fd int, buf *Statfs_t) (err error)
  11. //sys Ftruncate(fd int, length int64) (err error)
  12. //sysnb Getegid() (egid int)
  13. //sysnb Geteuid() (euid int)
  14. //sysnb Getgid() (gid int)
  15. //sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
  16. //sysnb Getuid() (uid int)
  17. //sys Listen(s int, n int) (err error)
  18. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  19. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  20. //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
  21. //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS_PSELECT6
  22. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
  23. //sys Setfsgid(gid int) (err error)
  24. //sys Setfsuid(uid int) (err error)
  25. //sysnb Setregid(rgid int, egid int) (err error)
  26. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  27. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  28. //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
  29. //sysnb Setreuid(ruid int, euid int) (err error)
  30. //sys Shutdown(fd int, how int) (err error)
  31. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
  32. func Stat(path string, stat *Stat_t) (err error) {
  33. return Fstatat(AT_FDCWD, path, stat, 0)
  34. }
  35. func Lchown(path string, uid int, gid int) (err error) {
  36. return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
  37. }
  38. func Lstat(path string, stat *Stat_t) (err error) {
  39. return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
  40. }
  41. //sys Statfs(path string, buf *Statfs_t) (err error)
  42. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  43. //sys Truncate(path string, length int64) (err error)
  44. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  45. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  46. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  47. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  48. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  49. //sysnb setgroups(n int, list *_Gid_t) (err error)
  50. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  51. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  52. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  53. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  54. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  55. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  56. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  57. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  58. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  59. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  60. //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
  61. func Getpagesize() int { return 65536 }
  62. //sysnb Gettimeofday(tv *Timeval) (err error)
  63. func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
  64. func NsecToTimespec(nsec int64) (ts Timespec) {
  65. ts.Sec = nsec / 1e9
  66. ts.Nsec = nsec % 1e9
  67. return
  68. }
  69. func NsecToTimeval(nsec int64) (tv Timeval) {
  70. nsec += 999 // round up to microsecond
  71. tv.Sec = nsec / 1e9
  72. tv.Usec = nsec % 1e9 / 1e3
  73. return
  74. }
  75. func Time(t *Time_t) (Time_t, error) {
  76. var tv Timeval
  77. err := Gettimeofday(&tv)
  78. if err != nil {
  79. return 0, err
  80. }
  81. if t != nil {
  82. *t = Time_t(tv.Sec)
  83. }
  84. return Time_t(tv.Sec), nil
  85. }
  86. func Utime(path string, buf *Utimbuf) error {
  87. tv := []Timeval{
  88. {Sec: buf.Actime},
  89. {Sec: buf.Modtime},
  90. }
  91. return Utimes(path, tv)
  92. }
  93. func Pipe(p []int) (err error) {
  94. if len(p) != 2 {
  95. return EINVAL
  96. }
  97. var pp [2]_C_int
  98. err = pipe2(&pp, 0)
  99. p[0] = int(pp[0])
  100. p[1] = int(pp[1])
  101. return
  102. }
  103. //sysnb pipe2(p *[2]_C_int, flags int) (err error)
  104. func Pipe2(p []int, flags int) (err error) {
  105. if len(p) != 2 {
  106. return EINVAL
  107. }
  108. var pp [2]_C_int
  109. err = pipe2(&pp, flags)
  110. p[0] = int(pp[0])
  111. p[1] = int(pp[1])
  112. return
  113. }
  114. func (r *PtraceRegs) PC() uint64 { return r.Pc }
  115. func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
  116. func (iov *Iovec) SetLen(length int) {
  117. iov.Len = uint64(length)
  118. }
  119. func (msghdr *Msghdr) SetControllen(length int) {
  120. msghdr.Controllen = uint64(length)
  121. }
  122. func (cmsg *Cmsghdr) SetLen(length int) {
  123. cmsg.Len = uint64(length)
  124. }
  125. func InotifyInit() (fd int, err error) {
  126. return InotifyInit1(0)
  127. }
  128. func Dup2(oldfd int, newfd int) (err error) {
  129. return Dup3(oldfd, newfd, 0)
  130. }
  131. func Pause() (err error) {
  132. _, _, e1 := Syscall6(SYS_PPOLL, 0, 0, 0, 0, 0, 0)
  133. if e1 != 0 {
  134. err = errnoErr(e1)
  135. }
  136. return
  137. }
  138. // TODO(dfc): constants that should be in zsysnum_linux_arm64.go, remove
  139. // these when the deprecated syscalls that the syscall package relies on
  140. // are removed.
  141. const (
  142. SYS_GETPGRP = 1060
  143. SYS_UTIMES = 1037
  144. SYS_FUTIMESAT = 1066
  145. SYS_PAUSE = 1061
  146. SYS_USTAT = 1070
  147. SYS_UTIME = 1063
  148. SYS_LCHOWN = 1032
  149. SYS_TIME = 1062
  150. SYS_EPOLL_CREATE = 1042
  151. SYS_EPOLL_WAIT = 1069
  152. )
  153. func Poll(fds []PollFd, timeout int) (n int, err error) {
  154. var ts *Timespec
  155. if timeout >= 0 {
  156. ts = new(Timespec)
  157. *ts = NsecToTimespec(int64(timeout) * 1e6)
  158. }
  159. if len(fds) == 0 {
  160. return ppoll(nil, 0, ts, nil)
  161. }
  162. return ppoll(&fds[0], len(fds), ts, nil)
  163. }