diff --git a/Cargo.lock b/Cargo.lock index 2d007c5d64..4a7e0d489f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3073,7 +3073,7 @@ dependencies = [ [[package]] name = "witx" -version = "0.8.7" +version = "0.8.8" dependencies = [ "anyhow", "diff", diff --git a/crates/wasi-common/WASI b/crates/wasi-common/WASI index 71f0425147..8deb71ddd0 160000 --- a/crates/wasi-common/WASI +++ b/crates/wasi-common/WASI @@ -1 +1 @@ -Subproject commit 71f042514728e425a9b1b251c7f6daaa44301f4a +Subproject commit 8deb71ddd0955101cb69333b08284e7b01775928 diff --git a/crates/wasi-common/src/error.rs b/crates/wasi-common/src/error.rs index 282a46734f..2b0fb5b7ac 100644 --- a/crates/wasi-common/src/error.rs +++ b/crates/wasi-common/src/error.rs @@ -17,6 +17,10 @@ pub enum Error { #[error("GetRandom: {0}")] GetRandom(#[from] getrandom::Error), + /// Some corners of the WASI standard are unsupported. + #[error("Unsupported: {0}")] + Unsupported(&'static str), + /// The host OS may return an io error that doesn't match one of the /// wasi errno variants we expect. We do not expose the details of this /// error to the user. diff --git a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs index b46bf41ec9..ae589c270d 100644 --- a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs +++ b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs @@ -714,14 +714,17 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { Ok(nevents) } - fn proc_exit(&self, _rval: types::Exitcode) -> std::result::Result<(), ()> { - // proc_exit is special in that it's expected to unwind the stack, which - // typically requires runtime-specific logic. - unimplemented!("runtimes are expected to override this implementation") + fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap { + // Check that the status is within WASI's range. + if status < 126 { + wiggle::Trap::I32Exit(status as i32) + } else { + wiggle::Trap::String("exit with invalid exit status outside of [0..126)".to_owned()) + } } fn proc_raise(&self, _sig: types::Signal) -> Result<()> { - unimplemented!("proc_raise") + Err(Error::Unsupported("proc_raise")) } fn sched_yield(&self) -> Result<()> { @@ -741,7 +744,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { _ri_data: &types::IovecArray<'_>, _ri_flags: types::Riflags, ) -> Result<(types::Size, types::Roflags)> { - unimplemented!("sock_recv") + Err(Error::Unsupported("sock_recv")) } fn sock_send( @@ -750,11 +753,11 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { _si_data: &types::CiovecArray<'_>, _si_flags: types::Siflags, ) -> Result { - unimplemented!("sock_send") + Err(Error::Unsupported("sock_send")) } fn sock_shutdown(&self, _fd: types::Fd, _how: types::Sdflags) -> Result<()> { - unimplemented!("sock_shutdown") + Err(Error::Unsupported("sock_shutdown")) } } @@ -801,7 +804,7 @@ impl WasiCtx { Err(error) => { events.push(types::Event { userdata: subscription.userdata, - error: error.into(), + error: error.try_into().expect("non-trapping error"), type_: types::Eventtype::FdRead, fd_readwrite: types::EventFdReadwrite { nbytes: 0, @@ -827,7 +830,7 @@ impl WasiCtx { Err(error) => { events.push(types::Event { userdata: subscription.userdata, - error: error.into(), + error: error.try_into().expect("non-trapping error"), type_: types::Eventtype::FdWrite, fd_readwrite: types::EventFdReadwrite { nbytes: 0, diff --git a/crates/wasi-common/src/snapshots/wasi_unstable.rs b/crates/wasi-common/src/snapshots/wasi_unstable.rs index 6c05c21427..dbdef63e42 100644 --- a/crates/wasi-common/src/snapshots/wasi_unstable.rs +++ b/crates/wasi-common/src/snapshots/wasi_unstable.rs @@ -23,15 +23,16 @@ impl types::GuestErrorConversion for WasiCtx { } impl types::UserErrorConversion for WasiCtx { - fn errno_from_error(&self, e: Error) -> Result { + fn errno_from_error(&self, e: Error) -> Result { tracing::debug!("Error: {:?}", e); - Ok(e.into()) + e.try_into() } } -impl From for Errno { - fn from(e: Error) -> Errno { - types_new::Errno::from(e).into() +impl TryFrom for Errno { + type Error = wiggle::Trap; + fn try_from(e: Error) -> Result { + Ok(types_new::Errno::try_from(e)?.into()) } } @@ -346,7 +347,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx { Ok(nevents) } - fn proc_exit(&self, rval: Exitcode) -> Result<(), ()> { + fn proc_exit(&self, rval: Exitcode) -> wiggle::Trap { WasiSnapshotPreview1::proc_exit(self, rval) } diff --git a/crates/wasi-common/src/sys/unix/poll.rs b/crates/wasi-common/src/sys/unix/poll.rs index 059391ab96..2b45c7110f 100644 --- a/crates/wasi-common/src/sys/unix/poll.rs +++ b/crates/wasi-common/src/sys/unix/poll.rs @@ -117,7 +117,7 @@ fn handle_fd_event( let output_event = if revents.contains(PollFlags::POLLNVAL) { Event { userdata: fd_event.userdata, - error: Error::Badf.into(), + error: Error::Badf.try_into().unwrap(), type_: fd_event.r#type, fd_readwrite: EventFdReadwrite { nbytes: 0, @@ -127,7 +127,7 @@ fn handle_fd_event( } else if revents.contains(PollFlags::POLLERR) { Event { userdata: fd_event.userdata, - error: Error::Io.into(), + error: Error::Io.try_into().unwrap(), type_: fd_event.r#type, fd_readwrite: EventFdReadwrite { nbytes: 0, diff --git a/crates/wasi-common/src/wasi.rs b/crates/wasi-common/src/wasi.rs index 214057e766..978d45d113 100644 --- a/crates/wasi-common/src/wasi.rs +++ b/crates/wasi-common/src/wasi.rs @@ -1,4 +1,5 @@ use crate::{Error, WasiCtx}; +use std::convert::{TryFrom, TryInto}; use tracing::debug; wiggle::from_witx!({ @@ -23,47 +24,51 @@ impl types::GuestErrorConversion for WasiCtx { } impl types::UserErrorConversion for WasiCtx { - fn errno_from_error(&self, e: Error) -> Result { + fn errno_from_error(&self, e: Error) -> Result { debug!("Error: {:?}", e); - Ok(e.into()) + e.try_into() } } -impl From for Errno { - fn from(e: Error) -> Errno { +impl TryFrom for Errno { + type Error = wiggle::Trap; + fn try_from(e: Error) -> Result { match e { - Error::Guest(e) => e.into(), - Error::TryFromInt(_) => Errno::Overflow, - Error::Utf8(_) => Errno::Ilseq, - Error::UnexpectedIo(_) => Errno::Io, - Error::GetRandom(_) => Errno::Io, - Error::TooBig => Errno::TooBig, - Error::Acces => Errno::Acces, - Error::Badf => Errno::Badf, - Error::Busy => Errno::Busy, - Error::Exist => Errno::Exist, - Error::Fault => Errno::Fault, - Error::Fbig => Errno::Fbig, - Error::Ilseq => Errno::Ilseq, - Error::Inval => Errno::Inval, - Error::Io => Errno::Io, - Error::Isdir => Errno::Isdir, - Error::Loop => Errno::Loop, - Error::Mfile => Errno::Mfile, - Error::Mlink => Errno::Mlink, - Error::Nametoolong => Errno::Nametoolong, - Error::Nfile => Errno::Nfile, - Error::Noent => Errno::Noent, - Error::Nomem => Errno::Nomem, - Error::Nospc => Errno::Nospc, - Error::Notdir => Errno::Notdir, - Error::Notempty => Errno::Notempty, - Error::Notsup => Errno::Notsup, - Error::Overflow => Errno::Overflow, - Error::Pipe => Errno::Pipe, - Error::Perm => Errno::Perm, - Error::Spipe => Errno::Spipe, - Error::Notcapable => Errno::Notcapable, + Error::Guest(e) => Ok(e.into()), + Error::TryFromInt(_) => Ok(Errno::Overflow), + Error::Utf8(_) => Ok(Errno::Ilseq), + Error::UnexpectedIo(_) => Ok(Errno::Io), + Error::GetRandom(_) => Ok(Errno::Io), + Error::TooBig => Ok(Errno::TooBig), + Error::Acces => Ok(Errno::Acces), + Error::Badf => Ok(Errno::Badf), + Error::Busy => Ok(Errno::Busy), + Error::Exist => Ok(Errno::Exist), + Error::Fault => Ok(Errno::Fault), + Error::Fbig => Ok(Errno::Fbig), + Error::Ilseq => Ok(Errno::Ilseq), + Error::Inval => Ok(Errno::Inval), + Error::Io => Ok(Errno::Io), + Error::Isdir => Ok(Errno::Isdir), + Error::Loop => Ok(Errno::Loop), + Error::Mfile => Ok(Errno::Mfile), + Error::Mlink => Ok(Errno::Mlink), + Error::Nametoolong => Ok(Errno::Nametoolong), + Error::Nfile => Ok(Errno::Nfile), + Error::Noent => Ok(Errno::Noent), + Error::Nomem => Ok(Errno::Nomem), + Error::Nospc => Ok(Errno::Nospc), + Error::Notdir => Ok(Errno::Notdir), + Error::Notempty => Ok(Errno::Notempty), + Error::Notsup => Ok(Errno::Notsup), + Error::Overflow => Ok(Errno::Overflow), + Error::Pipe => Ok(Errno::Pipe), + Error::Perm => Ok(Errno::Perm), + Error::Spipe => Ok(Errno::Spipe), + Error::Notcapable => Ok(Errno::Notcapable), + Error::Unsupported(feature) => { + Err(wiggle::Trap::String(format!("unsupported: {}", feature))) + } } } } @@ -80,8 +85,8 @@ impl From for Errno { PtrBorrowed { .. } => Self::Fault, InvalidUtf8 { .. } => Self::Ilseq, TryFromIntError { .. } => Self::Overflow, - InFunc { .. } => Self::Inval, - InDataField { .. } => Self::Inval, + InFunc { err, .. } => Errno::from(*err), + InDataField { err, .. } => Errno::from(*err), SliceLengthsDiffer { .. } => Self::Fault, BorrowCheckerOutOfHandles { .. } => Self::Fault, } diff --git a/crates/wasi-nn/src/witx.rs b/crates/wasi-nn/src/witx.rs index 6f7394e0b2..b686fcd091 100644 --- a/crates/wasi-nn/src/witx.rs +++ b/crates/wasi-nn/src/witx.rs @@ -22,7 +22,7 @@ impl types::GuestErrorConversion for WasiNnCtx { } impl<'a> types::UserErrorConversion for WasiNnCtx { - fn errno_from_wasi_nn_error(&self, e: WasiNnError) -> Result { + fn errno_from_wasi_nn_error(&self, e: WasiNnError) -> Result { eprintln!("Host error: {:?}", e); match e { WasiNnError::OpenvinoError(_) => unimplemented!(), diff --git a/crates/wasi/src/lib.rs b/crates/wasi/src/lib.rs index ba4f7b6c2e..2276c1db2e 100644 --- a/crates/wasi/src/lib.rs +++ b/crates/wasi/src/lib.rs @@ -1,5 +1,3 @@ -use wasmtime::Trap; - pub mod old; pub use wasi_common::virtfs; @@ -26,12 +24,7 @@ modules. This structure exports all that various fields of the wasi instance as fields which can be used to implement your own instantiation logic, if necessary. Additionally [`Wasi::get_export`] can be used to do name-based resolution.", - // Don't use the wiggle generated code to implement proc_exit, we need - // to hook directly into the runtime there: - function_override: { - proc_exit => wasi_proc_exit - } - }, + } }, }); @@ -41,17 +34,3 @@ pub fn is_wasi_module(name: &str) -> bool { // trick. name.starts_with("wasi") } - -/// Implement the WASI `proc_exit` function. This function is implemented here -/// instead of in wasi-common so that we can use the runtime to perform an -/// unwind rather than exiting the host process. -fn wasi_proc_exit(status: i32) -> Result<(), Trap> { - // Check that the status is within WASI's range. - if status >= 0 && status < 126 { - Err(Trap::i32_exit(status)) - } else { - Err(Trap::new( - "exit with invalid exit status outside of [0..126)", - )) - } -} diff --git a/crates/wasi/src/old/snapshot_0.rs b/crates/wasi/src/old/snapshot_0.rs index 826acb995a..f71dee7cdd 100644 --- a/crates/wasi/src/old/snapshot_0.rs +++ b/crates/wasi/src/old/snapshot_0.rs @@ -1,8 +1,6 @@ pub use wasi_common::virtfs; pub use wasi_common::{WasiCtx, WasiCtxBuilder}; -use crate::wasi_proc_exit; - // Defines a `struct Wasi` with member fields and appropriate APIs for dealing // with all the various WASI exports. wasmtime_wiggle::wasmtime_integration!({ @@ -25,12 +23,7 @@ modules. This structure exports all that various fields of the wasi instance as fields which can be used to implement your own instantiation logic, if necessary. Additionally [`Wasi::get_export`] can be used to do name-based resolution.", - // Don't use the wiggle generated code to implement proc_exit, we need - // to hook directly into the runtime there: - function_override: { - proc_exit => wasi_proc_exit - } - }, + } }, }); diff --git a/crates/wiggle/README.md b/crates/wiggle/README.md index cc0fd88492..75eb498efc 100644 --- a/crates/wiggle/README.md +++ b/crates/wiggle/README.md @@ -5,3 +5,14 @@ invoked as a Rust procedural macro. Wiggle is not specialized to any particular WebAssembly runtime. It is usable in at least Wasmtime and Lucet. + +## Learning more + +Read the docs on [docs.rs](https://docs.rs/wiggle/). + +There are child crates for [integrating with Wasmtime](https://github.com/bytecodealliance/wasmtime/tree/main/crates/wiggle/wasmtime) and [Lucet](https://github.com/bytecodealliance/lucet/tree/main/lucet-wiggle). + +The [wasi-common crate](https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi-common) is implemented using Wiggle and the [wasmtime-wasi +crate](https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi) integrates wasi-common with the Wasmtime engine. + +Andrew Brown wrote a great [blog post](https://bytecodealliance.org/articles/implementing-wasi-nn-in-wasmtime) on using Wiggle with Wasmtime. diff --git a/crates/wiggle/generate/src/funcs.rs b/crates/wiggle/generate/src/funcs.rs index e6551b17dd..5cdf59eda0 100644 --- a/crates/wiggle/generate/src/funcs.rs +++ b/crates/wiggle/generate/src/funcs.rs @@ -36,12 +36,6 @@ pub fn define_func( witx::CoreParamSignifies::Value(atom) => names.atom_type(atom), _ => unreachable!("ret should always be passed by value"), } - } else if func.noreturn { - // Ideally we would return `quote!(!)` here, but, we'd have to change - // the error handling logic in all the marshalling code to never return, - // and instead provide some other way to bail to the context... - // noreturn func - unimplemented!("noreturn funcs not supported yet!") } else { quote!(()) }; @@ -174,25 +168,42 @@ pub fn define_func( let mod_name = &module.name.as_str(); let func_name = &func.name.as_str(); - quote!(pub fn #ident(#abi_args) -> Result<#abi_ret, String> { - let _span = #rt::tracing::span!( - #rt::tracing::Level::TRACE, - "wiggle abi", - module = #mod_name, - function = #func_name - ); - let _enter = _span.enter(); + if func.noreturn { + quote!(pub fn #ident(#abi_args) -> Result<#abi_ret, wiggle::Trap> { + let _span = #rt::tracing::span!( + #rt::tracing::Level::TRACE, + "wiggle abi", + module = #mod_name, + function = #func_name + ); + let _enter = _span.enter(); - #(#marshal_args)* - #(#marshal_rets_pre)* - #log_marshalled_args - let #trait_bindings = match #trait_name::#ident(ctx, #(#trait_args),*) { - Ok(#trait_bindings) => { #trait_rets }, - Err(e) => { #ret_err }, - }; - #(#marshal_rets_post)* - #success - }) + #(#marshal_args)* + #log_marshalled_args + let trap = #trait_name::#ident(ctx, #(#trait_args),*); + Err(trap) + }) + } else { + quote!(pub fn #ident(#abi_args) -> Result<#abi_ret, wiggle::Trap> { + let _span = #rt::tracing::span!( + #rt::tracing::Level::TRACE, + "wiggle abi", + module = #mod_name, + function = #func_name + ); + let _enter = _span.enter(); + + #(#marshal_args)* + #(#marshal_rets_pre)* + #log_marshalled_args + let #trait_bindings = match #trait_name::#ident(ctx, #(#trait_args),*) { + Ok(#trait_bindings) => { #trait_rets }, + Err(e) => { #ret_err }, + }; + #(#marshal_rets_post)* + #success + }) + } } fn marshal_arg( diff --git a/crates/wiggle/generate/src/lib.rs b/crates/wiggle/generate/src/lib.rs index 206ded711b..1ba4b6ebae 100644 --- a/crates/wiggle/generate/src/lib.rs +++ b/crates/wiggle/generate/src/lib.rs @@ -40,7 +40,7 @@ pub fn generate(doc: &witx::Document, names: &Names, errs: &ErrorTransform) -> T let abi_typename = names.type_ref(&errtype.abi_type(), anon_lifetime()); let user_typename = errtype.typename(); let methodname = names.user_error_conversion_method(&errtype); - quote!(fn #methodname(&self, e: super::#user_typename) -> Result<#abi_typename, String>;) + quote!(fn #methodname(&self, e: super::#user_typename) -> Result<#abi_typename, wiggle::Trap>;) }); let user_error_conversion = quote! { pub trait UserErrorConversion { diff --git a/crates/wiggle/generate/src/module_trait.rs b/crates/wiggle/generate/src/module_trait.rs index c73cd052bb..e42551a70b 100644 --- a/crates/wiggle/generate/src/module_trait.rs +++ b/crates/wiggle/generate/src/module_trait.rs @@ -48,28 +48,34 @@ pub fn define_module_trait(names: &Names, m: &Module, errxform: &ErrorTransform) }; quote!(#arg_name: #arg_type) }); - let rets = f - .results - .iter() - .skip(1) - .map(|ret| names.type_ref(&ret.tref, lifetime.clone())); - let err = f - .results - .get(0) - .map(|err_result| { - if let Some(custom_err) = errxform.for_abi_error(&err_result.tref) { - let tn = custom_err.typename(); - quote!(super::#tn) - } else { - names.type_ref(&err_result.tref, lifetime.clone()) - } - }) - .unwrap_or(quote!(())); + + let result = if !f.noreturn { + let rets = f + .results + .iter() + .skip(1) + .map(|ret| names.type_ref(&ret.tref, lifetime.clone())); + let err = f + .results + .get(0) + .map(|err_result| { + if let Some(custom_err) = errxform.for_abi_error(&err_result.tref) { + let tn = custom_err.typename(); + quote!(super::#tn) + } else { + names.type_ref(&err_result.tref, lifetime.clone()) + } + }) + .unwrap_or(quote!(())); + quote!( Result<(#(#rets),*), #err> ) + } else { + quote!(wiggle::Trap) + }; if is_anonymous { - quote!(fn #funcname(&self, #(#args),*) -> Result<(#(#rets),*), #err>;) + quote!(fn #funcname(&self, #(#args),*) -> #result; ) } else { - quote!(fn #funcname<#lifetime>(&self, #(#args),*) -> Result<(#(#rets),*), #err>;) + quote!(fn #funcname<#lifetime>(&self, #(#args),*) -> #result;) } }); quote! { diff --git a/crates/wiggle/src/lib.rs b/crates/wiggle/src/lib.rs index 063ab5bd4b..102bcb0e7b 100644 --- a/crates/wiggle/src/lib.rs +++ b/crates/wiggle/src/lib.rs @@ -928,3 +928,16 @@ impl Pointee for str { <[u8]>::debug(pointer, f) } } + +/// 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 { + /// 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/test-helpers/examples/tracing.rs b/crates/wiggle/test-helpers/examples/tracing.rs index 3d08ec45e1..0f06e18509 100644 --- a/crates/wiggle/test-helpers/examples/tracing.rs +++ b/crates/wiggle/test-helpers/examples/tracing.rs @@ -36,7 +36,7 @@ impl_errno!(types::Errno, types::GuestErrorConversion); /// When the `errors` mapping in witx is non-empty, we need to impl the /// types::UserErrorConversion trait that wiggle generates from that mapping. impl<'a> types::UserErrorConversion for WasiCtx<'a> { - fn errno_from_rich_error(&self, e: RichError) -> Result { + fn errno_from_rich_error(&self, e: RichError) -> Result { wiggle::tracing::debug!( rich_error = wiggle::tracing::field::debug(&e), "error conversion" diff --git a/crates/wiggle/tests/errors.rs b/crates/wiggle/tests/errors.rs index a550da35bd..4252962469 100644 --- a/crates/wiggle/tests/errors.rs +++ b/crates/wiggle/tests/errors.rs @@ -34,7 +34,7 @@ mod convert_just_errno { /// When the `errors` mapping in witx is non-empty, we need to impl the /// types::UserErrorConversion trait that wiggle generates from that mapping. impl<'a> types::UserErrorConversion for WasiCtx<'a> { - fn errno_from_rich_error(&self, e: RichError) -> Result { + fn errno_from_rich_error(&self, e: RichError) -> Result { // WasiCtx can collect a Vec log so we can test this. We're // logging the Display impl that `thiserror::Error` provides us. self.log.borrow_mut().push(e.to_string()); @@ -115,8 +115,9 @@ mod convert_multiple_error_types { TooMuchCoffee(usize), } - // Just like the other error, except that we have a second errno type: - // trivial function. + // Just like the prior test, except that we have a second errno type. This should mean there + // are two functions in UserErrorConversion. + // Additionally, test that the function "baz" marked noreturn always returns a wiggle::Trap. wiggle::from_witx!({ witx_literal: " (typename $errno (enum u8 $ok $invalid_arg $picket_line)) @@ -127,7 +128,10 @@ mod convert_multiple_error_types { (result $err $errno)) (@interface func (export \"bar\") (param $drink u32) - (result $err $errno2))) + (result $err $errno2)) + (@interface func (export \"baz\") + (param $drink u32) + (@witx noreturn))) ", ctx: WasiCtx, errors: { errno => RichError, errno2 => AnotherRichError }, @@ -159,13 +163,13 @@ mod convert_multiple_error_types { // each member of the `errors` mapping. // Bodies elided. impl<'a> types::UserErrorConversion for WasiCtx<'a> { - fn errno_from_rich_error(&self, _e: RichError) -> Result { + fn errno_from_rich_error(&self, _e: RichError) -> Result { unimplemented!() } fn errno2_from_another_rich_error( &self, _e: AnotherRichError, - ) -> Result { + ) -> Result { unimplemented!() } } @@ -178,5 +182,8 @@ mod convert_multiple_error_types { fn bar(&self, _: u32) -> Result<(), AnotherRichError> { unimplemented!() } + fn baz(&self, _: u32) -> wiggle::Trap { + unimplemented!() + } } } diff --git a/crates/wiggle/wasmtime/macro/src/lib.rs b/crates/wiggle/wasmtime/macro/src/lib.rs index 095dcd16c5..b2e6303887 100644 --- a/crates/wiggle/wasmtime/macro/src/lib.rs +++ b/crates/wiggle/wasmtime/macro/src/lib.rs @@ -199,8 +199,9 @@ fn generate_func( #(#arg_names),* ); match result { - Ok(r) => {return Ok(r.into());}, - Err(err) => { return Err(wasmtime::Trap::new(err)); }, + Ok(r) => Ok(r.into()), + Err(wasmtime_wiggle::Trap::String(err)) => Err(wasmtime::Trap::new(err)), + Err(wasmtime_wiggle::Trap::I32Exit(err)) => Err(wasmtime::Trap::i32_exit(err)), } } } diff --git a/tests/wasm/exit125_wasi_snapshot0.wat b/tests/wasm/exit125_wasi_snapshot0.wat index 03e2ae9004..eeff9f5e0a 100644 --- a/tests/wasm/exit125_wasi_snapshot0.wat +++ b/tests/wasm/exit125_wasi_snapshot0.wat @@ -1,6 +1,7 @@ (module (import "wasi_unstable" "proc_exit" (func $__wasi_proc_exit (param i32))) + (memory (export "memory") 0) (func $_start (call $__wasi_proc_exit (i32.const 125)) ) diff --git a/tests/wasm/exit125_wasi_snapshot1.wat b/tests/wasm/exit125_wasi_snapshot1.wat index 6d2dbbfd38..3b8954c716 100644 --- a/tests/wasm/exit125_wasi_snapshot1.wat +++ b/tests/wasm/exit125_wasi_snapshot1.wat @@ -1,6 +1,7 @@ (module (import "wasi_snapshot_preview1" "proc_exit" (func $__wasi_proc_exit (param i32))) + (memory (export "memory") 0) (func $_start (call $__wasi_proc_exit (i32.const 125)) ) diff --git a/tests/wasm/exit126_wasi_snapshot0.wat b/tests/wasm/exit126_wasi_snapshot0.wat index 091e610011..ee54203048 100644 --- a/tests/wasm/exit126_wasi_snapshot0.wat +++ b/tests/wasm/exit126_wasi_snapshot0.wat @@ -1,6 +1,7 @@ (module (import "wasi_unstable" "proc_exit" (func $__wasi_proc_exit (param i32))) + (memory (export "memory") 0) (func $_start (call $__wasi_proc_exit (i32.const 126)) ) diff --git a/tests/wasm/exit126_wasi_snapshot1.wat b/tests/wasm/exit126_wasi_snapshot1.wat index e481533c59..bdf35b443b 100644 --- a/tests/wasm/exit126_wasi_snapshot1.wat +++ b/tests/wasm/exit126_wasi_snapshot1.wat @@ -1,6 +1,7 @@ (module (import "wasi_snapshot_preview1" "proc_exit" (func $__wasi_proc_exit (param i32))) + (memory (export "memory") 0) (func $_start (call $__wasi_proc_exit (i32.const 126)) ) diff --git a/tests/wasm/exit2_wasi_snapshot0.wat b/tests/wasm/exit2_wasi_snapshot0.wat index 244d7b6041..6149ae8719 100644 --- a/tests/wasm/exit2_wasi_snapshot0.wat +++ b/tests/wasm/exit2_wasi_snapshot0.wat @@ -1,6 +1,7 @@ (module (import "wasi_unstable" "proc_exit" (func $__wasi_proc_exit (param i32))) + (memory (export "memory") 0) (func $_start (call $__wasi_proc_exit (i32.const 2)) ) diff --git a/tests/wasm/exit2_wasi_snapshot1.wat b/tests/wasm/exit2_wasi_snapshot1.wat index 75f64407aa..5fe4df6409 100644 --- a/tests/wasm/exit2_wasi_snapshot1.wat +++ b/tests/wasm/exit2_wasi_snapshot1.wat @@ -1,6 +1,7 @@ (module (import "wasi_snapshot_preview1" "proc_exit" (func $__wasi_proc_exit (param i32))) + (memory (export "memory") 0) (func $_start (call $__wasi_proc_exit (i32.const 2)) ) diff --git a/tests/wasm/exit_with_saved_fprs.wat b/tests/wasm/exit_with_saved_fprs.wat index 6149c6bdf2..41d6039c49 100644 --- a/tests/wasm/exit_with_saved_fprs.wat +++ b/tests/wasm/exit_with_saved_fprs.wat @@ -3,6 +3,7 @@ (type (func (param i32))) (import "wasi_snapshot_preview1" "proc_exit" (func (type 0))) + (memory (export "memory") 0) (func $exit (param i32) local.get 0