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
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 ?
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.
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.
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.
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 ?
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?
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
orangeC23 commented on issue #6505:
Thanks a lot !
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.
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: Nov 22 2024 at 17:03 UTC