diff --git a/Cargo.lock b/Cargo.lock index dc2ec4c24e..742a77fcc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2908,7 +2908,7 @@ dependencies = [ [[package]] name = "witx" -version = "0.8.7" +version = "0.8.8" dependencies = [ "anyhow", "diff", diff --git a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs index 3d905159c7..74a39769bc 100644 --- a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs +++ b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs @@ -717,7 +717,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap { // Check that the status is within WASI's range. if status < 126 { - wiggle::Trap::I32(status as i32) + wiggle::Trap::I32Exit(status as i32) } else { wiggle::Trap::String("exit with invalid exit status outside of [0..126)".to_owned()) } diff --git a/crates/wiggle/src/lib.rs b/crates/wiggle/src/lib.rs index 47b5c681e5..102bcb0e7b 100644 --- a/crates/wiggle/src/lib.rs +++ b/crates/wiggle/src/lib.rs @@ -929,8 +929,15 @@ impl Pointee for str { } } -#[derive(Debug, Clone)] +/// A runtime-independent way for Wiggle to terminate WebAssembly execution. +/// Functions that are marked `(@witx noreturn)` will always return a Trap. +/// Other functions that want to Trap can do so via their `UserErrorConversion` +/// trait, which transforms the user's own error type into a `Result`. +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Trap { - I32(i32), + /// A Trap which indicates an i32 (posix-style) exit code. Runtimes may have a + /// special way of dealing with this for WASI embeddings and otherwise. + I32Exit(i32), + /// Any other Trap is just an unstructured String, for reporting and debugging. String(String), } diff --git a/crates/wiggle/wasmtime/macro/src/lib.rs b/crates/wiggle/wasmtime/macro/src/lib.rs index 582a471f31..b2e6303887 100644 --- a/crates/wiggle/wasmtime/macro/src/lib.rs +++ b/crates/wiggle/wasmtime/macro/src/lib.rs @@ -201,7 +201,7 @@ fn generate_func( match result { Ok(r) => Ok(r.into()), Err(wasmtime_wiggle::Trap::String(err)) => Err(wasmtime::Trap::new(err)), - Err(wasmtime_wiggle::Trap::I32(err)) => Err(wasmtime::Trap::i32_exit(err)), + Err(wasmtime_wiggle::Trap::I32Exit(err)) => Err(wasmtime::Trap::i32_exit(err)), } } }