runtime,syscall,internal/poll,os: wasip1 poll_oneoff scheduler integration + net.FileListener (#5386)

* runtime,syscall,internal/poll,os: wasip1 poll_oneoff scheduler integration + net.FileListener

On wasip1 today every syscall.Read/Write blocks the entire wasm module — the
cooperative scheduler invokes poll_oneoff only for sleep/timer wakeups, and
there's no path from the net package to a working TCP server. This change
fixes both: it threads poll_oneoff through the scheduler's idle path so a
goroutine doing FD I/O parks instead of blocking the module, and it provides
enough internal/poll / os / syscall surface that upstream Go's
net.FileListener / net.FileConn works on a host-pre-opened TCP socket.

* runtime: keep scheduler_cooperative idle-wait calls direct

TestBinarySize/hifive1b/examples/echo regressed by 32 bytes after the
previous commit routed the scheduler's idle wait through a
schedulerIdleWait helper. The extra call frame + branch landed on every
non-wasip1 cooperative target, where the original direct sleepTicks /
waitForEvents calls compile to a single inlined call.
This commit is contained in:
Achille
2026-05-26 01:12:55 -07:00
committed by GitHub
parent 85d223c5e2
commit d01a932201
17 changed files with 1404 additions and 51 deletions
+48
View File
@@ -0,0 +1,48 @@
//go:build js || nintendoswitch || wasip2 || (wasip1 && !scheduler.tasks && !scheduler.asyncify)
package syscall
// 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
// underlying libc syscalls and block the entire wasm module if the FD
// is in blocking mode.
//
// The wasip1 + cooperative-scheduler build replaces these with versions
// 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))
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))
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)
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)
if n < 0 {
err = getErrno()
}
return
}