Error description:
I'm trying to build a standalone WASM module which is reading from a file by using WASI.
The compilation is done by running the following command:
emcc filetest.c -o filetest.wasm --no-entry -s ERROR_ON_UNDEFINED_SYMBOLS=0
The compilation works fine and succeeds without an error.
I'm using wasmtime in order to run the module:
wasmtime filetest.wasm --dir . --invoke filetest
In my working directory, there is a file 'test.txt', which only contains one line with the content "test".
Running the WASM module by using the previously mentioned command, I'm getting the following output:
Looking up the meaning of errno 63, there seems to be an issue with stream resources:
ENOSR 63 Out of streams resources
I also activated the wasmtime WASI trace logging by setting the environment variable RUST_LOG to wasi_common=trace. Running the wasmtime command now prints the following output:
TRACE wasi_common::snapshots::preview_1::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_write"
TRACE wasi_common::snapshots::preview_1::wasi_snapshot_preview1 > fd=Fd(1) iovs=*guest 0x500e40/2
Fopen failed, errno = 63 TRACE wasi_common::snapshots::preview_1::wasi_snapshot_preview1 > result=Ok(24)
TRACE wasi_common::snapshots::preview_1::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="proc_exit"
TRACE wasi_common::snapshots::preview_1::wasi_snapshot_preview1 > rval=1
TRACE wasi_common::snapshots::preview_1::wasi_snapshot_preview1 > result=I32Exit(1)
This log shows that no open- or read-call was performed. There is only a fd_write-call, that prints the error message to the stdout file descriptor.
What is the reason behind this error and what can I do in order to get my example running?
Example code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <emscripten/emscripten.h>
EMSCRIPTEN_KEEPALIVE void filetest() {
FILE *handle = fopen("test.txt", "r");
if (handle == NULL) {
printf("Fopen failed, errno = %d", errno);
exit(EXIT_FAILURE);
}
fclose(handle);
}
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.13 (5312576)
clang version 15.0.0 (https://github.com/llvm/llvm-project 5c6ed60c517c47b25b6b25d8ac3666d0e746b0c3)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
Error description:
I'm trying to build a standalone WASM module which is reading from a file by using WASI.
The compilation is done by running the following command:
The compilation works fine and succeeds without an error.
I'm using wasmtime in order to run the module:
In my working directory, there is a file 'test.txt', which only contains one line with the content "test".
Running the WASM module by using the previously mentioned command, I'm getting the following output:
Looking up the meaning of errno 63, there seems to be an issue with stream resources:
I also activated the wasmtime WASI trace logging by setting the environment variable RUST_LOG to wasi_common=trace. Running the wasmtime command now prints the following output:
This log shows that no open- or read-call was performed. There is only a fd_write-call, that prints the error message to the stdout file descriptor.
What is the reason behind this error and what can I do in order to get my example running?
Example code:
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.13 (5312576)
clang version 15.0.0 (https://github.com/llvm/llvm-project 5c6ed60c517c47b25b6b25d8ac3666d0e746b0c3)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin