Stream: git-wasmtime

Topic: wasmtime / Issue #1479 Trap symbolication doesn't work af...


view this post on Zulip Wasmtime GitHub notifications bot (Apr 07 2020 at 17:21):

alexcrichton opened Issue #1479:

Currently in the wasmtime crate a Module 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 a Func after the Instance and Module are dropped. This means, though, that traps aren't properly symbolicated and resolved to wasm modules after the Module 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 the Module.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 07 2020 at 19:28):

sunfishcode commented on Issue #1479:

It doesn't seem safe to use a Func after its associated Instance has been dropped in general -- its vmctx parameter would dangle and any reference to memories, tables, or even imports would be unsafe. In what context does this come up?

view this post on Zulip Wasmtime GitHub notifications bot (Apr 07 2020 at 21:19):

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 of Func which keeps the actual underlying instance alive even after you drop the Instance which keeps it at least memory safe.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 16 2020 at 19:00):

alexcrichton closed Issue #1479:

Currently in the wasmtime crate a Module 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 a Func after the Instance and Module are dropped. This means, though, that traps aren't properly symbolicated and resolved to wasm modules after the Module 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 the Module.


Last updated: Nov 22 2024 at 16:03 UTC