github.com/Andyfoo/golang/x/sys@v0.0.0-20190901054642-57c1bf301704/unix/syscall_linux_riscv64.go (about) 1 // Copyright 2018 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 // +build riscv64,linux 6 7 package unix 8 9 import "unsafe" 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 Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 20 //sys Fchown(fd int, uid int, gid int) (err error) 21 //sys Fstat(fd int, stat *Stat_t) (err error) 22 //sys Fstatat(fd 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 Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK 34 35 func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) { 36 var ts *Timespec 37 if timeout != nil { 38 ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000} 39 } 40 return Pselect(nfd, r, w, e, ts, nil) 41 } 42 43 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) 44 //sys Setfsgid(gid int) (err error) 45 //sys Setfsuid(uid int) (err error) 46 //sysnb Setregid(rgid int, egid int) (err error) 47 //sysnb Setresgid(rgid int, egid int, sgid int) (err error) 48 //sysnb Setresuid(ruid int, euid int, suid int) (err error) 49 //sysnb Setrlimit(resource int, rlim *Rlimit) (err error) 50 //sysnb Setreuid(ruid int, euid int) (err error) 51 //sys Shutdown(fd int, how int) (err error) 52 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) 53 54 func Stat(path string, stat *Stat_t) (err error) { 55 return Fstatat(AT_FDCWD, path, stat, 0) 56 } 57 58 func Lchown(path string, uid int, gid int) (err error) { 59 return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW) 60 } 61 62 func Lstat(path string, stat *Stat_t) (err error) { 63 return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW) 64 } 65 66 //sys Statfs(path string, buf *Statfs_t) (err error) 67 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) 68 //sys Truncate(path string, length int64) (err error) 69 70 func Ustat(dev int, ubuf *Ustat_t) (err error) { 71 return ENOSYS 72 } 73 74 //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) 75 //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) 76 //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 77 //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 78 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) 79 //sysnb setgroups(n int, list *_Gid_t) (err error) 80 //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) 81 //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) 82 //sysnb socket(domain int, typ int, proto int) (fd int, err error) 83 //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) 84 //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 85 //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 86 //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) 87 //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) 88 //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) 89 //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) 90 //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) 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 Pipe(p []int) (err error) { 147 if len(p) != 2 { 148 return EINVAL 149 } 150 var pp [2]_C_int 151 err = pipe2(&pp, 0) 152 p[0] = int(pp[0]) 153 p[1] = int(pp[1]) 154 return 155 } 156 157 //sysnb pipe2(p *[2]_C_int, flags int) (err error) 158 159 func Pipe2(p []int, flags int) (err error) { 160 if len(p) != 2 { 161 return EINVAL 162 } 163 var pp [2]_C_int 164 err = pipe2(&pp, flags) 165 p[0] = int(pp[0]) 166 p[1] = int(pp[1]) 167 return 168 } 169 170 func (r *PtraceRegs) PC() uint64 { return r.Pc } 171 172 func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc } 173 174 func (iov *Iovec) SetLen(length int) { 175 iov.Len = uint64(length) 176 } 177 178 func (msghdr *Msghdr) SetControllen(length int) { 179 msghdr.Controllen = uint64(length) 180 } 181 182 func (cmsg *Cmsghdr) SetLen(length int) { 183 cmsg.Len = uint64(length) 184 } 185 186 func InotifyInit() (fd int, err error) { 187 return InotifyInit1(0) 188 } 189 190 func Dup2(oldfd int, newfd int) (err error) { 191 return Dup3(oldfd, newfd, 0) 192 } 193 194 func Pause() error { 195 _, err := ppoll(nil, 0, nil, nil) 196 return err 197 } 198 199 func Poll(fds []PollFd, timeout int) (n int, err error) { 200 var ts *Timespec 201 if timeout >= 0 { 202 ts = new(Timespec) 203 *ts = NsecToTimespec(int64(timeout) * 1e6) 204 } 205 if len(fds) == 0 { 206 return ppoll(nil, 0, ts, nil) 207 } 208 return ppoll(&fds[0], len(fds), ts, nil) 209 } 210 211 func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) { 212 return Renameat2(olddirfd, oldpath, newdirfd, newpath, 0) 213 } 214 215 //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error) 216 217 func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error { 218 cmdlineLen := len(cmdline) 219 if cmdlineLen > 0 { 220 // Account for the additional NULL byte added by 221 // BytePtrFromString in kexecFileLoad. The kexec_file_load 222 // syscall expects a NULL-terminated string. 223 cmdlineLen++ 224 } 225 return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags) 226 }