Source file src/syscall/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  package syscall
     6  
     7  import "unsafe"
     8  
     9  const _SYS_setgroups = SYS_SETGROUPS
    10  
    11  //sys	Dup2(oldfd int, newfd int) (err error)
    12  //sysnb	EpollCreate(size int) (fd int, err error)
    13  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
    14  //sys	Fchown(fd int, uid int, gid int) (err error)
    15  //sys	Fstat(fd int, stat *Stat_t) (err error)
    16  //sys	fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_NEWFSTATAT
    17  //sys	Fstatfs(fd int, buf *Statfs_t) (err error)
    18  //sys	Ftruncate(fd int, length int64) (err error)
    19  //sysnb	Getegid() (egid int)
    20  //sysnb	Geteuid() (euid int)
    21  //sysnb	Getgid() (gid int)
    22  //sysnb	Getrlimit(resource int, rlim *Rlimit) (err error) = SYS_GETRLIMIT
    23  //sysnb	Getuid() (uid int)
    24  //sysnb	InotifyInit() (fd int, err error)
    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) (err error)
    35  //sys	Setfsuid(uid int) (err error)
    36  //sysnb	Setrlimit(resource int, rlim *Rlimit) (err error)
    37  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
    38  //sys	Stat(path string, stat *Stat_t) (err error)
    39  //sys	Statfs(path string, buf *Statfs_t) (err error)
    40  //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error) = SYS_SYNC_FILE_RANGE
    41  //sys	Truncate(path string, length int64) (err error)
    42  //sys	Ustat(dev int, ubuf *Ustat_t) (err error)
    43  //sysnb	getgroups(n int, list *_Gid_t) (nn int, 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  // Linux on s390x uses the old mmap interface, which requires arguments to be passed in a struct.
    72  // mmap2 also requires arguments to be passed in a struct; it is currently not exposed in <asm/unistd.h>.
    73  func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
    74  	mmap_args := [6]uintptr{addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)}
    75  	r0, _, e1 := Syscall(SYS_MMAP, uintptr(unsafe.Pointer(&mmap_args[0])), 0, 0)
    76  	xaddr = uintptr(r0)
    77  	if e1 != 0 {
    78  		err = errnoErr(e1)
    79  	}
    80  	return
    81  }
    82  
    83  // On s390x Linux, all the socket calls go through an extra indirection.
    84  // The arguments to the underlying system call are the number below
    85  // and a pointer to an array of uintptr.  We hide the pointer in the
    86  // socketcall assembly to avoid allocation on every system call.
    87  
    88  const (
    89  	// see linux/net.h
    90  	_SOCKET      = 1
    91  	_BIND        = 2
    92  	_CONNECT     = 3
    93  	_LISTEN      = 4
    94  	_ACCEPT      = 5
    95  	_GETSOCKNAME = 6
    96  	_GETPEERNAME = 7
    97  	_SOCKETPAIR  = 8
    98  	_SEND        = 9
    99  	_RECV        = 10
   100  	_SENDTO      = 11
   101  	_RECVFROM    = 12
   102  	_SHUTDOWN    = 13
   103  	_SETSOCKOPT  = 14
   104  	_GETSOCKOPT  = 15
   105  	_SENDMSG     = 16
   106  	_RECVMSG     = 17
   107  	_ACCEPT4     = 18
   108  	_RECVMMSG    = 19
   109  	_SENDMMSG    = 20
   110  )
   111  
   112  func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err Errno)
   113  func rawsocketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err Errno)
   114  
   115  func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
   116  	fd, e := socketcall(_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
   117  	if e != 0 {
   118  		err = e
   119  	}
   120  	return
   121  }
   122  
   123  func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) {
   124  	_, e := rawsocketcall(_GETSOCKNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
   125  	if e != 0 {
   126  		err = e
   127  	}
   128  	return
   129  }
   130  
   131  func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) {
   132  	_, e := rawsocketcall(_GETPEERNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
   133  	if e != 0 {
   134  		err = e
   135  	}
   136  	return
   137  }
   138  
   139  func socketpair(domain int, typ int, flags int, fd *[2]int32) (err error) {
   140  	_, e := rawsocketcall(_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd)), 0, 0)
   141  	if e != 0 {
   142  		err = e
   143  	}
   144  	return
   145  }
   146  
   147  func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
   148  	_, e := socketcall(_BIND, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0)
   149  	if e != 0 {
   150  		err = e
   151  	}
   152  	return
   153  }
   154  
   155  func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
   156  	_, e := socketcall(_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0)
   157  	if e != 0 {
   158  		err = e
   159  	}
   160  	return
   161  }
   162  
   163  func socket(domain int, typ int, proto int) (fd int, err error) {
   164  	fd, e := rawsocketcall(_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto), 0, 0, 0)
   165  	if e != 0 {
   166  		err = e
   167  	}
   168  	return
   169  }
   170  
   171  func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) {
   172  	_, e := socketcall(_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0)
   173  	if e != 0 {
   174  		err = e
   175  	}
   176  	return
   177  }
   178  
   179  func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) {
   180  	_, e := socketcall(_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), vallen, 0)
   181  	if e != 0 {
   182  		err = e
   183  	}
   184  	return
   185  }
   186  
   187  func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) {
   188  	var base uintptr
   189  	if len(p) > 0 {
   190  		base = uintptr(unsafe.Pointer(&p[0]))
   191  	}
   192  	n, e := socketcall(_RECVFROM, uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)))
   193  	if e != 0 {
   194  		err = e
   195  	}
   196  	return
   197  }
   198  
   199  func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) {
   200  	var base uintptr
   201  	if len(p) > 0 {
   202  		base = uintptr(unsafe.Pointer(&p[0]))
   203  	}
   204  	_, e := socketcall(_SENDTO, uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen))
   205  	if e != 0 {
   206  		err = e
   207  	}
   208  	return
   209  }
   210  
   211  func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) {
   212  	n, e := socketcall(_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags), 0, 0, 0)
   213  	if e != 0 {
   214  		err = e
   215  	}
   216  	return
   217  }
   218  
   219  func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) {
   220  	n, e := socketcall(_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags), 0, 0, 0)
   221  	if e != 0 {
   222  		err = e
   223  	}
   224  	return
   225  }
   226  
   227  func Listen(s int, n int) (err error) {
   228  	_, e := socketcall(_LISTEN, uintptr(s), uintptr(n), 0, 0, 0, 0)
   229  	if e != 0 {
   230  		err = e
   231  	}
   232  	return
   233  }
   234  
   235  func Shutdown(s, how int) (err error) {
   236  	_, e := socketcall(_SHUTDOWN, uintptr(s), uintptr(how), 0, 0, 0, 0)
   237  	if e != 0 {
   238  		err = e
   239  	}
   240  	return
   241  }
   242  
   243  func (r *PtraceRegs) PC() uint64 { return r.Psw.Addr }
   244  
   245  func (r *PtraceRegs) SetPC(pc uint64) { r.Psw.Addr = pc }
   246  
   247  func (iov *Iovec) SetLen(length int) {
   248  	iov.Len = uint64(length)
   249  }
   250  
   251  func (msghdr *Msghdr) SetControllen(length int) {
   252  	msghdr.Controllen = uint64(length)
   253  }
   254  
   255  func (cmsg *Cmsghdr) SetLen(length int) {
   256  	cmsg.Len = uint64(length)
   257  }
   258  
   259  func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno)
   260  

View as plain text