Fixes #2418: Enhance wiggle to generate its UserErrorConverstion trait with a function that returns Result<abi_err, String> (#2419)
* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns a Result<abi_err, String>. This enhancement allows hostcall implementations using wiggle to return an actionable error to the instance (the abi_err) or to terminate the instance using the String as fatal error information. * Enhance wiggle to generate its UserErrorConverstion trait with a function that returns a Result<abi_err, String>. This enhancement allows hostcall implementations using wiggle to return an actionable error to the instance (the abi_err) or to terminate the instance using the String as fatal error information. * Enhance the wiggle/wasmtime integration to leverage new work in ab7e9c6. Hostcall implementations generated by wiggle now return an Result<abi_error, Trap>. As a result, hostcalls experiencing fatal errors may trap, thereby terminating the wasmtime instance. This enhancement has been performed for both wasi snapshot1 and wasi snapshot0. * Update wasi-nn crate to reflect enhancement in issue #2418. * Update wiggle test-helpers for wiggle enhancement made in issue #2418. * Address PR feedback; omit verbose return statement. * Address PR feedback; manually format within a proc macro. * Address PR feedback; manually format proc macro. * Restore return statements to wasi.rs. * Restore return statements in funcs.rs. * Address PR feedback; omit TODO and fix formatting. * Ok-wrap error type in assert statement.
This commit is contained in:
committed by
GitHub
parent
128c3bd749
commit
b06ed39c1e
@@ -185,7 +185,7 @@ fn generate_func(
|
||||
witx::CoreParamSignifies::Value(atom) => names.atom_type(atom),
|
||||
_ => unreachable!("coretype ret should always be passed by value"),
|
||||
};
|
||||
(quote! { #ret_ty }, quote! { return e.into(); })
|
||||
(quote! { #ret_ty }, quote! { return Ok(e.into()); })
|
||||
} else {
|
||||
(
|
||||
quote! {()},
|
||||
@@ -199,7 +199,7 @@ fn generate_func(
|
||||
let my_cx = cx.clone();
|
||||
let #name_ident = wasmtime::Func::wrap(
|
||||
store,
|
||||
move |caller: wasmtime::Caller<'_> #(,#arg_decls)*| -> #ret_ty {
|
||||
move |caller: wasmtime::Caller<'_> #(,#arg_decls)*| -> Result<#ret_ty, wasmtime::Trap> {
|
||||
unsafe {
|
||||
let mem = match caller.get_export("memory") {
|
||||
Some(wasmtime::Extern::Memory(m)) => m,
|
||||
@@ -210,11 +210,15 @@ fn generate_func(
|
||||
}
|
||||
};
|
||||
let mem = #runtime::WasmtimeGuestMemory::new(mem);
|
||||
#target_module::#name_ident(
|
||||
let result = #target_module::#name_ident(
|
||||
&mut my_cx.borrow_mut(),
|
||||
&mem,
|
||||
#(#arg_names),*
|
||||
)
|
||||
);
|
||||
match result {
|
||||
Ok(r) => {return Ok(r.into());},
|
||||
Err(err) => { return Err(wasmtime::Trap::new(err)); },
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user