aboutsummaryrefslogtreecommitdiff
path: root/src/internal/runtime/syscall/syscall_linux.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2025-05-05 15:51:05 -0400
committerGopher Robot <gobot@golang.org>2025-05-19 12:42:00 -0700
commit2a29cddec377e2dccb6bceb7a542249ec8ec96b2 (patch)
treeda3f1567ec42a6307dea2af5320aab6471925e72 /src/internal/runtime/syscall/syscall_linux.go
parent195e64232d6a799c43b18b02bd7ff24d6bc11c48 (diff)
downloadgo-2a29cddec377e2dccb6bceb7a542249ec8ec96b2.tar.xz
internal/runtime/syscall: add basic file system calls
Change-Id: I6a6a636c5e119165dc1018d1fc0354f5b6929656 Reviewed-on: https://go-review.googlesource.com/c/go/+/670496 Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/internal/runtime/syscall/syscall_linux.go')
-rw-r--r--src/internal/runtime/syscall/syscall_linux.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/internal/runtime/syscall/syscall_linux.go b/src/internal/runtime/syscall/syscall_linux.go
index 83df825169..49e5f8de2c 100644
--- a/src/internal/runtime/syscall/syscall_linux.go
+++ b/src/internal/runtime/syscall/syscall_linux.go
@@ -6,6 +6,7 @@
package syscall
import (
+ "internal/goarch"
"unsafe"
)
@@ -42,3 +43,47 @@ func Eventfd(initval, flags int32) (fd int32, errno uintptr) {
r1, _, e := Syscall6(SYS_EVENTFD2, uintptr(initval), uintptr(flags), 0, 0, 0, 0)
return int32(r1), e
}
+
+func Open(path *byte, mode int, perm uint32) (fd int, errno uintptr) {
+ // Use SYS_OPENAT to match the syscall package.
+ dfd := AT_FDCWD
+ r1, _, e := Syscall6(SYS_OPENAT, uintptr(dfd), uintptr(unsafe.Pointer(path)), uintptr(mode|O_LARGEFILE), uintptr(perm), 0, 0)
+ return int(r1), e
+}
+
+func Close(fd int) (errno uintptr) {
+ _, _, e := Syscall6(SYS_CLOSE, uintptr(fd), 0, 0, 0, 0, 0)
+ return e
+}
+
+func Read(fd int, p []byte) (n int, errno uintptr) {
+ var p0 unsafe.Pointer
+ if len(p) > 0 {
+ p0 = unsafe.Pointer(&p[0])
+ } else {
+ p0 = unsafe.Pointer(&_zero)
+ }
+ r1, _, e := Syscall6(SYS_READ, uintptr(fd), uintptr(p0), uintptr(len(p)), 0, 0, 0)
+ return int(r1), e
+}
+
+func Pread(fd int, p []byte, offset int64) (n int, errno uintptr) {
+ var p0 unsafe.Pointer
+ if len(p) > 0 {
+ p0 = unsafe.Pointer(&p[0])
+ } else {
+ p0 = unsafe.Pointer(&_zero)
+ }
+ var r1, e uintptr
+ switch goarch.GOARCH {
+ case "386":
+ r1, _, e = Syscall6(SYS_PREAD64, uintptr(fd), uintptr(p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
+ case "arm", "mipsle":
+ r1, _, e = Syscall6(SYS_PREAD64, uintptr(fd), uintptr(p0), uintptr(len(p)), 0, uintptr(offset), uintptr(offset>>32))
+ case "mips":
+ r1, _, e = Syscall6(SYS_PREAD64, uintptr(fd), uintptr(p0), uintptr(len(p)), 0, uintptr(offset>>32), uintptr(offset))
+ default:
+ r1, _, e = Syscall6(SYS_PREAD64, uintptr(fd), uintptr(p0), uintptr(len(p)), uintptr(offset), 0, 0)
+ }
+ return int(r1), e
+}