syscall_linux_amd64.go 5.6 KB

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