-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to correctly get the right file descriptor and execute in wasmtime? #6505
Comments
I don't think |
@bjorn3 is correct: wasmtime's wasi implementation fails BADF on directories because fd_advise does not work on directories. In your example, fd |
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. |
Would it make sense to add a test that the wasi implementation will return EBADF for fd_advise on directories? |
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 |
Thanks a lot ! |
This commit adds a check to `fd_advise`. If the fd is a directory, return `ebadf`. This brings iwasm in line with Wasmtime's behavior. WASI folks have stated that fd_advise should not work on directories as this is a Linux-specific behavior: bytecodealliance/wasmtime#6505 (comment)
it sounds like a bug (or a restriction) in wasmtime to me. in posix environments, it's common to ignore fadvice on directory. besides that, if you want to make it fail for some reasons, i feel it's more natural to use EISDIR than EBADF. |
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. |
This commit adds a check to `fd_advise`. If the fd is a directory, return `ebadf`. This brings iwasm in line with Wasmtime's behavior. WASI folks have stated that fd_advise should not work on directories as this is a Linux-specific behavior: bytecodealliance/wasmtime#6505 (comment)
Steps to reproduce
(1)'cargo new fd_advise'
(2)
cd fd_advise
and modify the main.rs :And add dependency in Cargo.toml:
(3)
![image](https://private-user-images.githubusercontent.com/28601300/242891549-9b6a973c-5b92-42a0-8b5a-6d813eee83cd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI4NDA5NDEsIm5iZiI6MTcyMjg0MDY0MSwicGF0aCI6Ii8yODYwMTMwMC8yNDI4OTE1NDktOWI2YTk3M2MtNWI5Mi00MmEwLThiNWEtNmQ4MTNlZWU4M2NkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODA1VDA2NTA0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc2NzYyYjkzMjFjMjFkZWI4YzUwODEzMzVhYjE1MjRjNGIwNWU1ZmVhZjRkNjA4M2U2MWIyODE5ZmQ1M2I4ZjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.4E3I_AbIVpIhcq-pM_mhmMcltKw97Hf5bYEJN9vFWe8)
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(5) execute it by wasmer:
![image](https://private-user-images.githubusercontent.com/28601300/242891833-41662979-5bff-460b-9bbe-6c1c37e4e3e0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI4NDA5NDEsIm5iZiI6MTcyMjg0MDY0MSwicGF0aCI6Ii8yODYwMTMwMC8yNDI4OTE4MzMtNDE2NjI5NzktNWJmZi00NjBiLTliYmUtNmMxYzM3ZTRlM2UwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODA1VDA2NTA0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZiZmQ0NGYxNDA1ZjkzOTA1ZDU5ZDA3NGE1ZTJkYTlkZWIzNWM1YmRlNmU5YzEyNTYwZDg3Y2NmM2UzNjU2NmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.ellEO8DQeF25JkWMprDeCJm_TYIsJcKQ7xb1s2voBPk)
wasmer --dir=/Users/name/filetest ./target/wasm32-wasi/debug/fd_advise.wasm
and it prints:without panic
Maybe I use wasmtime with wrong code ?
The text was updated successfully, but these errors were encountered: