github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/sys/unix/syscall_linux_s390x.go (about) 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. 4 5 // +build s390x,linux 6 7 package unix 8 9 import ( 10 "unsafe" 11 ) 12 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 Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) 34 //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK 35 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) 36 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) 37 //sys Setfsgid(gid int) (err error) 38 //sys Setfsuid(uid int) (err error) 39 //sysnb Setregid(rgid int, egid int) (err error) 40 //sysnb Setresgid(rgid int, egid int, sgid int) (err error) 41 //sysnb Setresuid(ruid int, euid int, suid int) (err error) 42 //sysnb Setrlimit(resource int, rlim *Rlimit) (err error) 43 //sysnb Setreuid(ruid int, euid int) (err error) 44 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) 45 //sys Stat(path string, stat *Stat_t) (err error) 46 //sys Statfs(path string, buf *Statfs_t) (err error) 47 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) 48 //sys Truncate(path string, length int64) (err error) 49 //sys Ustat(dev int, ubuf *Ustat_t) (err error) 50 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) 51 //sysnb setgroups(n int, list *_Gid_t) (err error) 52 53 //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error) 54 //sysnb Gettimeofday(tv *Timeval) (err error) 55 56 func Time(t *Time_t) (tt Time_t, err error) { 57 var tv Timeval 58 err = Gettimeofday(&tv) 59 if err != nil { 60 return 0, err 61 } 62 if t != nil { 63 *t = Time_t(tv.Sec) 64 } 65 return Time_t(tv.Sec), nil 66 } 67 68 //sys Utime(path string, buf *Utimbuf) (err error) 69 //sys utimes(path string, times *[2]Timeval) (err error) 70 71 func setTimespec(sec, nsec int64) Timespec { 72 return Timespec{Sec: sec, Nsec: nsec} 73 } 74 75 func setTimeval(sec, usec int64) Timeval { 76 return Timeval{Sec: sec, Usec: usec} 77 } 78 79 //sysnb pipe2(p *[2]_C_int, flags int) (err error) 80 81 func Pipe(p []int) (err error) { 82 if len(p) != 2 { 83 return EINVAL 84 } 85 var pp [2]_C_int 86 err = pipe2(&pp, 0) // pipe2 is the same as pipe when flags are set to 0. 87 p[0] = int(pp[0]) 88 p[1] = int(pp[1]) 89 return 90 } 91 92 func Pipe2(p []int, flags int) (err error) { 93 if len(p) != 2 { 94 return EINVAL 95 } 96 var pp [2]_C_int 97 err = pipe2(&pp, flags) 98 p[0] = int(pp[0]) 99 p[1] = int(pp[1]) 100 return 101 } 102 103 func Ioperm(from int, num int, on int) (err error) { 104 return ENOSYS 105 } 106 107 func Iopl(level int) (err error) { 108 return ENOSYS 109 } 110 111 func (r *PtraceRegs) PC() uint64 { return r.Psw.Addr } 112 113 func (r *PtraceRegs) SetPC(pc uint64) { r.Psw.Addr = pc } 114 115 func (iov *Iovec) SetLen(length int) { 116 iov.Len = uint64(length) 117 } 118 119 func (msghdr *Msghdr) SetControllen(length int) { 120 msghdr.Controllen = uint64(length) 121 } 122 123 func (msghdr *Msghdr) SetIovlen(length int) { 124 msghdr.Iovlen = uint64(length) 125 } 126 127 func (cmsg *Cmsghdr) SetLen(length int) { 128 cmsg.Len = uint64(length) 129 } 130 131 // Linux on s390x uses the old mmap interface, which requires arguments to be passed in a struct. 132 // mmap2 also requires arguments to be passed in a struct; it is currently not exposed in <asm/unistd.h>. 133 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) { 134 mmap_args := [6]uintptr{addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)} 135 r0, _, e1 := Syscall(SYS_MMAP, uintptr(unsafe.Pointer(&mmap_args[0])), 0, 0) 136 xaddr = uintptr(r0) 137 if e1 != 0 { 138 err = errnoErr(e1) 139 } 140 return 141 } 142 143 // On s390x Linux, all the socket calls go through an extra indirection. 144 // The arguments to the underlying system call (SYS_SOCKETCALL) are the 145 // number below and a pointer to an array of uintptr. 146 const ( 147 // see linux/net.h 148 netSocket = 1 149 netBind = 2 150 netConnect = 3 151 netListen = 4 152 netAccept = 5 153 netGetSockName = 6 154 netGetPeerName = 7 155 netSocketPair = 8 156 netSend = 9 157 netRecv = 10 158 netSendTo = 11 159 netRecvFrom = 12 160 netShutdown = 13 161 netSetSockOpt = 14 162 netGetSockOpt = 15 163 netSendMsg = 16 164 netRecvMsg = 17 165 netAccept4 = 18 166 netRecvMMsg = 19 167 netSendMMsg = 20 168 ) 169 170 func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (int, error) { 171 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))} 172 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept, uintptr(unsafe.Pointer(&args)), 0) 173 if err != 0 { 174 return 0, err 175 } 176 return int(fd), nil 177 } 178 179 func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) { 180 args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)} 181 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0) 182 if err != 0 { 183 return 0, err 184 } 185 return int(fd), nil 186 } 187 188 func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error { 189 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))} 190 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetSockName, uintptr(unsafe.Pointer(&args)), 0) 191 if err != 0 { 192 return err 193 } 194 return nil 195 } 196 197 func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error { 198 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))} 199 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetPeerName, uintptr(unsafe.Pointer(&args)), 0) 200 if err != 0 { 201 return err 202 } 203 return nil 204 } 205 206 func socketpair(domain int, typ int, flags int, fd *[2]int32) error { 207 args := [4]uintptr{uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd))} 208 _, _, err := RawSyscall(SYS_SOCKETCALL, netSocketPair, uintptr(unsafe.Pointer(&args)), 0) 209 if err != 0 { 210 return err 211 } 212 return nil 213 } 214 215 func bind(s int, addr unsafe.Pointer, addrlen _Socklen) error { 216 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)} 217 _, _, err := Syscall(SYS_SOCKETCALL, netBind, uintptr(unsafe.Pointer(&args)), 0) 218 if err != 0 { 219 return err 220 } 221 return nil 222 } 223 224 func connect(s int, addr unsafe.Pointer, addrlen _Socklen) error { 225 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)} 226 _, _, err := Syscall(SYS_SOCKETCALL, netConnect, uintptr(unsafe.Pointer(&args)), 0) 227 if err != 0 { 228 return err 229 } 230 return nil 231 } 232 233 func socket(domain int, typ int, proto int) (int, error) { 234 args := [3]uintptr{uintptr(domain), uintptr(typ), uintptr(proto)} 235 fd, _, err := RawSyscall(SYS_SOCKETCALL, netSocket, uintptr(unsafe.Pointer(&args)), 0) 236 if err != 0 { 237 return 0, err 238 } 239 return int(fd), nil 240 } 241 242 func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) error { 243 args := [5]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen))} 244 _, _, err := Syscall(SYS_SOCKETCALL, netGetSockOpt, uintptr(unsafe.Pointer(&args)), 0) 245 if err != 0 { 246 return err 247 } 248 return nil 249 } 250 251 func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) error { 252 args := [4]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val)} 253 _, _, err := Syscall(SYS_SOCKETCALL, netSetSockOpt, uintptr(unsafe.Pointer(&args)), 0) 254 if err != 0 { 255 return err 256 } 257 return nil 258 } 259 260 func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (int, error) { 261 var base uintptr 262 if len(p) > 0 { 263 base = uintptr(unsafe.Pointer(&p[0])) 264 } 265 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))} 266 n, _, err := Syscall(SYS_SOCKETCALL, netRecvFrom, uintptr(unsafe.Pointer(&args)), 0) 267 if err != 0 { 268 return 0, err 269 } 270 return int(n), nil 271 } 272 273 func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) error { 274 var base uintptr 275 if len(p) > 0 { 276 base = uintptr(unsafe.Pointer(&p[0])) 277 } 278 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen)} 279 _, _, err := Syscall(SYS_SOCKETCALL, netSendTo, uintptr(unsafe.Pointer(&args)), 0) 280 if err != 0 { 281 return err 282 } 283 return nil 284 } 285 286 func recvmsg(s int, msg *Msghdr, flags int) (int, error) { 287 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)} 288 n, _, err := Syscall(SYS_SOCKETCALL, netRecvMsg, uintptr(unsafe.Pointer(&args)), 0) 289 if err != 0 { 290 return 0, err 291 } 292 return int(n), nil 293 } 294 295 func sendmsg(s int, msg *Msghdr, flags int) (int, error) { 296 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)} 297 n, _, err := Syscall(SYS_SOCKETCALL, netSendMsg, uintptr(unsafe.Pointer(&args)), 0) 298 if err != 0 { 299 return 0, err 300 } 301 return int(n), nil 302 } 303 304 func Listen(s int, n int) error { 305 args := [2]uintptr{uintptr(s), uintptr(n)} 306 _, _, err := Syscall(SYS_SOCKETCALL, netListen, uintptr(unsafe.Pointer(&args)), 0) 307 if err != 0 { 308 return err 309 } 310 return nil 311 } 312 313 func Shutdown(s, how int) error { 314 args := [2]uintptr{uintptr(s), uintptr(how)} 315 _, _, err := Syscall(SYS_SOCKETCALL, netShutdown, uintptr(unsafe.Pointer(&args)), 0) 316 if err != 0 { 317 return err 318 } 319 return nil 320 } 321 322 //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) 323 324 func Poll(fds []PollFd, timeout int) (n int, err error) { 325 if len(fds) == 0 { 326 return poll(nil, 0, timeout) 327 } 328 return poll(&fds[0], len(fds), timeout) 329 } 330 331 //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error) 332 333 func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error { 334 cmdlineLen := len(cmdline) 335 if cmdlineLen > 0 { 336 // Account for the additional NULL byte added by 337 // BytePtrFromString in kexecFileLoad. The kexec_file_load 338 // syscall expects a NULL-terminated string. 339 cmdlineLen++ 340 } 341 return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags) 342 }