Improve panics/traps from imported functions (#857)
* Improve panics/traps from imported functions This commit performs a few refactorings and fixes a bug as well. The changes here are: * The `thread_local!` in the `wasmtime` crate for trap information is removed. The thread local in the `wasmtime_runtime` crate is now leveraged to transmit trap information. * Panics in user-provided functions are now caught explicitly to be carried across JIT code manually. Getting Rust panics unwinding through JIT code is pretty likely to be super tricky and difficult to do, so in the meantime we can get by with catching panics and resuming the panic once we've resumed in Rust code. * Various take/record trap apis have all been removed in favor of working directly with `Trap` objects, where the internal trap object has been expanded slightly to encompass user-provided errors as well. This borrows a bit #839 and otherwise will... Closes #848 * Rename `r#return` to `ret`
This commit is contained in:
@@ -33,7 +33,24 @@ impl Trap {
|
||||
}
|
||||
|
||||
pub(crate) fn from_jit(jit: wasmtime_runtime::Trap) -> Self {
|
||||
Trap::new_with_trace(jit.to_string(), jit.backtrace)
|
||||
match jit {
|
||||
wasmtime_runtime::Trap::User(error) => {
|
||||
// Since we're the only one using the wasmtime internals (in
|
||||
// theory) we should only see user errors which were originally
|
||||
// created from our own `Trap` type (see the trampoline module
|
||||
// with functions).
|
||||
//
|
||||
// If this unwrap trips for someone we'll need to tweak the
|
||||
// return type of this function to probably be `anyhow::Error`
|
||||
// or something like that.
|
||||
*error
|
||||
.downcast()
|
||||
.expect("only `Trap` user errors are supported")
|
||||
}
|
||||
wasmtime_runtime::Trap::Wasm { desc, backtrace } => {
|
||||
Trap::new_with_trace(desc.to_string(), backtrace)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn new_with_trace(message: String, native_trace: Backtrace) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user