summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-04-12 18:37:48 -0700
committerGitHub <noreply@github.com>2021-04-12 18:37:48 -0700
commitb0af95200a37d76eccf285dcb45b4ed6162212d0 (patch)
tree3633c42ad4935b06f2fe88a8e9901b9d0b08d774 /src/wasm-interpreter.h
parentc9aa77c3f6452154526456497731da1bc8e7d896 (diff)
downloadbinaryen-b0af95200a37d76eccf285dcb45b4ed6162212d0.tar.gz
binaryen-b0af95200a37d76eccf285dcb45b4ed6162212d0.tar.bz2
binaryen-b0af95200a37d76eccf285dcb45b4ed6162212d0.zip
Fuzzer: Distinguish traps from host limitations (#3801)
Host limitations are arbitrary and can be modified by optimizations, so ignore them. For example, if the optimizer removes allocations then a host limit on an allocation error may vanish. Or, an optimization that removes recursion and replaces it with a loop may avoid a host limit on call depth (that is not done currently, but might some day). This removes a class of annoying false positives in the fuzzer.
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index d76f3fabf..37bebdf6b 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -197,7 +197,7 @@ public:
Flow visit(Expression* curr) {
depth++;
if (maxDepth != NO_LIMIT && depth > maxDepth) {
- trap("interpreter recursion limit");
+ hostLimit("interpreter recursion limit");
}
auto ret = OverriddenVisitor<SubType, Flow>::visit(curr);
if (!ret.breaking()) {
@@ -1622,7 +1622,7 @@ public:
// limits on 32-bit machines, and in particular on wasm32 VMs that do not
// have 4GB support, so give up there.
if (num >= (1 << 30) / sizeof(Literal)) {
- trap("allocation failure");
+ hostLimit("allocation failure");
}
Literals data(num);
if (curr->isWithDefault()) {
@@ -1739,6 +1739,8 @@ public:
virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); }
+ virtual void hostLimit(const char* why) { WASM_UNREACHABLE("unimp"); }
+
virtual void throwException(const WasmException& exn) {
WASM_UNREACHABLE("unimp");
}
@@ -2024,6 +2026,8 @@ public:
void trap(const char* why) override { throw NonconstantException(); }
+ void hostLimit(const char* why) override { throw NonconstantException(); }
+
virtual void throwException(const WasmException& exn) override {
throw NonconstantException();
}
@@ -2076,6 +2080,7 @@ public:
SubType& instance) = 0;
virtual bool growMemory(Address oldSize, Address newSize) = 0;
virtual void trap(const char* why) = 0;
+ virtual void hostLimit(const char* why) = 0;
virtual void throwException(const WasmException& exn) = 0;
// the default impls for load and store switch on the sizes. you can either
@@ -3095,6 +3100,10 @@ private:
instance.externalInterface->trap(why);
}
+ void hostLimit(const char* why) override {
+ instance.externalInterface->hostLimit(why);
+ }
+
void throwException(const WasmException& exn) override {
instance.externalInterface->throwException(exn);
}