Stream: git-wasmtime

Topic: wasmtime / issue #6505 How to correctly get the right fil...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 13:06):

orangeC23 opened issue #6505:

Steps to reproduce

(1)'cargo new fd_advise'
(2)cd fd_advise and modify the main.rs :

fn main() {
    unsafe {
        let p1:wasi::Fd = 3;
        let p2:wasi::Filesize = 10;
        let p3:wasi::Filesize = 20;
        let p4:wasi::Advice = wasi::ADVICE_NORMAL;

        println!("===[Result]===");
        println!("{:?}", wasi::fd_advise(p1, p2, p3, p4).unwrap());
    }
}

And add dependency in Cargo.toml:

[dependencies]
wasi = "0.11.0"

(3) cargo build --target wasm32-wasi
(4) execute it by wasmtime:wasmtime run --dir=/Users/name/filetest ./target/wasm32-wasi/debug/fd_advise.wasm and it prints
![image](https://github.com/bytecodealliance/wasmtime/assets/28601300/9b6a973c-5b92-42a0-8b5a-6d813eee83cd)

(5) execute it by wasmer:wasmer --dir=/Users/name/filetest ./target/wasm32-wasi/debug/fd_advise.wasm and it prints:
![image](https://github.com/bytecodealliance/wasmtime/assets/28601300/41662979-5bff-460b-9bbe-6c1c37e4e3e0)

without panic

view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 13:07):

orangeC23 edited issue #6505:

Steps to reproduce

(1)'cargo new fd_advise'
(2)cd fd_advise and modify the main.rs :

fn main() {
    unsafe {
        let p1:wasi::Fd = 3;
        let p2:wasi::Filesize = 10;
        let p3:wasi::Filesize = 20;
        let p4:wasi::Advice = wasi::ADVICE_NORMAL;

        println!("===[Result]===");
        println!("{:?}", wasi::fd_advise(p1, p2, p3, p4).unwrap());
    }
}

And add dependency in Cargo.toml:

[dependencies]
wasi = "0.11.0"

(3) cargo build --target wasm32-wasi
(4) execute it by wasmtime:wasmtime run --dir=/Users/name/filetest ./target/wasm32-wasi/debug/fd_advise.wasm and it prints
![image](https://github.com/bytecodealliance/wasmtime/assets/28601300/9b6a973c-5b92-42a0-8b5a-6d813eee83cd)

(5) execute it by wasmer:wasmer --dir=/Users/name/filetest ./target/wasm32-wasi/debug/fd_advise.wasm and it prints:
![image](https://github.com/bytecodealliance/wasmtime/assets/28601300/41662979-5bff-460b-9bbe-6c1c37e4e3e0)

without panic

Maybe I use wasmtime with wrong code ?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 14:01):

bjorn3 commented on issue #6505:

I don't think fd_advise is meant to be used on directories. --dir opens a directory, not a file. If /Users/name/filetest is a file, I'm surprised you don't get an error earlier when trying to open it as directory.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 18:08):

pchickey commented on issue #6505:

@bjorn3 is correct: wasmtime's wasi implementation fails BADF on directories because fd_advise does not work on directories. In your example, fd 3 is a preopened directory.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 18:26):

pchickey commented on issue #6505:

Since I believe what you described is the intended behavior, I'm going to close this issue, but please re-open if my understanding of the problem is incorrect.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 18:26):

pchickey closed issue #6505:

Steps to reproduce

(1)'cargo new fd_advise'
(2)cd fd_advise and modify the main.rs :

fn main() {
    unsafe {
        let p1:wasi::Fd = 3;
        let p2:wasi::Filesize = 10;
        let p3:wasi::Filesize = 20;
        let p4:wasi::Advice = wasi::ADVICE_NORMAL;

        println!("===[Result]===");
        println!("{:?}", wasi::fd_advise(p1, p2, p3, p4).unwrap());
    }
}

And add dependency in Cargo.toml:

[dependencies]
wasi = "0.11.0"

(3) cargo build --target wasm32-wasi
(4) execute it by wasmtime:wasmtime run --dir=/Users/name/filetest ./target/wasm32-wasi/debug/fd_advise.wasm and it prints
![image](https://github.com/bytecodealliance/wasmtime/assets/28601300/9b6a973c-5b92-42a0-8b5a-6d813eee83cd)

(5) execute it by wasmer:wasmer --dir=/Users/name/filetest ./target/wasm32-wasi/debug/fd_advise.wasm and it prints:
![image](https://github.com/bytecodealliance/wasmtime/assets/28601300/41662979-5bff-460b-9bbe-6c1c37e4e3e0)

without panic

Maybe I use wasmtime with wrong code ?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 18:27):

bjorn3 commented on issue #6505:

Would it make sense to add a test that the wasi implementation will return EBADF for fd_advise on directories?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 02 2023 at 18:30):

pchickey commented on issue #6505:

We already do, along with a note that it differs from the Linux behavior. https://github.com/bytecodealliance/wasmtime/blob/main/crates/test-programs/wasi-tests/src/bin/dir_fd_op_failures.rs#L64

view this post on Zulip Wasmtime GitHub notifications bot (Jun 04 2023 at 02:02):

orangeC23 commented on issue #6505:

Thanks a lot !

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 05:45):

yamt commented on issue #6505:

it sounds like a bug (or a restriction) in wasmtime to me.

in posix environments, it's common to ignore fadvice on directory.
wasi doesn't seem to have a word about the case. (so i expect it to follow posix equivalent.)

besides that, if you want to make it fail for some reasons, i feel it's more natural to use EISDIR than EBADF.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:28):

pchickey commented on issue #6505:

OK. This is the least interesting topic possible to debate, so we will change wasmtime's behavior to ignore and return success if you send a PR to change our implementations and tests.


Last updated: Dec 23 2024 at 12:05 UTC