syscall_linux_amd64.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. import "syscall"
  7. //sys Dup2(oldfd int, newfd 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 Fstatfs(fd int, buf *Statfs_t) (err error)
  12. //sys Ftruncate(fd int, length int64) (err error)
  13. //sysnb Getegid() (egid int)
  14. //sysnb Geteuid() (euid int)
  15. //sysnb Getgid() (gid int)
  16. //sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
  17. //sysnb Getuid() (uid int)
  18. //sysnb InotifyInit() (fd int, err error)
  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. //sys Lstat(path string, stat *Stat_t) (err error)
  24. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  25. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  26. //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
  27. //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
  28. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
  29. //sys Setfsgid(gid int) (err error)
  30. //sys Setfsuid(uid int) (err error)
  31. //sysnb Setregid(rgid int, egid int) (err error)
  32. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  33. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  34. //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
  35. //sysnb Setreuid(ruid int, euid int) (err error)
  36. //sys Shutdown(fd int, how int) (err error)
  37. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
  38. //sys Stat(path string, stat *Stat_t) (err error)
  39. //sys Statfs(path string, buf *Statfs_t) (err error)
  40. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  41. //sys Truncate(path string, length int64) (err error)
  42. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  43. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  44. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  45. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  46. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  47. //sysnb setgroups(n int, list *_Gid_t) (err error)
  48. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  49. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  50. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  51. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  52. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  53. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  54. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  55. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  56. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  57. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  58. //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
  59. //go:noescape
  60. func gettimeofday(tv *Timeval) (err syscall.Errno)
  61. func Gettimeofday(tv *Timeval) (err error) {
  62. errno := gettimeofday(tv)
  63. if errno != 0 {
  64. return errno
  65. }
  66. return nil
  67. }
  68. func Getpagesize() int { return 4096 }
  69. func Time(t *Time_t) (tt Time_t, err error) {
  70. var tv Timeval
  71. errno := gettimeofday(&tv)
  72. if errno != 0 {
  73. return 0, errno
  74. }
  75. if t != nil {
  76. *t = Time_t(tv.Sec)
  77. }
  78. return Time_t(tv.Sec), nil
  79. }
  80. func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
  81. func NsecToTimespec(nsec int64) (ts Timespec) {
  82. ts.Sec = nsec / 1e9
  83. ts.Nsec = nsec % 1e9
  84. return
  85. }
  86. func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
  87. func NsecToTimeval(nsec int64) (tv Timeval) {
  88. nsec += 999 // round up to microsecond
  89. tv.Sec = nsec / 1e9
  90. tv.Usec = nsec % 1e9 / 1e3
  91. return
  92. }
  93. //sysnb pipe(p *[2]_C_int) (err error)
  94. func Pipe(p []int) (err error) {
  95. if len(p) != 2 {
  96. return EINVAL
  97. }
  98. var pp [2]_C_int
  99. err = pipe(&pp)
  100. p[0] = int(pp[0])
  101. p[1] = int(pp[1])
  102. return
  103. }
  104. //sysnb pipe2(p *[2]_C_int, flags int) (err error)
  105. func Pipe2(p []int, flags int) (err error) {
  106. if len(p) != 2 {
  107. return EINVAL
  108. }
  109. var pp [2]_C_int
  110. err = pipe2(&pp, flags)
  111. p[0] = int(pp[0])
  112. p[1] = int(pp[1])
  113. return
  114. }
  115. func (r *PtraceRegs) PC() uint64 { return r.Rip }
  116. func (r *PtraceRegs) SetPC(pc uint64) { r.Rip = pc }
  117. func (iov *Iovec) SetLen(length int) {
  118. iov.Len = uint64(length)
  119. }
  120. func (msghdr *Msghdr) SetControllen(length int) {
  121. msghdr.Controllen = uint64(length)
  122. }
  123. func (cmsg *Cmsghdr) SetLen(length int) {
  124. cmsg.Len = uint64(length)
  125. }