Source file src/cmd/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go

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

View as plain text