Skip to content

Commit c7a6976

Browse files
authored
Trap on atomic.wait on an unshared memory (#8497)
This matches VM behavior.
1 parent 7c2fd23 commit c7a6976

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/wasm-interpreter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,6 +4213,9 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
42134213
VISIT(timeout, curr->timeout)
42144214
auto bytes = curr->expectedType.getByteSize();
42154215
auto info = getMemoryInstanceInfo(curr->memory);
4216+
if (!info.instance->wasm.getMemory(info.name)->shared) {
4217+
trap("cannot atomic.wait a non-shared memory");
4218+
}
42164219
auto memorySizeBytes = info.instance->getMemorySizeBytes(info.name);
42174220
auto addr = info.instance->getFinalAddress(
42184221
curr, ptr.getSingleValue(), bytes, memorySizeBytes);

test/lit/exec/atomic.wast

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,31 @@
55
(module
66
(import "fuzzing-support" "log-i32" (func $log (param i32)))
77

8-
(memory $0 23 256 shared)
8+
(memory $shared 23 256 shared)
9+
(memory $unshared 10 20)
910

1011
;; CHECK: [fuzz-exec] export wait_and_log
1112
;; CHECK-NEXT: [LoggingExternalInterface logging 2]
1213
(func $wait_and_log (export "wait_and_log")
1314
(call $log
14-
(memory.atomic.wait64
15+
(memory.atomic.wait64 $shared
1516
(i32.const 0)
1617
(i64.const 0)
1718
(i64.const 0)
1819
)
1920
)
2021
)
22+
23+
;; CHECK: [fuzz-exec] export wait_unshared
24+
;; CHECK-NEXT: [trap cannot atomic.wait a non-shared memory]
25+
(func $wait_unshared (export "wait_unshared")
26+
;; Waiting on an unshared memory traps.
27+
(drop
28+
(memory.atomic.wait32 $unshared
29+
(i32.const 0)
30+
(i32.const 0)
31+
(i64.const 0)
32+
)
33+
)
34+
)
2135
)

0 commit comments

Comments
 (0)