Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: src/compiler/wasm-compiler.cc

Issue 2256603002: [wasm] Add stack checks at the beginning of each function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use the right control input. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/wasm-compiler.cc
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
index af4ee67c4391ca94e33728a8174543d37068a07d..d8dddc9422d45a3602e378cdbaff47558138b93c 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -66,7 +66,7 @@ void MergeControlToEnd(JSGraph* jsgraph, Node* node) {
Node* BuildCallToRuntime(Runtime::FunctionId f, JSGraph* jsgraph,
Handle<Context> context, Node** parameters,
int parameter_count, Node** effect_ptr,
- Node** control_ptr) {
+ Node* control) {
// At the moment we only allow 2 parameters. If more parameters are needed,
// then the size of {inputs} below has to be increased accordingly.
DCHECK(parameter_count <= 2);
@@ -88,7 +88,7 @@ Node* BuildCallToRuntime(Runtime::FunctionId f, JSGraph* jsgraph,
inputs[count++] = jsgraph->Int32Constant(fun->nargs); // arity
inputs[count++] = jsgraph->HeapConstant(context); // context
inputs[count++] = *effect_ptr;
- inputs[count++] = *control_ptr;
+ inputs[count++] = control;
Node* node =
jsgraph->graph()->NewNode(jsgraph->common()->Call(desc), count, inputs);
@@ -263,7 +263,7 @@ class WasmTrapHelper : public ZoneObject {
trap_position_smi}; // byte position
BuildCallToRuntime(Runtime::kThrowWasmError, jsgraph(),
module->instance->context, parameters,
- arraysize(parameters), effect_ptr, control_ptr);
+ arraysize(parameters), effect_ptr, *control_ptr);
}
if (false) {
// End the control flow with a throw
@@ -388,6 +388,40 @@ Node* WasmGraphBuilder::Int64Constant(int64_t value) {
return jsgraph()->Int64Constant(value);
}
+void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) {
+ // We do not generate stack checks for cctests.
+ if (module_ && !module_->instance->context.is_null()) {
+ Node* limit = graph()->NewNode(
+ jsgraph()->machine()->Load(MachineType::Pointer()),
+ jsgraph()->ExternalConstant(
+ ExternalReference::address_of_stack_limit(jsgraph()->isolate())),
+ jsgraph()->IntPtrConstant(0), *effect_, *control_);
+ Node* pointer = graph()->NewNode(jsgraph()->machine()->LoadStackPointer());
+
+ Node* check =
+ graph()->NewNode(jsgraph()->machine()->UintLessThan(), limit, pointer);
+
+ Diamond stack_check(graph(), jsgraph()->common(), check, BranchHint::kTrue);
+
+ Node* effect_true = *effect_;
+
+ Node* effect_false;
+ // Generate a call to the runtime if there is a stack check failure.
+ {
+ Node* node = BuildCallToRuntime(Runtime::kStackGuard, jsgraph(),
+ module_->instance->context, nullptr, 0,
+ effect_, stack_check.if_false);
+ effect_false = node;
+ }
+
+ Node* ephi = graph()->NewNode(jsgraph()->common()->EffectPhi(2),
+ effect_true, effect_false, stack_check.merge);
+
+ *control_ = stack_check.merge;
+ *effect_ = ephi;
+ }
+}
+
Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right,
wasm::WasmCodePosition position) {
const Operator* op;
@@ -2205,7 +2239,7 @@ Node* WasmGraphBuilder::ToJS(Node* node, wasm::LocalType type) {
// Throw a TypeError.
return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(),
module_->instance->context, nullptr, 0, effect_,
- control_);
+ *control_);
case wasm::kAstF32:
node = graph()->NewNode(jsgraph()->machine()->ChangeFloat32ToFloat64(),
node);
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698