Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using namespace cashew;

extern Name WASM, RETURN_FLOW;

enum { maxCallDepth = 250 };
enum { maxInterpreterDepth = 250 };

// Stuff that flows around during executing expressions: a literal, or a change
// in control flow.
Expand Down Expand Up @@ -128,8 +128,16 @@ class Indenter {
// Execute an expression
template<typename SubType>
class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
protected:
// Keep a record of call depth, to guard against excessive recursion.
size_t depth = 0;

public:
Flow visit(Expression* curr) {
depth++;
if (depth > maxInterpreterDepth) {
trap("interpreter recursion limit");
}
auto ret = OverriddenVisitor<SubType, Flow>::visit(curr);
if (!ret.breaking() &&
(isConcreteType(curr->type) || isConcreteType(ret.value.type))) {
Expand All @@ -142,6 +150,7 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
#endif
assert(ret.value.type == curr->type);
}
depth--;
return ret;
}

Expand Down Expand Up @@ -1790,7 +1799,7 @@ template<typename GlobalManager, typename SubType> class ModuleInstanceBase {
// Internal function call. Must be public so that callTable implementations
// can use it (refactor?)
Literal callFunctionInternal(Name name, const LiteralList& arguments) {
if (callDepth > maxCallDepth) {
if (callDepth > maxInterpreterDepth) {
externalInterface->trap("stack limit");
}
auto previousCallDepth = callDepth;
Expand Down