forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
adapter_{open|close}_badfd
exports to Preview 1 adapter (byteco…
…dealliance#7663) * add `adapter_{open|close}_badfd` exports to Preview 1 adapter This is to be used by `wasi-libc` to reserve file descriptors for its own use (e.g. for sockets), ensuring that any attempt to pass them directly to Preview 1 functions will consistently return an error. See WebAssembly/wasi-libc#447 for further details. Signed-off-by: Joel Dice <[email protected]> * add `preview2_adapter_badfd` test Signed-off-by: Joel Dice <[email protected]> --------- Signed-off-by: Joel Dice <[email protected]>
- Loading branch information
Showing
5 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
fn main() { | ||
#[link(wasm_import_module = "wasi_snapshot_preview1")] | ||
extern "C" { | ||
#[cfg_attr(target_arch = "wasm32", link_name = "adapter_open_badfd")] | ||
fn adapter_open_badfd(fd: *mut u32) -> bool; | ||
|
||
#[cfg_attr(target_arch = "wasm32", link_name = "adapter_close_badfd")] | ||
fn adapter_close_badfd(fd: u32) -> bool; | ||
} | ||
|
||
unsafe { | ||
let mut fd = 0; | ||
assert!(adapter_open_badfd(&mut fd)); | ||
|
||
assert_eq!(wasi::fd_close(fd), Err(wasi::ERRNO_BADF)); | ||
|
||
assert_eq!(wasi::fd_fdstat_get(fd).map(drop), Err(wasi::ERRNO_BADF)); | ||
|
||
assert_eq!(wasi::fd_fdstat_set_rights(fd, 0, 0), Err(wasi::ERRNO_BADF)); | ||
|
||
let mut buffer = [0_u8; 1]; | ||
assert_eq!( | ||
wasi::fd_read( | ||
fd, | ||
&[wasi::Iovec { | ||
buf: buffer.as_mut_ptr(), | ||
buf_len: 1 | ||
}] | ||
), | ||
Err(wasi::ERRNO_BADF) | ||
); | ||
|
||
assert_eq!( | ||
wasi::fd_write( | ||
fd, | ||
&[wasi::Ciovec { | ||
buf: buffer.as_ptr(), | ||
buf_len: 1 | ||
}] | ||
), | ||
Err(wasi::ERRNO_BADF) | ||
); | ||
|
||
assert!(adapter_close_badfd(fd)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters