]> Cypherpunks repositories - gostls13.git/commitdiff
internal/runtime/syscall: add basic file system calls
authorMichael Pratt <mpratt@google.com>
Mon, 5 May 2025 19:51:05 +0000 (15:51 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 19 May 2025 19:42:00 +0000 (12:42 -0700)
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>

12 files changed:
src/internal/runtime/syscall/defs_linux.go
src/internal/runtime/syscall/defs_linux_386.go
src/internal/runtime/syscall/defs_linux_amd64.go
src/internal/runtime/syscall/defs_linux_arm.go
src/internal/runtime/syscall/defs_linux_arm64.go
src/internal/runtime/syscall/defs_linux_loong64.go
src/internal/runtime/syscall/defs_linux_mips64x.go
src/internal/runtime/syscall/defs_linux_mipsx.go
src/internal/runtime/syscall/defs_linux_ppc64x.go
src/internal/runtime/syscall/defs_linux_riscv64.go
src/internal/runtime/syscall/defs_linux_s390x.go
src/internal/runtime/syscall/syscall_linux.go

index 70a1388a9e75d461bcbc07b4bd93d3809260f6c6..4c131e23cfe81cacf4c55b791634b2370808d2a3 100644 (file)
@@ -5,6 +5,10 @@
 package syscall
 
 const (
+       AT_FDCWD = -0x64
+
+       ENOENT = 0x2
+
        EPOLLIN       = 0x1
        EPOLLOUT      = 0x4
        EPOLLERR      = 0x8
@@ -17,6 +21,9 @@ const (
        EPOLL_CTL_MOD = 0x3
        EFD_CLOEXEC   = 0x80000
 
+       O_RDONLY  = 0x0
+       O_CLOEXEC = 0x80000
+
        PR_SET_VMA           = 0x53564d41
        PR_SET_VMA_ANON_NAME = 0
 )
index 2cfedab7c68107cd9a1a81d9b0d03a22140fcbc7..6f05fd73065694545701c3c7b42ad7e088ac3ea1 100644 (file)
@@ -5,6 +5,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 6
        SYS_FCNTL         = 55
        SYS_MPROTECT      = 125
        SYS_PRCTL         = 172
@@ -13,8 +14,13 @@ const (
        SYS_EPOLL_CREATE1 = 329
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 328
+       SYS_OPENAT        = 295
+       SYS_PREAD64       = 180
+       SYS_READ          = 3
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x8000
 )
 
 type EpollEvent struct {
index f664a59ad77ca3c4d6084b079c2500f89b37d203..6c6281810082824d03ae9a8f762d2faacd43e006 100644 (file)
@@ -5,6 +5,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 3
        SYS_MPROTECT      = 10
        SYS_FCNTL         = 72
        SYS_PRCTL         = 157
@@ -13,8 +14,13 @@ const (
        SYS_EPOLL_CREATE1 = 291
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 290
+       SYS_OPENAT        = 257
+       SYS_PREAD64       = 17
+       SYS_READ          = 0
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x0
 )
 
 type EpollEvent struct {
index 2850199a652cc52e6a69b127476bcc497c87ec20..2b6005a3daeedd56819f8ae7360f1a7e00e4d524 100644 (file)
@@ -5,6 +5,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 6
        SYS_FCNTL         = 55
        SYS_MPROTECT      = 125
        SYS_PRCTL         = 172
@@ -13,8 +14,13 @@ const (
        SYS_EPOLL_CREATE1 = 357
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 356
+       SYS_OPENAT        = 322
+       SYS_PREAD64       = 180
+       SYS_READ          = 3
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x20000
 )
 
 type EpollEvent struct {
index 1c951c1e7d2c60fa5ef402b9417dbcda0ba951f5..05922fbf7a6c6f799bf2aecf549fcfbd5c70e2b5 100644 (file)
@@ -5,6 +5,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 57
        SYS_EPOLL_CREATE1 = 20
        SYS_EPOLL_CTL     = 21
        SYS_EPOLL_PWAIT   = 22
@@ -13,8 +14,13 @@ const (
        SYS_MPROTECT      = 226
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 19
+       SYS_OPENAT        = 56
+       SYS_PREAD64       = 67
+       SYS_READ          = 63
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x0
 )
 
 type EpollEvent struct {
index dfeee05737d51b11bec3d85981f774dc4bd0e517..2501434cebd7162d9334c3913a61bda7dc2e2173 100644 (file)
@@ -5,6 +5,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 57
        SYS_EPOLL_CREATE1 = 20
        SYS_EPOLL_CTL     = 21
        SYS_EPOLL_PWAIT   = 22
@@ -13,8 +14,13 @@ const (
        SYS_MPROTECT      = 226
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 19
+       SYS_OPENAT        = 56
+       SYS_PREAD64       = 67
+       SYS_READ          = 63
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x0
 )
 
 type EpollEvent struct {
index b9b8818d302646d8b47bceffd0f5202f9f34006f..92ba3f7398fbd26586fcecbf4265e7df9fe09b46 100644 (file)
@@ -7,6 +7,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 5003
        SYS_MPROTECT      = 5010
        SYS_FCNTL         = 5070
        SYS_PRCTL         = 5153
@@ -15,8 +16,13 @@ const (
        SYS_EPOLL_CREATE1 = 5285
        SYS_EPOLL_PWAIT2  = 5441
        SYS_EVENTFD2      = 5284
+       SYS_OPENAT        = 5247
+       SYS_PREAD64       = 5016
+       SYS_READ          = 5000
 
        EFD_NONBLOCK = 0x80
+
+       O_LARGEFILE = 0x0
 )
 
 type EpollEvent struct {
index f147865f447c6f5736f9a346e2a55ccab951bf9d..7b4dee08af04137ee2ebca8eefdfb50c25353348 100644 (file)
@@ -7,6 +7,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 4006
        SYS_FCNTL         = 4055
        SYS_MPROTECT      = 4125
        SYS_PRCTL         = 4192
@@ -15,8 +16,13 @@ const (
        SYS_EPOLL_CREATE1 = 4326
        SYS_EPOLL_PWAIT2  = 4441
        SYS_EVENTFD2      = 4325
+       SYS_OPENAT        = 4288
+       SYS_PREAD64       = 4200
+       SYS_READ          = 4003
 
        EFD_NONBLOCK = 0x80
+
+       O_LARGEFILE = 0x2000
 )
 
 type EpollEvent struct {
index 81421089db46860e54e3507dd31cb45f684b95ed..4656517628534d83d85b65633217282f85d3a290 100644 (file)
@@ -7,6 +7,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 6
        SYS_FCNTL         = 55
        SYS_MPROTECT      = 125
        SYS_PRCTL         = 171
@@ -15,8 +16,13 @@ const (
        SYS_EPOLL_CREATE1 = 315
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 314
+       SYS_OPENAT        = 286
+       SYS_PREAD64       = 179
+       SYS_READ          = 3
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x0
 )
 
 type EpollEvent struct {
index dfeee05737d51b11bec3d85981f774dc4bd0e517..2501434cebd7162d9334c3913a61bda7dc2e2173 100644 (file)
@@ -5,6 +5,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 57
        SYS_EPOLL_CREATE1 = 20
        SYS_EPOLL_CTL     = 21
        SYS_EPOLL_PWAIT   = 22
@@ -13,8 +14,13 @@ const (
        SYS_MPROTECT      = 226
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 19
+       SYS_OPENAT        = 56
+       SYS_PREAD64       = 67
+       SYS_READ          = 63
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x0
 )
 
 type EpollEvent struct {
index 1d9d5b221943b022371a0021701d7e46d8a201ad..8005890e45365fa9d5f5cebcb8026b0ea0b8ef1f 100644 (file)
@@ -5,6 +5,7 @@
 package syscall
 
 const (
+       SYS_CLOSE         = 6
        SYS_FCNTL         = 55
        SYS_MPROTECT      = 125
        SYS_PRCTL         = 172
@@ -13,8 +14,13 @@ const (
        SYS_EPOLL_CREATE1 = 327
        SYS_EPOLL_PWAIT2  = 441
        SYS_EVENTFD2      = 323
+       SYS_OPENAT        = 288
+       SYS_PREAD64       = 180
+       SYS_READ          = 3
 
        EFD_NONBLOCK = 0x800
+
+       O_LARGEFILE = 0x0
 )
 
 type EpollEvent struct {
index 83df825169b9071590bd4cb2f7c1e4436c3a6392..49e5f8de2cb10545ae3a37cfac42a506956cb213 100644 (file)
@@ -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
+}