syscall_linux_riscv64.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. // +build riscv64,linux
  5. package unix
  6. import "unsafe"
  7. func EpollCreate(size int) (fd int, err error) {
  8. if size <= 0 {
  9. return -1, EINVAL
  10. }
  11. return EpollCreate1(0)
  12. }
  13. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
  14. //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
  15. //sys Fchown(fd int, uid int, gid int) (err error)
  16. //sys Fstat(fd int, stat *Stat_t) (err error)
  17. //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
  18. //sys Fstatfs(fd int, buf *Statfs_t) (err error)
  19. //sys Ftruncate(fd int, length int64) (err error)
  20. //sysnb Getegid() (egid int)
  21. //sysnb Geteuid() (euid int)
  22. //sysnb Getgid() (gid int)
  23. //sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
  24. //sysnb Getuid() (uid int)
  25. //sys Listen(s int, n int) (err error)
  26. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  27. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  28. //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
  29. func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
  30. var ts *Timespec
  31. if timeout != nil {
  32. ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
  33. }
  34. return Pselect(nfd, r, w, e, ts, nil)
  35. }
  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. //sysnb Setregid(rgid int, egid int) (err error)
  40. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  41. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  42. //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
  43. //sysnb Setreuid(ruid int, euid int) (err error)
  44. //sys Shutdown(fd int, how int) (err error)
  45. //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
  46. func Stat(path string, stat *Stat_t) (err error) {
  47. return Fstatat(AT_FDCWD, path, stat, 0)
  48. }
  49. func Lchown(path string, uid int, gid int) (err error) {
  50. return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
  51. }
  52. func Lstat(path string, stat *Stat_t) (err error) {
  53. return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
  54. }
  55. //sys Statfs(path string, buf *Statfs_t) (err error)
  56. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  57. //sys Truncate(path string, length int64) (err error)
  58. func Ustat(dev int, ubuf *Ustat_t) (err error) {
  59. return ENOSYS
  60. }
  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. //sysnb setgroups(n int, list *_Gid_t) (err error)
  67. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  68. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  69. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  70. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  71. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  72. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  73. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  74. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  75. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  76. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  77. //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
  78. //sysnb Gettimeofday(tv *Timeval) (err error)
  79. func setTimespec(sec, nsec int64) Timespec {
  80. return Timespec{Sec: sec, Nsec: nsec}
  81. }
  82. func setTimeval(sec, usec int64) Timeval {
  83. return Timeval{Sec: sec, Usec: usec}
  84. }
  85. func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
  86. if tv == nil {
  87. return utimensat(dirfd, path, nil, 0)
  88. }
  89. ts := []Timespec{
  90. NsecToTimespec(TimevalToNsec(tv[0])),
  91. NsecToTimespec(TimevalToNsec(tv[1])),
  92. }
  93. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  94. }
  95. func Time(t *Time_t) (Time_t, error) {
  96. var tv Timeval
  97. err := Gettimeofday(&tv)
  98. if err != nil {
  99. return 0, err
  100. }
  101. if t != nil {
  102. *t = Time_t(tv.Sec)
  103. }
  104. return Time_t(tv.Sec), nil
  105. }
  106. func Utime(path string, buf *Utimbuf) error {
  107. tv := []Timeval{
  108. {Sec: buf.Actime},
  109. {Sec: buf.Modtime},
  110. }
  111. return Utimes(path, tv)
  112. }
  113. func utimes(path string, tv *[2]Timeval) (err error) {
  114. if tv == nil {
  115. return utimensat(AT_FDCWD, path, nil, 0)
  116. }
  117. ts := []Timespec{
  118. NsecToTimespec(TimevalToNsec(tv[0])),
  119. NsecToTimespec(TimevalToNsec(tv[1])),
  120. }
  121. return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  122. }
  123. func Pipe(p []int) (err error) {
  124. if len(p) != 2 {
  125. return EINVAL
  126. }
  127. var pp [2]_C_int
  128. err = pipe2(&pp, 0)
  129. p[0] = int(pp[0])
  130. p[1] = int(pp[1])
  131. return
  132. }
  133. //sysnb pipe2(p *[2]_C_int, flags int) (err error)
  134. func Pipe2(p []int, flags int) (err error) {
  135. if len(p) != 2 {
  136. return EINVAL
  137. }
  138. var pp [2]_C_int
  139. err = pipe2(&pp, flags)
  140. p[0] = int(pp[0])
  141. p[1] = int(pp[1])
  142. return
  143. }
  144. func (r *PtraceRegs) PC() uint64 { return r.Pc }
  145. func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
  146. func (iov *Iovec) SetLen(length int) {
  147. iov.Len = uint64(length)
  148. }
  149. func (msghdr *Msghdr) SetControllen(length int) {
  150. msghdr.Controllen = uint64(length)
  151. }
  152. func (msghdr *Msghdr) SetIovlen(length int) {
  153. msghdr.Iovlen = uint64(length)
  154. }
  155. func (cmsg *Cmsghdr) SetLen(length int) {
  156. cmsg.Len = uint64(length)
  157. }
  158. func InotifyInit() (fd int, err error) {
  159. return InotifyInit1(0)
  160. }
  161. func Dup2(oldfd int, newfd int) (err error) {
  162. return Dup3(oldfd, newfd, 0)
  163. }
  164. func Pause() error {
  165. _, err := ppoll(nil, 0, nil, nil)
  166. return err
  167. }
  168. func Poll(fds []PollFd, timeout int) (n int, err error) {
  169. var ts *Timespec
  170. if timeout >= 0 {
  171. ts = new(Timespec)
  172. *ts = NsecToTimespec(int64(timeout) * 1e6)
  173. }
  174. if len(fds) == 0 {
  175. return ppoll(nil, 0, ts, nil)
  176. }
  177. return ppoll(&fds[0], len(fds), ts, nil)
  178. }
  179. func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
  180. return Renameat2(olddirfd, oldpath, newdirfd, newpath, 0)
  181. }
  182. //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
  183. func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
  184. cmdlineLen := len(cmdline)
  185. if cmdlineLen > 0 {
  186. // Account for the additional NULL byte added by
  187. // BytePtrFromString in kexecFileLoad. The kexec_file_load
  188. // syscall expects a NULL-terminated string.
  189. cmdlineLen++
  190. }
  191. return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
  192. }