Stream: general

Topic: WASI fopen operation not permitted


view this post on Zulip Risto (Sep 01 2020 at 12:54):

I am trying to use wasmtime from my own program to run a module that opens a file for reading. The file is in same folder with the runtime.
I have tried setting up WASI and the linker in the following manner after which I run the Wasm module.

    let wasi = Wasi::new(&store, WasiCtx::new(std::env::args()).expect("Wasi Error"));
    wasi.add_to_linker(&mut linker)?;
    let main_module = Module::from_file(store.engine(), "./example_main.wasm")?;
    let main_instance = linker.instantiate(&main_module)?;
    linker.instance("example_main", &main_instance)?;
    linker.alias("example_main", "env")?;

However, calling fopen in the module returns NULL and perror prints a message saying "Operation not permitted".
The same code in C works fine, so file permissions are unlikely the cause. The file also has 777 permissions.

I would assume that I have some permissions missing from WASI to allow it to access files.
I tried passing different switches to the program ./example --dir=. --dir=absolute/path/to/example/folder ./example -- --dir=. --dir=absolute/path/to/example/folder, but none change the error message.

Pointers to where the issue could be are appreciated.

view this post on Zulip Risto (Sep 01 2020 at 13:49):

Tried to use fopen with wasmtime-cli too, but it has the same error, so the problem isnt specific to my code either.

view this post on Zulip bjorn3 (Sep 01 2020 at 14:07):

You need to use WasiCtxBuilder and call preopened_dir I think. WasiCtx::new takes the arguments to be passed to the wasm module, not arguments to customize WasiCtx.

view this post on Zulip Risto (Sep 01 2020 at 14:10):

It seems that the issue might be with the module itself. It was built with emscripten.
Running the examples from here worked fine, unless compiled with emscripten https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-tutorial.md#executing-in-wasmtime-runtime

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip Risto (Sep 01 2020 at 16:23):

Posted an issue about it here: https://github.com/emscripten-core/emscripten/issues/12094

I am trying to compile and run the examples depicted here: https://github.com/bytecodealliance/wasmtime/blob/fbe29da5cc1c0847af176f151f114a6a535534ff/docs/WASI-tutorial.md The tools I try to use ar...

Last updated: Dec 23 2024 at 12:05 UTC