summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-03-19 12:34:35 -0700
committerGitHub <noreply@github.com>2024-03-19 12:34:35 -0700
commit4ce9fb460b6a1161209904264bafec96abe911ac (patch)
tree24043d7baa00165c920fd6180d3b447f6ba2e738
parent70f860e7b11b013efd5af4bb5c14b72d2183a45a (diff)
downloadbinaryen-4ce9fb460b6a1161209904264bafec96abe911ac.tar.gz
binaryen-4ce9fb460b6a1161209904264bafec96abe911ac.tar.bz2
binaryen-4ce9fb460b6a1161209904264bafec96abe911ac.zip
Atomics: Handle timeouts in waits in the (single-threaded) interpreter (#6408)
The interpreter does not run multiple threads, and it was returning 0 from atomic.wait, which means it was woken up. But it is more correct for it to return 2, which means it timed out - which is actually the case, as no other thread exists that can wake it up. However, even that is not good for fuzzing as the timeout may be infinite or large, so just emit a host limit error on any timeout for now, until we actually implement threads.
-rw-r--r--src/wasm-interpreter.h12
-rw-r--r--test/lit/exec/atomic.wast21
2 files changed, 30 insertions, 3 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 0dedfeb58..af01865f4 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -3461,9 +3461,15 @@ public:
if (loaded != expected.getSingleValue()) {
return Literal(int32_t(1)); // not equal
}
- // TODO: add threads support!
- // for now, just assume we are woken up
- return Literal(int32_t(0)); // woken up
+ // TODO: Add threads support. For now, report a host limit here, as there
+ // are no other threads that can wake us up. Without such threads,
+ // we'd hang if there is no timeout, and even if there is a timeout
+ // then we can hang for a long time if it is in a loop. The only
+ // timeout value we allow here for now is 0.
+ if (timeout.getSingleValue().getInteger() != 0) {
+ hostLimit("threads support");
+ }
+ return Literal(int32_t(0)); // equal
}
Flow visitAtomicNotify(AtomicNotify* curr) {
NOTE_ENTER("AtomicNotify");
diff --git a/test/lit/exec/atomic.wast b/test/lit/exec/atomic.wast
new file mode 100644
index 000000000..73567121f
--- /dev/null
+++ b/test/lit/exec/atomic.wast
@@ -0,0 +1,21 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited.
+
+;; RUN: wasm-opt %s -all --fuzz-exec-before -q -o /dev/null 2>&1 | filecheck %s
+
+(module
+ (import "fuzzing-support" "log-i32" (func $log (param i32)))
+
+ (memory $0 23 256 shared)
+
+ ;; CHECK: [fuzz-exec] calling wait_and_log
+ ;; CHECK-NEXT: [LoggingExternalInterface logging 0]
+ (func $wait_and_log (export "wait_and_log")
+ (call $log
+ (memory.atomic.wait64
+ (i32.const 0)
+ (i64.const 0)
+ (i64.const 0)
+ )
+ )
+ )
+)