Source file src/syscall/syscall_linux_amd64.go
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 5 package syscall 6 7 import ( 8 "unsafe" 9 ) 10 11 const ( 12 _SYS_setgroups = SYS_SETGROUPS 13 _SYS_clone3 = 435 14 _SYS_faccessat2 = 439 15 _SYS_fchmodat2 = 452 16 ) 17 18 //sys Dup2(oldfd int, newfd int) (err error) 19 //sys Fchown(fd int, uid int, gid int) (err error) 20 //sys Fstat(fd int, stat *Stat_t) (err error) 21 //sys Fstatfs(fd int, buf *Statfs_t) (err error) 22 //sys Ftruncate(fd int, length int64) (err error) 23 //sysnb Getegid() (egid int) 24 //sysnb Geteuid() (euid int) 25 //sysnb Getgid() (gid int) 26 //sysnb Getrlimit(resource int, rlim *Rlimit) (err error) 27 //sysnb Getuid() (uid int) 28 //sysnb InotifyInit() (fd int, err error) 29 //sys Ioperm(from int, num int, on int) (err error) 30 //sys Iopl(level int) (err error) 31 //sys Listen(s int, n int) (err error) 32 //sys Pause() (err error) 33 //sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 34 //sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 35 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) 36 //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK 37 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) 38 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) 39 //sys Setfsgid(gid int) (err error) 40 //sys Setfsuid(uid int) (err error) 41 //sysnb setrlimit(resource int, rlim *Rlimit) (err error) = SYS_SETRLIMIT 42 //sys Shutdown(fd int, how int) (err error) 43 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) 44 //sys Statfs(path string, buf *Statfs_t) (err error) 45 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) 46 //sys Truncate(path string, length int64) (err error) 47 //sys Ustat(dev int, ubuf *Ustat_t) (err error) 48 //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) 49 //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 50 //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 51 //sys fstatat(fd int, path string, stat *Stat_t, flags int) (err error) = SYS_NEWFSTATAT 52 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) 53 //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) 54 //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) 55 //sysnb socket(domain int, typ int, proto int) (fd int, err error) 56 //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) 57 //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 58 //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 59 //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) 60 //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) 61 //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) 62 //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) 63 //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) 64 //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) 65 66 func Stat(path string, stat *Stat_t) (err error) { 67 return fstatat(_AT_FDCWD, path, stat, 0) 68 } 69 70 func Lchown(path string, uid int, gid int) (err error) { 71 return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW) 72 } 73 74 func Lstat(path string, stat *Stat_t) (err error) { 75 return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW) 76 } 77 78 //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error) 79 80 //go:noescape 81 func gettimeofday(tv *Timeval) (err Errno) 82 83 func Gettimeofday(tv *Timeval) (err error) { 84 errno := gettimeofday(tv) 85 if errno != 0 { 86 return errno 87 } 88 return nil 89 } 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 103 //sys Utime(path string, buf *Utimbuf) (err error) 104 //sys utimes(path string, times *[2]Timeval) (err error) 105 106 //go:nosplit 107 func rawSetrlimit(resource int, rlim *Rlimit) Errno { 108 _, _, errno := RawSyscall(SYS_SETRLIMIT, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0) 109 return errno 110 } 111 112 func setTimespec(sec, nsec int64) Timespec { 113 return Timespec{Sec: sec, Nsec: nsec} 114 } 115 116 func setTimeval(sec, usec int64) Timeval { 117 return Timeval{Sec: sec, Usec: usec} 118 } 119 120 func (r *PtraceRegs) PC() uint64 { return r.Rip } 121 122 func (r *PtraceRegs) SetPC(pc uint64) { r.Rip = pc } 123 124 func (iov *Iovec) SetLen(length int) { 125 iov.Len = uint64(length) 126 } 127 128 func (msghdr *Msghdr) SetControllen(length int) { 129 msghdr.Controllen = uint64(length) 130 } 131 132 func (cmsg *Cmsghdr) SetLen(length int) { 133 cmsg.Len = uint64(length) 134 } 135