Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/syscall/env_libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func Getenv(key string) (value string, found bool) {
for size := uintptr(0); ; size++ {
v := *(*byte)(unsafe.Pointer(ptr))
if v == 0 {
src := *(*[]byte)(unsafe.Pointer(&sliceHeader{buf: raw, len: size, cap: size}))
Comment thread
jakebailey marked this conversation as resolved.
return string(src), true
return string(unsafe.Slice(raw, size)), true
}
ptr += unsafe.Sizeof(byte(0))
}
Expand Down
14 changes: 1 addition & 13 deletions src/syscall/syscall_libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import (
"unsafe"
)

type sliceHeader struct {
buf *byte
len uintptr
cap uintptr
}

func Close(fd int) (err error) {
if libc_close(int32(fd)) < 0 {
err = getErrno()
Expand Down Expand Up @@ -58,8 +52,7 @@ func Fsync(fd int) (err error) {

func Readlink(path string, p []byte) (n int, err error) {
data := cstring(path)
buf, count := splitSlice(p)
n = libc_readlink(&data[0], buf, uint(count))
n = libc_readlink(&data[0], unsafe.SliceData(p), uint(len(p)))
if n < 0 {
err = getErrno()
}
Expand Down Expand Up @@ -264,11 +257,6 @@ func cstring(s string) []byte {
return data
}

func splitSlice(p []byte) (buf *byte, len uintptr) {
slice := (*sliceHeader)(unsafe.Pointer(&p))
return slice.buf, slice.len
}

// These two functions are provided by the runtime.
func runtimeSetenv(key, value string)
func runtimeUnsetenv(key string)
Expand Down
14 changes: 6 additions & 8 deletions src/syscall/syscall_libc_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package syscall

import "unsafe"

// These are the default Read/Write/Pread/Pwrite implementations for
// libc-backed wasm targets that do NOT have the cooperative scheduler
// + wasip1 netpoll integration. They are simple pass-throughs to the
Expand All @@ -12,35 +14,31 @@ package syscall
// that park the goroutine on EAGAIN; see syscall_libc_wasip1.go.

func Write(fd int, p []byte) (n int, err error) {
buf, count := splitSlice(p)
n = libc_write(int32(fd), buf, uint(count))
n = libc_write(int32(fd), unsafe.SliceData(p), uint(len(p)))
if n < 0 {
err = getErrno()
}
return
}

func Read(fd int, p []byte) (n int, err error) {
buf, count := splitSlice(p)
n = libc_read(int32(fd), buf, uint(count))
n = libc_read(int32(fd), unsafe.SliceData(p), uint(len(p)))
if n < 0 {
err = getErrno()
}
return
}

func Pread(fd int, p []byte, offset int64) (n int, err error) {
buf, count := splitSlice(p)
n = libc_pread(int32(fd), buf, uint(count), offset)
n = libc_pread(int32(fd), unsafe.SliceData(p), uint(len(p)), offset)
if n < 0 {
err = getErrno()
}
return
}

func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
buf, count := splitSlice(p)
n = libc_pwrite(int32(fd), buf, uint(count), offset)
n = libc_pwrite(int32(fd), unsafe.SliceData(p), uint(len(p)), offset)
if n < 0 {
err = getErrno()
}
Expand Down
14 changes: 5 additions & 9 deletions src/syscall/syscall_libc_wasip1.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package syscall

import (
"internal/task"
_ "unsafe" // for go:linkname
"unsafe"
)

// pollMode constants must mirror runtime/netpoll_wasip1.go's pollRead/
Expand All @@ -26,9 +26,8 @@ func runtime_netpoll_done(pd uintptr)
// goroutine until the cooperative scheduler's pollIO wakes us, then
// retry. EINTR retries immediately without parking.
func Write(fd int, p []byte) (n int, err error) {
buf, count := splitSlice(p)
for {
n = libc_write(int32(fd), buf, uint(count))
n = libc_write(int32(fd), unsafe.SliceData(p), uint(len(p)))
if n >= 0 {
return
}
Expand All @@ -45,9 +44,8 @@ func Write(fd int, p []byte) (n int, err error) {
}

func Read(fd int, p []byte) (n int, err error) {
buf, count := splitSlice(p)
for {
n = libc_read(int32(fd), buf, uint(count))
n = libc_read(int32(fd), unsafe.SliceData(p), uint(len(p)))
if n >= 0 {
return
}
Expand All @@ -64,9 +62,8 @@ func Read(fd int, p []byte) (n int, err error) {
}

func Pread(fd int, p []byte, offset int64) (n int, err error) {
buf, count := splitSlice(p)
for {
n = libc_pread(int32(fd), buf, uint(count), offset)
n = libc_pread(int32(fd), unsafe.SliceData(p), uint(len(p)), offset)
if n >= 0 {
return
}
Expand All @@ -83,9 +80,8 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) {
}

func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
buf, count := splitSlice(p)
for {
n = libc_pwrite(int32(fd), buf, uint(count), offset)
n = libc_pwrite(int32(fd), unsafe.SliceData(p), uint(len(p)), offset)
if n >= 0 {
return
}
Expand Down
Loading