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

View as plain text