Black Lives Matter. Support the Equal Justice Initiative.

Source file src/syscall/syscall_linux_s390x.go

Documentation: syscall

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

View as plain text