Black Lives Matter. Support the Equal Justice Initiative.

Source file src/syscall/syscall_linux_riscv64.go

Documentation: syscall

     1  // Copyright 2019 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  func EpollCreate(size int) (fd int, err error) {
    12  	if size <= 0 {
    13  		return -1, EINVAL
    14  	}
    15  	return EpollCreate1(0)
    16  }
    17  
    18  //sys	EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
    19  //sys	Fchown(fd int, uid int, gid int) (err error)
    20  //sys	Fstat(fd int, stat *Stat_t) (err error)
    21  //sys	Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
    22  //sys	fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error)
    23  //sys	Fstatfs(fd int, buf *Statfs_t) (err error)
    24  //sys	Ftruncate(fd int, length int64) (err error)
    25  //sysnb	Getegid() (egid int)
    26  //sysnb	Geteuid() (euid int)
    27  //sysnb	Getgid() (gid int)
    28  //sysnb	Getrlimit(resource int, rlim *Rlimit) (err error)
    29  //sysnb	Getuid() (uid int)
    30  //sys	Listen(s int, n int) (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	renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error)
    34  //sys	Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
    35  //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
    36  //sys	Setfsgid(gid int) (err error)
    37  //sys	Setfsuid(uid int) (err error)
    38  //sysnb	Setregid(rgid int, egid int) (err error)
    39  //sysnb	Setresgid(rgid int, egid int, sgid int) (err error)
    40  //sysnb	Setresuid(ruid int, euid int, suid int) (err error)
    41  //sysnb	Setrlimit(resource int, rlim *Rlimit) (err error)
    42  //sysnb	Setreuid(ruid int, euid int) (err error)
    43  //sys	Shutdown(fd int, how int) (err error)
    44  //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
    45  
    46  func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
    47  	return renameat2(olddirfd, oldpath, newdirfd, newpath, 0)
    48  }
    49  
    50  func Stat(path string, stat *Stat_t) (err error) {
    51  	return Fstatat(_AT_FDCWD, path, stat, 0)
    52  }
    53  
    54  func Lchown(path string, uid int, gid int) (err error) {
    55  	return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
    56  }
    57  
    58  func Lstat(path string, stat *Stat_t) (err error) {
    59  	return Fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
    60  }
    61  
    62  //sys	Statfs(path string, buf *Statfs_t) (err error)
    63  //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error)
    64  //sys	Truncate(path string, length int64) (err error)
    65  //sys	accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
    66  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
    67  //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    68  //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
    69  //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
    70  //sysnb	setgroups(n int, list *_Gid_t) (err error)
    71  //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
    72  //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
    73  //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
    74  //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
    75  //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    76  //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
    77  //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
    78  //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
    79  //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
    80  //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
    81  //sys	mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
    82  
    83  type sigset_t struct {
    84  	X__val [16]uint64
    85  }
    86  
    87  //sys	pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_t) (n int, err error) = SYS_PSELECT6
    88  
    89  func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
    90  	var ts *Timespec
    91  	if timeout != nil {
    92  		ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
    93  	}
    94  	return pselect(nfd, r, w, e, ts, nil)
    95  }
    96  
    97  //sysnb	Gettimeofday(tv *Timeval) (err error)
    98  
    99  func setTimespec(sec, nsec int64) Timespec {
   100  	return Timespec{Sec: sec, Nsec: nsec}
   101  }
   102  
   103  func setTimeval(sec, usec int64) Timeval {
   104  	return Timeval{Sec: sec, Usec: usec}
   105  }
   106  
   107  func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
   108  	if tv == nil {
   109  		return utimensat(dirfd, path, nil, 0)
   110  	}
   111  
   112  	ts := []Timespec{
   113  		NsecToTimespec(TimevalToNsec(tv[0])),
   114  		NsecToTimespec(TimevalToNsec(tv[1])),
   115  	}
   116  	return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
   117  }
   118  
   119  func Time(t *Time_t) (Time_t, error) {
   120  	var tv Timeval
   121  	err := Gettimeofday(&tv)
   122  	if err != nil {
   123  		return 0, err
   124  	}
   125  	if t != nil {
   126  		*t = Time_t(tv.Sec)
   127  	}
   128  	return Time_t(tv.Sec), nil
   129  }
   130  
   131  func Utime(path string, buf *Utimbuf) error {
   132  	tv := []Timeval{
   133  		{Sec: buf.Actime},
   134  		{Sec: buf.Modtime},
   135  	}
   136  	return Utimes(path, tv)
   137  }
   138  
   139  func utimes(path string, tv *[2]Timeval) (err error) {
   140  	if tv == nil {
   141  		return utimensat(_AT_FDCWD, path, nil, 0)
   142  	}
   143  
   144  	ts := []Timespec{
   145  		NsecToTimespec(TimevalToNsec(tv[0])),
   146  		NsecToTimespec(TimevalToNsec(tv[1])),
   147  	}
   148  	return utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
   149  }
   150  
   151  func Pipe(p []int) (err error) {
   152  	if len(p) != 2 {
   153  		return EINVAL
   154  	}
   155  	var pp [2]_C_int
   156  	err = pipe2(&pp, 0)
   157  	p[0] = int(pp[0])
   158  	p[1] = int(pp[1])
   159  	return
   160  }
   161  
   162  //sysnb pipe2(p *[2]_C_int, flags int) (err error)
   163  
   164  func Pipe2(p []int, flags int) (err error) {
   165  	if len(p) != 2 {
   166  		return EINVAL
   167  	}
   168  	var pp [2]_C_int
   169  	err = pipe2(&pp, flags)
   170  	p[0] = int(pp[0])
   171  	p[1] = int(pp[1])
   172  	return
   173  }
   174  
   175  func (r *PtraceRegs) PC() uint64 { return r.Pc }
   176  
   177  func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
   178  
   179  func (iov *Iovec) SetLen(length int) {
   180  	iov.Len = uint64(length)
   181  }
   182  
   183  func (msghdr *Msghdr) SetControllen(length int) {
   184  	msghdr.Controllen = uint64(length)
   185  }
   186  
   187  func (cmsg *Cmsghdr) SetLen(length int) {
   188  	cmsg.Len = uint64(length)
   189  }
   190  
   191  func InotifyInit() (fd int, err error) {
   192  	return InotifyInit1(0)
   193  }
   194  
   195  //sys	ppoll(fds *pollFd, nfds int, timeout *Timespec, sigmask *sigset_t) (n int, err error)
   196  
   197  func Pause() error {
   198  	_, err := ppoll(nil, 0, nil, nil)
   199  	return err
   200  }
   201  
   202  func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) {
   203  	panic("not implemented")
   204  }
   205  

View as plain text