golang.org/x/sys@v0.20.1-0.20240517151509-673e0f94c16d/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  //go:build s390x && linux
     6  
     7  package unix
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
    14  //sys	Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
    15  //sys	Fchown(fd int, uid int, gid int) (err error)
    16  //sys	Fstat(fd int, stat *Stat_t) (err error)
    17  //sys	Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_NEWFSTATAT
    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  //sys	Lchown(path string, uid int, gid int) (err error)
    26  //sys	Lstat(path string, stat *Stat_t) (err error)
    27  //sys	Pause() (err error)
    28  //sys	pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
    29  //sys	pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
    30  //sys	Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
    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) (prev int, err error)
    35  //sys	setfsuid(uid int) (prev int, err error)
    36  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
    37  //sys	Stat(path string, stat *Stat_t) (err error)
    38  //sys	Statfs(path string, buf *Statfs_t) (err error)
    39  //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error)
    40  //sys	Truncate(path string, length int64) (err error)
    41  //sys	Ustat(dev int, ubuf *Ustat_t) (err error)
    42  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
    43  //sysnb	setgroups(n int, list *_Gid_t) (err error)
    44  
    45  //sys	futimesat(dirfd int, path string, times *[2]Timeval) (err error)
    46  //sysnb	Gettimeofday(tv *Timeval) (err error)
    47  
    48  func Time(t *Time_t) (tt Time_t, err error) {
    49  	var tv Timeval
    50  	err = Gettimeofday(&tv)
    51  	if err != nil {
    52  		return 0, err
    53  	}
    54  	if t != nil {
    55  		*t = Time_t(tv.Sec)
    56  	}
    57  	return Time_t(tv.Sec), nil
    58  }
    59  
    60  //sys	Utime(path string, buf *Utimbuf) (err error)
    61  //sys	utimes(path string, times *[2]Timeval) (err error)
    62  
    63  func setTimespec(sec, nsec int64) Timespec {
    64  	return Timespec{Sec: sec, Nsec: nsec}
    65  }
    66  
    67  func setTimeval(sec, usec int64) Timeval {
    68  	return Timeval{Sec: sec, Usec: usec}
    69  }
    70  
    71  func Ioperm(from int, num int, on int) (err error) {
    72  	return ENOSYS
    73  }
    74  
    75  func Iopl(level int) (err error) {
    76  	return ENOSYS
    77  }
    78  
    79  func (r *PtraceRegs) PC() uint64 { return r.Psw.Addr }
    80  
    81  func (r *PtraceRegs) SetPC(pc uint64) { r.Psw.Addr = pc }
    82  
    83  func (iov *Iovec) SetLen(length int) {
    84  	iov.Len = uint64(length)
    85  }
    86  
    87  func (msghdr *Msghdr) SetControllen(length int) {
    88  	msghdr.Controllen = uint64(length)
    89  }
    90  
    91  func (msghdr *Msghdr) SetIovlen(length int) {
    92  	msghdr.Iovlen = uint64(length)
    93  }
    94  
    95  func (cmsg *Cmsghdr) SetLen(length int) {
    96  	cmsg.Len = uint64(length)
    97  }
    98  
    99  func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
   100  	rsa.Service_name_len = uint64(length)
   101  }
   102  
   103  // Linux on s390x uses the old mmap interface, which requires arguments to be passed in a struct.
   104  // mmap2 also requires arguments to be passed in a struct; it is currently not exposed in <asm/unistd.h>.
   105  func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
   106  	mmap_args := [6]uintptr{addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)}
   107  	r0, _, e1 := Syscall(SYS_MMAP, uintptr(unsafe.Pointer(&mmap_args[0])), 0, 0)
   108  	xaddr = uintptr(r0)
   109  	if e1 != 0 {
   110  		err = errnoErr(e1)
   111  	}
   112  	return
   113  }
   114  
   115  // On s390x Linux, all the socket calls go through an extra indirection.
   116  // The arguments to the underlying system call (SYS_SOCKETCALL) are the
   117  // number below and a pointer to an array of uintptr.
   118  const (
   119  	// see linux/net.h
   120  	netSocket      = 1
   121  	netBind        = 2
   122  	netConnect     = 3
   123  	netListen      = 4
   124  	netAccept      = 5
   125  	netGetSockName = 6
   126  	netGetPeerName = 7
   127  	netSocketPair  = 8
   128  	netSend        = 9
   129  	netRecv        = 10
   130  	netSendTo      = 11
   131  	netRecvFrom    = 12
   132  	netShutdown    = 13
   133  	netSetSockOpt  = 14
   134  	netGetSockOpt  = 15
   135  	netSendMsg     = 16
   136  	netRecvMsg     = 17
   137  	netAccept4     = 18
   138  	netRecvMMsg    = 19
   139  	netSendMMsg    = 20
   140  )
   141  
   142  func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) {
   143  	args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)}
   144  	fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0)
   145  	if err != 0 {
   146  		return 0, err
   147  	}
   148  	return int(fd), nil
   149  }
   150  
   151  func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
   152  	args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
   153  	_, _, err := RawSyscall(SYS_SOCKETCALL, netGetSockName, uintptr(unsafe.Pointer(&args)), 0)
   154  	if err != 0 {
   155  		return err
   156  	}
   157  	return nil
   158  }
   159  
   160  func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
   161  	args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
   162  	_, _, err := RawSyscall(SYS_SOCKETCALL, netGetPeerName, uintptr(unsafe.Pointer(&args)), 0)
   163  	if err != 0 {
   164  		return err
   165  	}
   166  	return nil
   167  }
   168  
   169  func socketpair(domain int, typ int, flags int, fd *[2]int32) error {
   170  	args := [4]uintptr{uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd))}
   171  	_, _, err := RawSyscall(SYS_SOCKETCALL, netSocketPair, uintptr(unsafe.Pointer(&args)), 0)
   172  	if err != 0 {
   173  		return err
   174  	}
   175  	return nil
   176  }
   177  
   178  func bind(s int, addr unsafe.Pointer, addrlen _Socklen) error {
   179  	args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
   180  	_, _, err := Syscall(SYS_SOCKETCALL, netBind, uintptr(unsafe.Pointer(&args)), 0)
   181  	if err != 0 {
   182  		return err
   183  	}
   184  	return nil
   185  }
   186  
   187  func connect(s int, addr unsafe.Pointer, addrlen _Socklen) error {
   188  	args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
   189  	_, _, err := Syscall(SYS_SOCKETCALL, netConnect, uintptr(unsafe.Pointer(&args)), 0)
   190  	if err != 0 {
   191  		return err
   192  	}
   193  	return nil
   194  }
   195  
   196  func socket(domain int, typ int, proto int) (int, error) {
   197  	args := [3]uintptr{uintptr(domain), uintptr(typ), uintptr(proto)}
   198  	fd, _, err := RawSyscall(SYS_SOCKETCALL, netSocket, uintptr(unsafe.Pointer(&args)), 0)
   199  	if err != 0 {
   200  		return 0, err
   201  	}
   202  	return int(fd), nil
   203  }
   204  
   205  func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) error {
   206  	args := [5]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen))}
   207  	_, _, err := Syscall(SYS_SOCKETCALL, netGetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
   208  	if err != 0 {
   209  		return err
   210  	}
   211  	return nil
   212  }
   213  
   214  func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) error {
   215  	args := [5]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val), vallen}
   216  	_, _, err := Syscall(SYS_SOCKETCALL, netSetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
   217  	if err != 0 {
   218  		return err
   219  	}
   220  	return nil
   221  }
   222  
   223  func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (int, error) {
   224  	var base uintptr
   225  	if len(p) > 0 {
   226  		base = uintptr(unsafe.Pointer(&p[0]))
   227  	}
   228  	args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))}
   229  	n, _, err := Syscall(SYS_SOCKETCALL, netRecvFrom, uintptr(unsafe.Pointer(&args)), 0)
   230  	if err != 0 {
   231  		return 0, err
   232  	}
   233  	return int(n), nil
   234  }
   235  
   236  func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) error {
   237  	var base uintptr
   238  	if len(p) > 0 {
   239  		base = uintptr(unsafe.Pointer(&p[0]))
   240  	}
   241  	args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen)}
   242  	_, _, err := Syscall(SYS_SOCKETCALL, netSendTo, uintptr(unsafe.Pointer(&args)), 0)
   243  	if err != 0 {
   244  		return err
   245  	}
   246  	return nil
   247  }
   248  
   249  func recvmsg(s int, msg *Msghdr, flags int) (int, error) {
   250  	args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
   251  	n, _, err := Syscall(SYS_SOCKETCALL, netRecvMsg, uintptr(unsafe.Pointer(&args)), 0)
   252  	if err != 0 {
   253  		return 0, err
   254  	}
   255  	return int(n), nil
   256  }
   257  
   258  func sendmsg(s int, msg *Msghdr, flags int) (int, error) {
   259  	args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
   260  	n, _, err := Syscall(SYS_SOCKETCALL, netSendMsg, uintptr(unsafe.Pointer(&args)), 0)
   261  	if err != 0 {
   262  		return 0, err
   263  	}
   264  	return int(n), nil
   265  }
   266  
   267  func Listen(s int, n int) error {
   268  	args := [2]uintptr{uintptr(s), uintptr(n)}
   269  	_, _, err := Syscall(SYS_SOCKETCALL, netListen, uintptr(unsafe.Pointer(&args)), 0)
   270  	if err != 0 {
   271  		return err
   272  	}
   273  	return nil
   274  }
   275  
   276  func Shutdown(s, how int) error {
   277  	args := [2]uintptr{uintptr(s), uintptr(how)}
   278  	_, _, err := Syscall(SYS_SOCKETCALL, netShutdown, uintptr(unsafe.Pointer(&args)), 0)
   279  	if err != 0 {
   280  		return err
   281  	}
   282  	return nil
   283  }
   284  
   285  //sys	kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
   286  
   287  func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
   288  	cmdlineLen := len(cmdline)
   289  	if cmdlineLen > 0 {
   290  		// Account for the additional NULL byte added by
   291  		// BytePtrFromString in kexecFileLoad. The kexec_file_load
   292  		// syscall expects a NULL-terminated string.
   293  		cmdlineLen++
   294  	}
   295  	return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
   296  }