Skip to content
Open
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
15 changes: 12 additions & 3 deletions crates/wasmtime/src/runtime/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2055,11 +2055,20 @@ impl StoreOpaque {
// If this loop becomes hot in the future, however, it should be
// possible to precompute maps about linear memories in a store and have
// a quicker lookup.
let mut fault = None;
//
// A shared memory can be defined by more than one instance in a store,
// for example when it's imported through the single-memory instance
// that `SharedMemory::vmimport` creates. Each of those instances
// reports the same fault, so only assert that the faulting address
// doesn't belong to two different memories. The memory size isn't
// compared because a shared memory can grow concurrently.
let mut fault: Option<vm::WasmFault> = None;
for (_, instance) in self.instances.iter() {
if let Some(f) = instance.handle.get().wasm_fault(addr) {
assert!(fault.is_none());
fault = Some(f);
match &fault {
Some(prev) => assert_eq!(prev.wasm_address, f.wasm_address),
None => fault = Some(f),
}
}
}
if fault.is_some() {
Expand Down
10 changes: 10 additions & 0 deletions tests/misc_testsuite/threads/shared-memory-imported-oob.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;;! threads = true

;; A shared memory defined in one instance and imported into another must
;; still report an out-of-bounds access as a trap.
(module $a
(memory (export "m") 1 1 shared)
(func (export "ld") (param i32) (result i32) (i32.load (local.get 0))))
(register "a" $a)
(module $b (import "a" "m" (memory 1 1 shared)))
(assert_trap (invoke $a "ld" (i32.const 0x10000)) "out of bounds memory access")
Loading