alexcrichton opened Issue #1479:
Currently in the
wasmtime
crate aModule
will 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
Module
is dropped. For example you can continue to use aFunc
after theInstance
andModule
are dropped. This means, though, that traps aren't properly symbolicated and resolved to wasm modules after theModule
is dropped though.To fix this I think we'll need to tie the trap info registration to the
wasmtime_runtime::InstanceHandle
somehow rather than theModule
.
sunfishcode commented on Issue #1479:
It doesn't seem safe to use a
Func
after its associatedInstance
has been dropped in general -- itsvmctx
parameter 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
InstanceHandle
inside ofFunc
which keeps the actual underlying instance alive even after you drop theInstance
which keeps it at least memory safe.
alexcrichton closed Issue #1479:
Currently in the
wasmtime
crate aModule
will 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
Module
is dropped. For example you can continue to use aFunc
after theInstance
andModule
are dropped. This means, though, that traps aren't properly symbolicated and resolved to wasm modules after theModule
is dropped though.To fix this I think we'll need to tie the trap info registration to the
wasmtime_runtime::InstanceHandle
somehow rather than theModule
.
Last updated: Nov 22 2024 at 16:03 UTC