Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a panic with Func::new and reference types #2039

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/wasmtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ impl Config {
.finish(settings::Flags::new(self.flags.clone()))
}

pub(crate) fn target_isa_with_reference_types(&self) -> Box<dyn TargetIsa> {
let mut flags = self.flags.clone();
flags.set("enable_safepoints", "true").unwrap();
self.isa_flags.clone().finish(settings::Flags::new(flags))
}

pub(crate) fn validator(&self) -> Validator {
let mut ret = Validator::new();
ret.wasm_threads(self.wasm_threads)
Expand Down
5 changes: 4 additions & 1 deletion crates/wasmtime/src/trampoline/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ pub fn create_handle_with_function(
func: Box<dyn Fn(*mut VMContext, *mut u128) -> Result<(), Trap>>,
store: &Store,
) -> Result<(StoreInstanceHandle, VMTrampoline)> {
let isa = store.engine().config().target_isa();
// Note that we specifically enable reference types here in our ISA because
// `Func::new` is intended to be infallible, but our signature may use
// reference types which requires safepoints.
let isa = store.engine().config().target_isa_with_reference_types();

let pointer_type = isa.pointer_type();
let sig = ft.get_wasmtime_signature(pointer_type);
Expand Down
15 changes: 15 additions & 0 deletions tests/all/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,18 @@ fn pass_cross_store_arg() -> anyhow::Result<()> {

Ok(())
}

#[test]
fn externref_signature_no_reference_types() -> anyhow::Result<()> {
let store = Store::default();
Func::wrap(&store, |_: Option<Func>| {});
Func::new(
&store,
FuncType::new(
Box::new([ValType::FuncRef, ValType::ExternRef]),
Box::new([ValType::FuncRef, ValType::ExternRef]),
),
|_, _, _| Ok(()),
);
Ok(())
}