From 20cd955fa1b441e3c6a0dcccd2b3d231800acb0d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 11 Dec 2023 07:20:39 -0800 Subject: [PATCH] Update `*_badfd` methods in the adapter to return an errno Makes them a bit more consistent with the rest of the WASI functions as opposed to returning a boolean. --- crates/test-programs/src/bin/preview2_adapter_badfd.rs | 8 ++++---- crates/wasi-preview1-component-adapter/src/lib.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/test-programs/src/bin/preview2_adapter_badfd.rs b/crates/test-programs/src/bin/preview2_adapter_badfd.rs index 7baa33717225..e437dd668dcc 100644 --- a/crates/test-programs/src/bin/preview2_adapter_badfd.rs +++ b/crates/test-programs/src/bin/preview2_adapter_badfd.rs @@ -2,15 +2,15 @@ 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; + fn adapter_open_badfd(fd: *mut u32) -> wasi::Errno; #[cfg_attr(target_arch = "wasm32", link_name = "adapter_close_badfd")] - fn adapter_close_badfd(fd: u32) -> bool; + fn adapter_close_badfd(fd: u32) -> wasi::Errno; } unsafe { let mut fd = 0; - assert!(adapter_open_badfd(&mut fd)); + assert_eq!(adapter_open_badfd(&mut fd), wasi::ERRNO_SUCCESS); assert_eq!(wasi::fd_close(fd), Err(wasi::ERRNO_BADF)); @@ -41,6 +41,6 @@ fn main() { Err(wasi::ERRNO_BADF) ); - assert!(adapter_close_badfd(fd)); + assert_eq!(adapter_close_badfd(fd), wasi::ERRNO_SUCCESS); } } diff --git a/crates/wasi-preview1-component-adapter/src/lib.rs b/crates/wasi-preview1-component-adapter/src/lib.rs index 59561f3ef150..8ef496d56441 100644 --- a/crates/wasi-preview1-component-adapter/src/lib.rs +++ b/crates/wasi-preview1-component-adapter/src/lib.rs @@ -152,17 +152,17 @@ impl TrappingUnwrap for Result { /// from WASI Preview 1 to Preview 2. It will use this function to reserve /// descriptors for its own use, valid only for use with libc functions. #[no_mangle] -pub unsafe extern "C" fn adapter_open_badfd(fd: *mut u32) -> bool { +pub unsafe extern "C" fn adapter_open_badfd(fd: *mut u32) -> Errno { State::with(|state| { *fd = state.descriptors_mut().open(Descriptor::Bad)?; Ok(()) - }) == wasi::ERRNO_SUCCESS + }) } /// Close a descriptor previously opened using `adapter_open_badfd`. #[no_mangle] -pub unsafe extern "C" fn adapter_close_badfd(fd: u32) -> bool { - State::with(|state| state.descriptors_mut().close(fd)) == wasi::ERRNO_SUCCESS +pub unsafe extern "C" fn adapter_close_badfd(fd: u32) -> Errno { + State::with(|state| state.descriptors_mut().close(fd)) } #[no_mangle]