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 //sysnb EpollCreate(size int) (fd int, err error)
15 //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
16 //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
17 //sys Fchown(fd int, uid int, gid int) (err error)
18 //sys Fstat(fd int, stat *Stat_t) (err error)
19 //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_NEWFSTATAT
20 //sys Fstatfs(fd int, buf *Statfs_t) (err error)
21 //sys Ftruncate(fd int, length int64) (err error)
22 //sysnb Getegid() (egid int)
23 //sysnb Geteuid() (euid int)
24 //sysnb Getgid() (gid int)
25 //sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
26 //sysnb Getuid() (uid int)
27 //sysnb InotifyInit() (fd int, err error)
28 //sys Lchown(path string, uid int, gid int) (err error)
29 //sys Lstat(path string, stat *Stat_t) (err error)
30 //sys Pause() (err error)
31 //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
32 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
33 //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
34 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
35 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
36 //sys Setfsgid(gid int) (err error)
37 //sys Setfsuid(uid int) (err error)
38 //sysnb Setregid(rgid int, egid int) (err error)
39 //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
40 //sysnb Setresuid(ruid int, euid int, suid int) (err error)
41 //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
42 //sysnb Setreuid(ruid int, euid int) (err error)
43 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
44 //sys Stat(path string, stat *Stat_t) (err error)
45 //sys Statfs(path string, buf *Statfs_t) (err error)
46 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
47 //sys Truncate(path string, length int64) (err error)
48 //sys Ustat(dev int, ubuf *Ustat_t) (err error)
49 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
50 //sysnb setgroups(n int, list *_Gid_t) (err error)
52 //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error)
53 //sysnb Gettimeofday(tv *Timeval) (err error)
55 func Time(t *Time_t) (tt Time_t, err error) {
57 err = Gettimeofday(&tv)
64 return Time_t(tv.Sec), nil
67 //sys Utime(path string, buf *Utimbuf) (err error)
68 //sys utimes(path string, times *[2]Timeval) (err error)
70 func setTimespec(sec, nsec int64) Timespec {
71 return Timespec{Sec: sec, Nsec: nsec}
74 func setTimeval(sec, usec int64) Timeval {
75 return Timeval{Sec: sec, Usec: usec}
78 //sysnb pipe2(p *[2]_C_int, flags int) (err error)
80 func Pipe(p []int) (err error) {
85 err = pipe2(&pp, 0) // pipe2 is the same as pipe when flags are set to 0.
91 func Pipe2(p []int, flags int) (err error) {
96 err = pipe2(&pp, flags)
102 func Ioperm(from int, num int, on int) (err error) {
106 func Iopl(level int) (err error) {
110 func (r *PtraceRegs) PC() uint64 { return r.Psw.Addr }
112 func (r *PtraceRegs) SetPC(pc uint64) { r.Psw.Addr = pc }
114 func (iov *Iovec) SetLen(length int) {
115 iov.Len = uint64(length)
118 func (msghdr *Msghdr) SetControllen(length int) {
119 msghdr.Controllen = uint64(length)
122 func (cmsg *Cmsghdr) SetLen(length int) {
123 cmsg.Len = uint64(length)
126 // Linux on s390x uses the old mmap interface, which requires arguments to be passed in a struct.
127 // mmap2 also requires arguments to be passed in a struct; it is currently not exposed in <asm/unistd.h>.
128 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
129 mmap_args := [6]uintptr{addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)}
130 r0, _, e1 := Syscall(SYS_MMAP, uintptr(unsafe.Pointer(&mmap_args[0])), 0, 0)
138 // On s390x Linux, all the socket calls go through an extra indirection.
139 // The arguments to the underlying system call (SYS_SOCKETCALL) are the
140 // number below and a pointer to an array of uintptr.
165 func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (int, error) {
166 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
167 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept, uintptr(unsafe.Pointer(&args)), 0)
174 func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) {
175 args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)}
176 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0)
183 func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
184 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
185 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetSockName, uintptr(unsafe.Pointer(&args)), 0)
192 func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
193 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
194 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetPeerName, uintptr(unsafe.Pointer(&args)), 0)
201 func socketpair(domain int, typ int, flags int, fd *[2]int32) error {
202 args := [4]uintptr{uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd))}
203 _, _, err := RawSyscall(SYS_SOCKETCALL, netSocketPair, uintptr(unsafe.Pointer(&args)), 0)
210 func bind(s int, addr unsafe.Pointer, addrlen _Socklen) error {
211 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
212 _, _, err := Syscall(SYS_SOCKETCALL, netBind, uintptr(unsafe.Pointer(&args)), 0)
219 func connect(s int, addr unsafe.Pointer, addrlen _Socklen) error {
220 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
221 _, _, err := Syscall(SYS_SOCKETCALL, netConnect, uintptr(unsafe.Pointer(&args)), 0)
228 func socket(domain int, typ int, proto int) (int, error) {
229 args := [3]uintptr{uintptr(domain), uintptr(typ), uintptr(proto)}
230 fd, _, err := RawSyscall(SYS_SOCKETCALL, netSocket, uintptr(unsafe.Pointer(&args)), 0)
237 func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) error {
238 args := [5]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen))}
239 _, _, err := Syscall(SYS_SOCKETCALL, netGetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
246 func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) error {
247 args := [4]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val)}
248 _, _, err := Syscall(SYS_SOCKETCALL, netSetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
255 func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (int, error) {
258 base = uintptr(unsafe.Pointer(&p[0]))
260 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))}
261 n, _, err := Syscall(SYS_SOCKETCALL, netRecvFrom, uintptr(unsafe.Pointer(&args)), 0)
268 func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) error {
271 base = uintptr(unsafe.Pointer(&p[0]))
273 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen)}
274 _, _, err := Syscall(SYS_SOCKETCALL, netSendTo, uintptr(unsafe.Pointer(&args)), 0)
281 func recvmsg(s int, msg *Msghdr, flags int) (int, error) {
282 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
283 n, _, err := Syscall(SYS_SOCKETCALL, netRecvMsg, uintptr(unsafe.Pointer(&args)), 0)
290 func sendmsg(s int, msg *Msghdr, flags int) (int, error) {
291 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
292 n, _, err := Syscall(SYS_SOCKETCALL, netSendMsg, uintptr(unsafe.Pointer(&args)), 0)
299 func Listen(s int, n int) error {
300 args := [2]uintptr{uintptr(s), uintptr(n)}
301 _, _, err := Syscall(SYS_SOCKETCALL, netListen, uintptr(unsafe.Pointer(&args)), 0)
308 func Shutdown(s, how int) error {
309 args := [2]uintptr{uintptr(s), uintptr(how)}
310 _, _, err := Syscall(SYS_SOCKETCALL, netShutdown, uintptr(unsafe.Pointer(&args)), 0)
317 //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error)
319 func Poll(fds []PollFd, timeout int) (n int, err error) {
321 return poll(nil, 0, timeout)
323 return poll(&fds[0], len(fds), timeout)
326 //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
328 func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
329 cmdlineLen := len(cmdline)
331 // Account for the additional NULL byte added by
332 // BytePtrFromString in kexecFileLoad. The kexec_file_load
333 // syscall expects a NULL-terminated string.
336 return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)