summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index a935d2069..0e67a1845 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -26,7 +26,8 @@ int32_t safe_ctz(int32_t v) {
}
enum {
- pageSize = 64*1024
+ pageSize = 64*1024,
+ maxCallDepth = 5000
};
//
@@ -66,6 +67,8 @@ public:
private:
+ size_t callDepth = 0;
+
#ifdef WASM_INTERPRETER_DEBUG
int indent = 0;
#endif
@@ -680,6 +683,9 @@ private:
}
};
+ if (callDepth > maxCallDepth) externalInterface->trap();
+ callDepth++;
+
Function *function = wasm.functionsMap[name];
assert(function);
FunctionScope scope(function, arguments);
@@ -687,6 +693,7 @@ private:
Literal ret = ExpressionRunner(*this, scope).visit(function->body).value;
if (function->result == none) ret = Literal();
assert(function->result == ret.type);
+ callDepth--;
return ret;
}