diff options
author | Sam Clegg <sbc@chromium.org> | 2022-01-21 13:49:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-21 13:49:37 -0800 |
commit | 830b18b34197ad791e7b0d5bd5f5bade2a704395 (patch) | |
tree | 46ae5c3a5d547fb5af0f0ffb3fce52921ac02fde /src/passes/StackCheck.cpp | |
parent | 02ef6b11d740f5a3aa2071b53b35c306d6ddfa7a (diff) | |
download | binaryen-830b18b34197ad791e7b0d5bd5f5bade2a704395.tar.gz binaryen-830b18b34197ad791e7b0d5bd5f5bade2a704395.tar.bz2 binaryen-830b18b34197ad791e7b0d5bd5f5bade2a704395.zip |
StackCheck: Add argument stack-check-handler call (#4471)
This function call now takes the address (which by defintion is outside
of the stack range) that the program was attempting to set SP to.
This allows emscripten to provide a more useful error message on stack
over/under flow.
Diffstat (limited to 'src/passes/StackCheck.cpp')
-rw-r--r-- | src/passes/StackCheck.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/passes/StackCheck.cpp b/src/passes/StackCheck.cpp index e7fc3c6b3..07cf46aee 100644 --- a/src/passes/StackCheck.cpp +++ b/src/passes/StackCheck.cpp @@ -35,11 +35,12 @@ namespace wasm { // Exported function to set the base and the limit. static Name SET_STACK_LIMITS("__set_stack_limits"); -static void importStackOverflowHandler(Module& module, Name name) { +static void +importStackOverflowHandler(Module& module, Name name, Signature sig) { ImportInfo info(module); if (!info.getImportedFunction(ENV, name)) { - auto import = Builder::makeFunction(name, Signature(), {}); + auto import = Builder::makeFunction(name, sig, {}); import->module = ENV; import->base = name; module.addFunction(std::move(import)); @@ -79,7 +80,10 @@ struct EnforceStackLimits : public WalkerPass<PostWalker<EnforceStackLimits>> { // Otherwise, just trap. Expression* handlerExpr; if (handler.is()) { - handlerExpr = builder.makeCall(handler, {}, Type::none); + handlerExpr = + builder.makeCall(handler, + {builder.makeLocalGet(newSP, stackPointer->type)}, + stackPointer->type); } else { handlerExpr = builder.makeUnreachable(); } @@ -133,7 +137,8 @@ struct StackCheck : public Pass { runner->options.getArgumentOrDefault("stack-check-handler", ""); if (handlerName != "") { handler = handlerName; - importStackOverflowHandler(*module, handler); + importStackOverflowHandler( + *module, handler, Signature({stackPointer->type}, Type::none)); } Builder builder(*module); |