Fix a "trampoline missing" panic with components (#4296)

One test case I wrote recently was to import a lowered function into a
wasm module and then immediately export it. This previously didn't work
because trampoline lookup would fail as the original
`VMCallerCheckedAnyfunc` function pointer points into the
`trampoline_obj` of a component which wasn't registered with the
`ModuleRegistry`. This plumbs through the necessary configuration to get
that all hooked up.
This commit is contained in:
Alex Crichton
2022-06-23 09:41:03 -05:00
committed by GitHub
parent 6778b4fce2
commit 445cc87a06
7 changed files with 204 additions and 28 deletions

View File

@@ -614,3 +614,50 @@ fn bad_import_alignment() -> Result<()> {
assert!(trap.to_string().contains("pointer not aligned"), "{}", trap);
Ok(())
}
#[test]
fn no_actual_wasm_code() -> Result<()> {
let component = r#"
(component
(import "f" (func $f))
(core func $f_lower
(canon lower (func $f))
)
(core module $m
(import "" "" (func $f))
(export "f" (func $f))
)
(core instance $i (instantiate $m
(with "" (instance
(export "" (func $f_lower))
))
))
(func (export "thunk")
(canon lift
(core func $i "f")
)
)
)
"#;
let engine = super::engine();
let component = Component::new(&engine, component)?;
let mut store = Store::new(&engine, 0);
let mut linker = Linker::new(&engine);
linker
.root()
.func_wrap("f", |mut store: StoreContextMut<'_, u32>| -> Result<()> {
*store.data_mut() += 1;
Ok(())
})?;
let instance = linker.instantiate(&mut store, &component)?;
let thunk = instance.get_typed_func::<(), (), _>(&mut store, "thunk")?;
assert_eq!(*store.data(), 0);
thunk.call(&mut store, ())?;
assert_eq!(*store.data(), 1);
Ok(())
}