Source file src/syscall/syscall_linux_riscv64.go
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 Setrlimit(resource int, rlim *Rlimit) (err error) 39 //sys Shutdown(fd int, how int) (err error) 40 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) 41 42 func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) { 43 return renameat2(olddirfd, oldpath, newdirfd, newpath, 0) 44 } 45 46 func Stat(path string, stat *Stat_t) (err error) { 47 return Fstatat(_AT_FDCWD, path, stat, 0) 48 } 49 50 func Lchown(path string, uid int, gid int) (err error) { 51 return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW) 52 } 53 54 func Lstat(path string, stat *Stat_t) (err error) { 55 return Fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW) 56 } 57 58 //sys Statfs(path string, buf *Statfs_t) (err error) 59 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) 60 //sys Truncate(path string, length int64) (err error) 61 //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) 62 //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) 63 //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 64 //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 65 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) 66 //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) 67 //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) 68 //sysnb socket(domain int, typ int, proto int) (fd int, err error) 69 //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) 70 //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 71 //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 72 //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) 73 //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) 74 //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) 75 //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) 76 //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) 77 78 type sigset_t struct { 79 X__val [16]uint64 80 } 81 82 //sys pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_t) (n int, err error) = SYS_PSELECT6 83 84 func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) { 85 var ts *Timespec 86 if timeout != nil { 87 ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000} 88 } 89 return pselect(nfd, r, w, e, ts, nil) 90 } 91 92 //sysnb Gettimeofday(tv *Timeval) (err error) 93 94 func setTimespec(sec, nsec int64) Timespec { 95 return Timespec{Sec: sec, Nsec: nsec} 96 } 97 98 func setTimeval(sec, usec int64) Timeval { 99 return Timeval{Sec: sec, Usec: usec} 100 } 101 102 func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) { 103 if tv == nil { 104 return utimensat(dirfd, path, nil, 0) 105 } 106 107 ts := []Timespec{ 108 NsecToTimespec(TimevalToNsec(tv[0])), 109 NsecToTimespec(TimevalToNsec(tv[1])), 110 } 111 return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0) 112 } 113 114 func Time(t *Time_t) (Time_t, error) { 115 var tv Timeval 116 err := Gettimeofday(&tv) 117 if err != nil { 118 return 0, err 119 } 120 if t != nil { 121 *t = Time_t(tv.Sec) 122 } 123 return Time_t(tv.Sec), nil 124 } 125 126 func Utime(path string, buf *Utimbuf) error { 127 tv := []Timeval{ 128 {Sec: buf.Actime}, 129 {Sec: buf.Modtime}, 130 } 131 return Utimes(path, tv) 132 } 133 134 func utimes(path string, tv *[2]Timeval) (err error) { 135 if tv == nil { 136 return utimensat(_AT_FDCWD, path, nil, 0) 137 } 138 139 ts := []Timespec{ 140 NsecToTimespec(TimevalToNsec(tv[0])), 141 NsecToTimespec(TimevalToNsec(tv[1])), 142 } 143 return utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0) 144 } 145 146 func (r *PtraceRegs) PC() uint64 { return r.Pc } 147 148 func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc } 149 150 func (iov *Iovec) SetLen(length int) { 151 iov.Len = uint64(length) 152 } 153 154 func (msghdr *Msghdr) SetControllen(length int) { 155 msghdr.Controllen = uint64(length) 156 } 157 158 func (cmsg *Cmsghdr) SetLen(length int) { 159 cmsg.Len = uint64(length) 160 } 161 162 func InotifyInit() (fd int, err error) { 163 return InotifyInit1(0) 164 } 165 166 //sys ppoll(fds *pollFd, nfds int, timeout *Timespec, sigmask *sigset_t) (n int, err error) 167 168 func Pause() error { 169 _, err := ppoll(nil, 0, nil, nil) 170 return err 171 } 172 173 func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) 174