Skip to content

Commit 0e5e24c

Browse files
authored
[Shared Everything] struct.wait on unshared should trap (#8498)
1 parent 9687f72 commit 0e5e24c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/wasm-interpreter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,10 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
22542254
VISIT(expected, curr->expected)
22552255
VISIT(timeout, curr->timeout)
22562256

2257+
if (!curr->ref->type.getHeapType().isShared()) {
2258+
trap("cannot struct.wait a non-shared object");
2259+
}
2260+
22572261
auto data = ref.getSingleValue().getGCData();
22582262
if (!data) {
22592263
trap("null ref");

test/spec/waitqueue.wast

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
)
7777

7878
(module
79-
(type $t (struct (field (mut waitqueue))))
79+
(type $t (shared (struct (field (mut waitqueue)))))
8080

8181
(global $g (mut (ref null $t)) (struct.new $t (i32.const 0)))
8282

@@ -117,3 +117,16 @@
117117

118118
(assert_trap (invoke "struct.wait" (i32.const 0) (i64.const 0)) "null ref")
119119
(assert_trap (invoke "struct.notify" (i32.const 0)) "null ref")
120+
121+
;; Waiting on a non-shared struct should trap.
122+
(module
123+
(type $t (struct (field (mut waitqueue))))
124+
125+
(global $g (mut (ref null $t)) (struct.new $t (i32.const 0)))
126+
127+
(func (export "struct.wait") (param $expected i32) (param $timeout i64) (result i32)
128+
(struct.wait $t 0 (global.get $g) (local.get $expected) (local.get $timeout))
129+
)
130+
)
131+
(assert_trap (invoke "struct.wait" (i32.const 0) (i64.const 100)) "not shared")
132+

0 commit comments

Comments
 (0)