From 020cca8c3c24b9e5e2515cd859cb4fa752027bae Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 17 Apr 2026 11:23:18 +0200 Subject: [PATCH] wasm: add more stubbed file operations This fixes issue #5037. A few more wasip1 syscalls needed to be present, and in particular fd_prestat_get needed to return EBADF on invalid file descriptors. --- targets/wasm_exec.js | 14 ++++++++++---- testdata/stdlib.go | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/targets/wasm_exec.js b/targets/wasm_exec.js index fa731a982..3d926ce52 100644 --- a/targets/wasm_exec.js +++ b/targets/wasm_exec.js @@ -237,9 +237,11 @@ } const timeOrigin = Date.now() - performance.now(); + const wasi_EBADF = 8; + const wasi_ENOSYS = 52; this.importObject = { wasi_snapshot_preview1: { - // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_write + // https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md fd_write: function(fd, iovs_ptr, iovs_len, nwritten_ptr) { let nwritten = 0; if (fd == 1) { @@ -268,9 +270,13 @@ mem().setUint32(nwritten_ptr, nwritten, true); return 0; }, - fd_close: () => 0, // dummy - fd_fdstat_get: () => 0, // dummy - fd_seek: () => 0, // dummy + fd_read: () => wasi_ENOSYS, + fd_close: () => wasi_ENOSYS, + fd_fdstat_get: () => wasi_ENOSYS, + fd_prestat_get: () => wasi_EBADF, // wasi-libc relies on this errno value + fd_prestat_dir_name: () => wasi_ENOSYS, + fd_seek: () => wasi_ENOSYS, + path_open: () => wasi_ENOSYS, proc_exit: (code) => { this.exited = true; this.exitCode = code; diff --git a/testdata/stdlib.go b/testdata/stdlib.go index f051eaf02..36086aa8a 100644 --- a/testdata/stdlib.go +++ b/testdata/stdlib.go @@ -33,6 +33,7 @@ func main() { // package time time.Sleep(time.Millisecond) time.Sleep(-1) // negative sleep should return immediately + time.LoadLocation("UTC") // Exit the program normally. os.Exit(0)