Skip to content

Commit 020cca8

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent 4cbd34d commit 020cca8

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

targets/wasm_exec.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,11 @@
237237
}
238238

239239
const timeOrigin = Date.now() - performance.now();
240+
const wasi_EBADF = 8;
241+
const wasi_ENOSYS = 52;
240242
this.importObject = {
241243
wasi_snapshot_preview1: {
242-
// https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_write
244+
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md
243245
fd_write: function(fd, iovs_ptr, iovs_len, nwritten_ptr) {
244246
let nwritten = 0;
245247
if (fd == 1) {
@@ -268,9 +270,13 @@
268270
mem().setUint32(nwritten_ptr, nwritten, true);
269271
return 0;
270272
},
271-
fd_close: () => 0, // dummy
272-
fd_fdstat_get: () => 0, // dummy
273-
fd_seek: () => 0, // dummy
273+
fd_read: () => wasi_ENOSYS,
274+
fd_close: () => wasi_ENOSYS,
275+
fd_fdstat_get: () => wasi_ENOSYS,
276+
fd_prestat_get: () => wasi_EBADF, // wasi-libc relies on this errno value
277+
fd_prestat_dir_name: () => wasi_ENOSYS,
278+
fd_seek: () => wasi_ENOSYS,
279+
path_open: () => wasi_ENOSYS,
274280
proc_exit: (code) => {
275281
this.exited = true;
276282
this.exitCode = code;

testdata/stdlib.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func main() {
3333
// package time
3434
time.Sleep(time.Millisecond)
3535
time.Sleep(-1) // negative sleep should return immediately
36+
time.LoadLocation("UTC")
3637

3738
// Exit the program normally.
3839
os.Exit(0)

0 commit comments

Comments
 (0)