1 // Copyright 2016 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.
13 //sys Dup2(oldfd int, newfd int) (err error)
14 //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
15 //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
16 //sys Fchown(fd int, uid int, gid int) (err error)
17 //sys Fstat(fd int, stat *Stat_t) (err error)
18 //sys Fstatfs(fd int, buf *Statfs_t) (err error)
19 //sys Ftruncate(fd int, length int64) (err error)
20 //sysnb Getegid() (egid int)
21 //sysnb Geteuid() (euid int)
22 //sysnb Getgid() (gid int)
23 //sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
24 //sysnb Getuid() (uid int)
25 //sysnb InotifyInit() (fd int, err error)
26 //sys Lchown(path string, uid int, gid int) (err error)
27 //sys Lstat(path string, stat *Stat_t) (err error)
28 //sys Pause() (err error)
29 //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
30 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
31 //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
32 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
33 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
34 //sys Setfsgid(gid int) (err error)
35 //sys Setfsuid(uid int) (err error)
36 //sysnb Setregid(rgid int, egid int) (err error)
37 //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
38 //sysnb Setresuid(ruid int, euid int, suid int) (err error)
39 //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
40 //sysnb Setreuid(ruid int, euid int) (err error)
41 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
42 //sys Stat(path string, stat *Stat_t) (err error)
43 //sys Statfs(path string, buf *Statfs_t) (err error)
44 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
45 //sys Truncate(path string, length int64) (err error)
46 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
47 //sysnb setgroups(n int, list *_Gid_t) (err error)
49 func Getpagesize() int { return 4096 }
51 //sysnb Gettimeofday(tv *Timeval) (err error)
53 func Time(t *Time_t) (tt Time_t, err error) {
55 err = Gettimeofday(&tv)
62 return Time_t(tv.Sec), nil
65 //sys Utime(path string, buf *Utimbuf) (err error)
67 func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
69 func NsecToTimespec(nsec int64) (ts Timespec) {
75 func NsecToTimeval(nsec int64) (tv Timeval) {
76 nsec += 999 // round up to microsecond
78 tv.Usec = nsec % 1e9 / 1e3
82 //sysnb pipe2(p *[2]_C_int, flags int) (err error)
84 func Pipe(p []int) (err error) {
89 err = pipe2(&pp, 0) // pipe2 is the same as pipe when flags are set to 0.
95 func Pipe2(p []int, flags int) (err error) {
100 err = pipe2(&pp, flags)
106 func Ioperm(from int, num int, on int) (err error) {
110 func Iopl(level int) (err error) {
114 func (r *PtraceRegs) PC() uint64 { return r.Psw.Addr }
116 func (r *PtraceRegs) SetPC(pc uint64) { r.Psw.Addr = pc }
118 func (iov *Iovec) SetLen(length int) {
119 iov.Len = uint64(length)
122 func (msghdr *Msghdr) SetControllen(length int) {
123 msghdr.Controllen = uint64(length)
126 func (cmsg *Cmsghdr) SetLen(length int) {
127 cmsg.Len = uint64(length)
130 // Linux on s390x uses the old mmap interface, which requires arguments to be passed in a struct.
131 // mmap2 also requires arguments to be passed in a struct; it is currently not exposed in <asm/unistd.h>.
132 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
133 mmap_args := [6]uintptr{addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)}
134 r0, _, e1 := Syscall(SYS_MMAP, uintptr(unsafe.Pointer(&mmap_args[0])), 0, 0)
142 // On s390x Linux, all the socket calls go through an extra indirection.
143 // The arguments to the underlying system call (SYS_SOCKETCALL) are the
144 // number below and a pointer to an array of uintptr.
169 func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (int, error) {
170 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
171 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept, uintptr(unsafe.Pointer(&args)), 0)
178 func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) {
179 args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)}
180 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0)
187 func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
188 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
189 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetSockName, uintptr(unsafe.Pointer(&args)), 0)
196 func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
197 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
198 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetPeerName, uintptr(unsafe.Pointer(&args)), 0)
205 func socketpair(domain int, typ int, flags int, fd *[2]int32) error {
206 args := [4]uintptr{uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd))}
207 _, _, err := RawSyscall(SYS_SOCKETCALL, netSocketPair, uintptr(unsafe.Pointer(&args)), 0)
214 func bind(s int, addr unsafe.Pointer, addrlen _Socklen) error {
215 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
216 _, _, err := Syscall(SYS_SOCKETCALL, netBind, uintptr(unsafe.Pointer(&args)), 0)
223 func connect(s int, addr unsafe.Pointer, addrlen _Socklen) error {
224 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
225 _, _, err := Syscall(SYS_SOCKETCALL, netConnect, uintptr(unsafe.Pointer(&args)), 0)
232 func socket(domain int, typ int, proto int) (int, error) {
233 args := [3]uintptr{uintptr(domain), uintptr(typ), uintptr(proto)}
234 fd, _, err := RawSyscall(SYS_SOCKETCALL, netSocket, uintptr(unsafe.Pointer(&args)), 0)
241 func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) error {
242 args := [5]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen))}
243 _, _, err := Syscall(SYS_SOCKETCALL, netGetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
250 func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) error {
251 args := [4]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val)}
252 _, _, err := Syscall(SYS_SOCKETCALL, netSetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
259 func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (int, error) {
262 base = uintptr(unsafe.Pointer(&p[0]))
264 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))}
265 n, _, err := Syscall(SYS_SOCKETCALL, netRecvFrom, uintptr(unsafe.Pointer(&args)), 0)
272 func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) error {
275 base = uintptr(unsafe.Pointer(&p[0]))
277 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen)}
278 _, _, err := Syscall(SYS_SOCKETCALL, netSendTo, uintptr(unsafe.Pointer(&args)), 0)
285 func recvmsg(s int, msg *Msghdr, flags int) (int, error) {
286 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
287 n, _, err := Syscall(SYS_SOCKETCALL, netRecvMsg, uintptr(unsafe.Pointer(&args)), 0)
294 func sendmsg(s int, msg *Msghdr, flags int) (int, error) {
295 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
296 n, _, err := Syscall(SYS_SOCKETCALL, netSendMsg, uintptr(unsafe.Pointer(&args)), 0)
303 func Listen(s int, n int) error {
304 args := [2]uintptr{uintptr(s), uintptr(n)}
305 _, _, err := Syscall(SYS_SOCKETCALL, netListen, uintptr(unsafe.Pointer(&args)), 0)
312 func Shutdown(s, how int) error {
313 args := [2]uintptr{uintptr(s), uintptr(how)}
314 _, _, err := Syscall(SYS_SOCKETCALL, netShutdown, uintptr(unsafe.Pointer(&args)), 0)
321 //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error)
323 func Poll(fds []PollFd, timeout int) (n int, err error) {
325 return poll(nil, 0, timeout)
327 return poll(&fds[0], len(fds), timeout)