alexcrichton opened Issue #1479:
Currently in the
wasmtimecrate aModulewill dynamically register its unwinding information in a global which is unregistered when a module is dropped. This global is used when inspecting a native backtrace to figure out which frames are wasm frames and which frames are native frames.Unfortunately though instances and their exports can still be usable after a
Moduleis dropped. For example you can continue to use aFuncafter theInstanceandModuleare dropped. This means, though, that traps aren't properly symbolicated and resolved to wasm modules after theModuleis dropped though.To fix this I think we'll need to tie the trap info registration to the
wasmtime_runtime::InstanceHandlesomehow rather than theModule.
sunfishcode commented on Issue #1479:
It doesn't seem safe to use a
Funcafter its associatedInstancehas been dropped in general -- itsvmctxparameter would dangle and any reference to memories, tables, or even imports would be unsafe. In what context does this come up?
alexcrichton commented on Issue #1479:
This program shows the error:
use wasmtime::*; fn main() -> anyhow::Result<()> { let store = Store::default(); let module = Module::new(&store, r#"(func (export "foo") unreachable)"#)?; let instance = Instance::new(&module, &[])?; let func = instance.exports()[0].func().unwrap().clone(); println!("asserting before we drop modules"); assert_trap(func.call(&[]).unwrap_err().downcast()?); drop((instance, module)); println!("asserting after drop"); assert_trap(func.call(&[]).unwrap_err().downcast()?); Ok(()) } fn assert_trap(t: Trap) { assert_eq!(t.trace().len(), 1); assert_eq!(t.trace()[0].func_index(), 0); }the first assertion there passes but the second fails.
We keep an
InstanceHandleinside ofFuncwhich keeps the actual underlying instance alive even after you drop theInstancewhich keeps it at least memory safe.
alexcrichton closed Issue #1479:
Currently in the
wasmtimecrate aModulewill dynamically register its unwinding information in a global which is unregistered when a module is dropped. This global is used when inspecting a native backtrace to figure out which frames are wasm frames and which frames are native frames.Unfortunately though instances and their exports can still be usable after a
Moduleis dropped. For example you can continue to use aFuncafter theInstanceandModuleare dropped. This means, though, that traps aren't properly symbolicated and resolved to wasm modules after theModuleis dropped though.To fix this I think we'll need to tie the trap info registration to the
wasmtime_runtime::InstanceHandlesomehow rather than theModule.
Last updated: Dec 13 2025 at 19:03 UTC