syscall_linux_riscv64.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. //go:build riscv64 && linux
  5. // +build riscv64,linux
  6. package unix
  7. import "unsafe"
  8. //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
  9. //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
  10. //sys Fchown(fd int, uid int, gid int) (err error)
  11. //sys Fstat(fd int, stat *Stat_t) (err error)
  12. //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
  13. //sys Fstatfs(fd int, buf *Statfs_t) (err error)
  14. //sys Ftruncate(fd int, length int64) (err error)
  15. //sysnb Getegid() (egid int)
  16. //sysnb Geteuid() (euid int)
  17. //sysnb Getgid() (gid int)
  18. //sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
  19. //sysnb Getuid() (uid int)
  20. //sys Listen(s int, n int) (err error)
  21. //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
  22. //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
  23. //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
  24. func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
  25. var ts *Timespec
  26. if timeout != nil {
  27. ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
  28. }
  29. return Pselect(nfd, r, w, e, ts, nil)
  30. }
  31. //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
  32. //sys setfsgid(gid int) (prev int, err error)
  33. //sys setfsuid(uid int) (prev int, err error)
  34. //sysnb Setregid(rgid int, egid int) (err error)
  35. //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
  36. //sysnb Setresuid(ruid int, euid int, suid int) (err error)
  37. //sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
  38. //sysnb Setreuid(ruid int, euid int) (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. func Stat(path string, stat *Stat_t) (err error) {
  42. return Fstatat(AT_FDCWD, path, stat, 0)
  43. }
  44. func Lchown(path string, uid int, gid int) (err error) {
  45. return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
  46. }
  47. func Lstat(path string, stat *Stat_t) (err error) {
  48. return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
  49. }
  50. //sys Statfs(path string, buf *Statfs_t) (err error)
  51. //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
  52. //sys Truncate(path string, length int64) (err error)
  53. func Ustat(dev int, ubuf *Ustat_t) (err error) {
  54. return ENOSYS
  55. }
  56. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  57. //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
  58. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  59. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  60. //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
  61. //sysnb setgroups(n int, list *_Gid_t) (err error)
  62. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  63. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  64. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  65. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  66. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  67. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  68. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  69. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  70. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  71. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  72. //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
  73. //sysnb Gettimeofday(tv *Timeval) (err error)
  74. func setTimespec(sec, nsec int64) Timespec {
  75. return Timespec{Sec: sec, Nsec: nsec}
  76. }
  77. func setTimeval(sec, usec int64) Timeval {
  78. return Timeval{Sec: sec, Usec: usec}
  79. }
  80. func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
  81. if tv == nil {
  82. return utimensat(dirfd, path, nil, 0)
  83. }
  84. ts := []Timespec{
  85. NsecToTimespec(TimevalToNsec(tv[0])),
  86. NsecToTimespec(TimevalToNsec(tv[1])),
  87. }
  88. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  89. }
  90. func Time(t *Time_t) (Time_t, error) {
  91. var tv Timeval
  92. err := Gettimeofday(&tv)
  93. if err != nil {
  94. return 0, err
  95. }
  96. if t != nil {
  97. *t = Time_t(tv.Sec)
  98. }
  99. return Time_t(tv.Sec), nil
  100. }
  101. func Utime(path string, buf *Utimbuf) error {
  102. tv := []Timeval{
  103. {Sec: buf.Actime},
  104. {Sec: buf.Modtime},
  105. }
  106. return Utimes(path, tv)
  107. }
  108. func utimes(path string, tv *[2]Timeval) (err error) {
  109. if tv == nil {
  110. return utimensat(AT_FDCWD, path, nil, 0)
  111. }
  112. ts := []Timespec{
  113. NsecToTimespec(TimevalToNsec(tv[0])),
  114. NsecToTimespec(TimevalToNsec(tv[1])),
  115. }
  116. return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  117. }
  118. func (r *PtraceRegs) PC() uint64 { return r.Pc }
  119. func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
  120. func (iov *Iovec) SetLen(length int) {
  121. iov.Len = uint64(length)
  122. }
  123. func (msghdr *Msghdr) SetControllen(length int) {
  124. msghdr.Controllen = uint64(length)
  125. }
  126. func (msghdr *Msghdr) SetIovlen(length int) {
  127. msghdr.Iovlen = uint64(length)
  128. }
  129. func (cmsg *Cmsghdr) SetLen(length int) {
  130. cmsg.Len = uint64(length)
  131. }
  132. func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
  133. rsa.Service_name_len = uint64(length)
  134. }
  135. func Pause() error {
  136. _, err := ppoll(nil, 0, nil, nil)
  137. return err
  138. }
  139. func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
  140. return Renameat2(olddirfd, oldpath, newdirfd, newpath, 0)
  141. }
  142. //sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
  143. func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
  144. cmdlineLen := len(cmdline)
  145. if cmdlineLen > 0 {
  146. // Account for the additional NULL byte added by
  147. // BytePtrFromString in kexecFileLoad. The kexec_file_load
  148. // syscall expects a NULL-terminated string.
  149. cmdlineLen++
  150. }
  151. return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
  152. }