syscall_linux_amd64.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. // +build amd64,linux
  5. package unix
  6. //sys Dup2(oldfd int, newfd int) (err error)
  7. //sysnb EpollCreate(size int) (fd int, err error)
  8. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
  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(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_NEWFSTATAT
  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. //sysnb inotifyInit() (fd int, err error)
  21. func InotifyInit() (fd int, err error) {
  22. // First try inotify_init1, because Android's seccomp policy blocks the latter.
  23. fd, err = InotifyInit1(0)
  24. if err == ENOSYS {
  25. fd, err = inotifyInit()
  26. }
  27. return
  28. }
  29. //sys Ioperm(from int, num int, on int) (err error)
  30. //sys Iopl(level int) (err error)
  31. //sys Lchown(path string, uid int, gid int) (err error)
  32. //sys Listen(s int, n int) (err error)
  33. func Lstat(path string, stat *Stat_t) (err error) {
  34. return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
  35. }
  36. //sys Pause() (err error)
  37. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  38. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  39. //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
  40. //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
  41. func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
  42. var ts *Timespec
  43. if timeout != nil {
  44. ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
  45. }
  46. return Pselect(nfd, r, w, e, ts, nil)
  47. }
  48. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
  49. //sys Setfsgid(gid int) (err error)
  50. //sys Setfsuid(uid int) (err error)
  51. //sysnb Setregid(rgid int, egid int) (err error)
  52. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  53. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  54. //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
  55. //sysnb Setreuid(ruid int, euid int) (err error)
  56. //sys Shutdown(fd int, how int) (err error)
  57. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
  58. func Stat(path string, stat *Stat_t) (err error) {
  59. // Use fstatat, because Android's seccomp policy blocks stat.
  60. return Fstatat(AT_FDCWD, path, stat, 0)
  61. }
  62. //sys Statfs(path string, buf *Statfs_t) (err error)
  63. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  64. //sys Truncate(path string, length int64) (err error)
  65. //sys Ustat(dev int, ubuf *Ustat_t) (err error)
  66. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  67. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  68. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  69. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  70. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  71. //sysnb setgroups(n int, list *_Gid_t) (err error)
  72. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  73. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  74. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  75. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  76. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  77. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  78. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  79. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  80. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  81. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  82. //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
  83. //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error)
  84. func Gettimeofday(tv *Timeval) (err error) {
  85. errno := gettimeofday(tv)
  86. if errno != 0 {
  87. return errno
  88. }
  89. return nil
  90. }
  91. func Time(t *Time_t) (tt Time_t, err error) {
  92. var tv Timeval
  93. errno := gettimeofday(&tv)
  94. if errno != 0 {
  95. return 0, errno
  96. }
  97. if t != nil {
  98. *t = Time_t(tv.Sec)
  99. }
  100. return Time_t(tv.Sec), nil
  101. }
  102. //sys Utime(path string, buf *Utimbuf) (err error)
  103. //sys utimes(path string, times *[2]Timeval) (err error)
  104. func setTimespec(sec, nsec int64) Timespec {
  105. return Timespec{Sec: sec, Nsec: nsec}
  106. }
  107. func setTimeval(sec, usec int64) Timeval {
  108. return Timeval{Sec: sec, Usec: usec}
  109. }
  110. //sysnb pipe(p *[2]_C_int) (err error)
  111. func Pipe(p []int) (err error) {
  112. if len(p) != 2 {
  113. return EINVAL
  114. }
  115. var pp [2]_C_int
  116. err = pipe(&pp)
  117. p[0] = int(pp[0])
  118. p[1] = int(pp[1])
  119. return
  120. }
  121. //sysnb pipe2(p *[2]_C_int, flags int) (err error)
  122. func Pipe2(p []int, flags int) (err error) {
  123. if len(p) != 2 {
  124. return EINVAL
  125. }
  126. var pp [2]_C_int
  127. err = pipe2(&pp, flags)
  128. p[0] = int(pp[0])
  129. p[1] = int(pp[1])
  130. return
  131. }
  132. func (r *PtraceRegs) PC() uint64 { return r.Rip }
  133. func (r *PtraceRegs) SetPC(pc uint64) { r.Rip = pc }
  134. func (iov *Iovec) SetLen(length int) {
  135. iov.Len = uint64(length)
  136. }
  137. func (msghdr *Msghdr) SetControllen(length int) {
  138. msghdr.Controllen = uint64(length)
  139. }
  140. func (msghdr *Msghdr) SetIovlen(length int) {
  141. msghdr.Iovlen = uint64(length)
  142. }
  143. func (cmsg *Cmsghdr) SetLen(length int) {
  144. cmsg.Len = uint64(length)
  145. }
  146. //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error)
  147. func Poll(fds []PollFd, timeout int) (n int, err error) {
  148. if len(fds) == 0 {
  149. return poll(nil, 0, timeout)
  150. }
  151. return poll(&fds[0], len(fds), timeout)
  152. }
  153. //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
  154. func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
  155. cmdlineLen := len(cmdline)
  156. if cmdlineLen > 0 {
  157. // Account for the additional NULL byte added by
  158. // BytePtrFromString in kexecFileLoad. The kexec_file_load
  159. // syscall expects a NULL-terminated string.
  160. cmdlineLen++
  161. }
  162. return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
  163. }