Refactor the internals of traps in wasmtime_runtime (#4326)
This commit is a small refactoring of `wasmtime_runtime::Trap` and various internals. The `Trap` structure is now a reason plus backtrace, and the old `Trap` enum is mostly in `TrapReason` now. Additionally all `Trap`-returning methods of `wasmtime_runtime` are changed to returning a `TrapCode` to indicate that they never capture a backtrace. Finally the `UnwindReason` internally now no longer duplicates the trap reasons, instead only having two variants of "panic" and "trap". The motivation for this commit is mostly just cleaning up trap internals and removing the need for methods like `wasmtime_runtime::Trap::insert_backtrace` to leave it only happening at the `wasmtime` layer.
This commit is contained in:
@@ -464,7 +464,7 @@ impl Table {
|
||||
let table = Table::from_wasmtime_table(wasmtime_export, store);
|
||||
(*table.wasmtime_table(store, std::iter::empty()))
|
||||
.fill(0, init, ty.minimum())
|
||||
.map_err(Trap::from_runtime)?;
|
||||
.map_err(|c| Trap::new_wasm(c, None))?;
|
||||
|
||||
Ok(table)
|
||||
}
|
||||
@@ -653,7 +653,7 @@ impl Table {
|
||||
let src_table = src_table.wasmtime_table(store, src_range);
|
||||
unsafe {
|
||||
runtime::Table::copy(dst_table, src_table, dst_index, src_index, len)
|
||||
.map_err(Trap::from_runtime)?;
|
||||
.map_err(|c| Trap::new_wasm(c, None))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -681,7 +681,9 @@ impl Table {
|
||||
|
||||
let table = self.wasmtime_table(store, std::iter::empty());
|
||||
unsafe {
|
||||
(*table).fill(dst, val, len).map_err(Trap::from_runtime)?;
|
||||
(*table)
|
||||
.fill(dst, val, len)
|
||||
.map_err(|c| Trap::new_wasm(c, None))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -322,7 +322,7 @@ impl Instance {
|
||||
)
|
||||
.map_err(|e| -> Error {
|
||||
match e {
|
||||
InstantiationError::Trap(trap) => Trap::from_runtime(trap).into(),
|
||||
InstantiationError::Trap(trap) => Trap::new_wasm(trap, None).into(),
|
||||
other => other.into(),
|
||||
}
|
||||
})?;
|
||||
|
||||
@@ -218,15 +218,16 @@ impl Trap {
|
||||
|
||||
#[cold] // see Trap::new
|
||||
pub(crate) fn from_runtime(runtime_trap: wasmtime_runtime::Trap) -> Self {
|
||||
match runtime_trap {
|
||||
wasmtime_runtime::Trap::User { error, backtrace } => {
|
||||
let wasmtime_runtime::Trap { reason, backtrace } = runtime_trap;
|
||||
match reason {
|
||||
wasmtime_runtime::TrapReason::User(error) => {
|
||||
let trap = Trap::from(error);
|
||||
if let Some(backtrace) = backtrace {
|
||||
trap.record_backtrace(TrapBacktrace::new(backtrace, None));
|
||||
}
|
||||
trap
|
||||
}
|
||||
wasmtime_runtime::Trap::Jit { pc, backtrace } => {
|
||||
wasmtime_runtime::TrapReason::Jit(pc) => {
|
||||
let code = GlobalModuleRegistry::with(|modules| {
|
||||
modules
|
||||
.lookup_trap_code(pc)
|
||||
@@ -235,14 +236,11 @@ impl Trap {
|
||||
let backtrace = backtrace.map(|bt| TrapBacktrace::new(bt, Some(pc)));
|
||||
Trap::new_wasm(code, backtrace)
|
||||
}
|
||||
wasmtime_runtime::Trap::Wasm {
|
||||
trap_code,
|
||||
backtrace,
|
||||
} => {
|
||||
wasmtime_runtime::TrapReason::Wasm(trap_code) => {
|
||||
let backtrace = backtrace.map(|bt| TrapBacktrace::new(bt, None));
|
||||
Trap::new_wasm(trap_code, backtrace)
|
||||
}
|
||||
wasmtime_runtime::Trap::OOM { backtrace } => {
|
||||
wasmtime_runtime::TrapReason::OOM => {
|
||||
let reason = TrapReason::Message("out of memory".to_string());
|
||||
let backtrace = backtrace.map(|bt| TrapBacktrace::new(bt, None));
|
||||
Trap::new_with_trace(reason, backtrace)
|
||||
|
||||
Reference in New Issue
Block a user