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