Skip to content

Commit 132a490

Browse files
authored
Expose GC refs to Wasm in gc_alloc_raw libcall (#10322)
* Expose GC refs to Wasm in `gc_alloc_raw` libcall As we are returning a GC reference to Wasm, we need to mark that GC reference as exposed to Wasm. Fixes #9669 * miri ignore test that calls wasm and therefore can't run in miri
1 parent 6336065 commit 132a490

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

crates/wasmtime/src/runtime/vm/libcalls.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,14 @@ unsafe fn gc_alloc_raw(
529529
}
530530
};
531531

532-
Ok(gc_ref.as_raw_u32())
532+
let raw = gc_ref.as_raw_u32();
533+
534+
store
535+
.store_opaque_mut()
536+
.unwrap_gc_store_mut()
537+
.expose_gc_ref_to_wasm(gc_ref);
538+
539+
Ok(raw)
533540
}
534541

535542
// Intern a `funcref` into the GC heap, returning its `FuncRefTableId`.

tests/all/gc.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,3 +1003,53 @@ fn ref_matches() -> Result<()> {
10031003

10041004
Ok(())
10051005
}
1006+
1007+
#[test]
1008+
#[cfg_attr(miri, ignore)]
1009+
fn issue_9669() -> Result<()> {
1010+
let _ = env_logger::try_init();
1011+
1012+
let mut config = Config::new();
1013+
config.wasm_function_references(true);
1014+
config.wasm_gc(true);
1015+
config.collector(Collector::DeferredReferenceCounting);
1016+
1017+
let engine = Engine::new(&config)?;
1018+
1019+
let module = Module::new(
1020+
&engine,
1021+
r#"
1022+
(module
1023+
(type $empty (struct))
1024+
(type $thing (struct
1025+
(field $field1 (ref $empty))
1026+
(field $field2 (ref $empty))
1027+
))
1028+
1029+
(func (export "run")
1030+
(local $object (ref $thing))
1031+
1032+
struct.new $empty
1033+
struct.new $empty
1034+
struct.new $thing
1035+
1036+
local.tee $object
1037+
struct.get $thing $field1
1038+
drop
1039+
1040+
local.get $object
1041+
struct.get $thing $field2
1042+
drop
1043+
)
1044+
)
1045+
"#,
1046+
)?;
1047+
1048+
let mut store = Store::new(&engine, ());
1049+
let instance = Instance::new(&mut store, &module, &[])?;
1050+
1051+
let func = instance.get_typed_func::<(), ()>(&mut store, "run")?;
1052+
func.call(&mut store, ())?;
1053+
1054+
Ok(())
1055+
}

0 commit comments

Comments
 (0)