Commit a5d71c2c authored by michael_dawson's avatar michael_dawson Committed by Commit bot

PPC: JSEntryTrampoline: check for stack space before pushing arguments

Port 146598f4

Original commit message:
Optimistically pushing a lot of arguments can run into the stack limit of the process, at least on operating systems where this limit is close to the limit that V8 sets for itself.

R=mbrandy@us.ibm.com

BUG=

Review URL: https://codereview.chromium.org/1073893002

Cr-Commit-Position: refs/heads/master@{#27719}
parent 3865493a
......@@ -827,6 +827,43 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
}
enum IsTagged { kArgcIsSmiTagged, kArgcIsUntaggedInt };
// Clobbers r5; preserves all other registers.
static void Generate_CheckStackOverflow(MacroAssembler* masm,
const int calleeOffset, Register argc,
IsTagged argc_is_tagged) {
// Check the stack for overflow. We are not trying to catch
// interruptions (e.g. debug break and preemption) here, so the "real stack
// limit" is checked.
Label okay;
__ LoadRoot(r5, Heap::kRealStackLimitRootIndex);
// Make r5 the space we have left. The stack might already be overflowed
// here which will cause r5 to become negative.
__ sub(r5, sp, r5);
// Check if the arguments will overflow the stack.
if (argc_is_tagged == kArgcIsSmiTagged) {
__ SmiToPtrArrayOffset(r0, argc);
} else {
DCHECK(argc_is_tagged == kArgcIsUntaggedInt);
__ ShiftLeftImm(r0, argc, Operand(kPointerSizeLog2));
}
__ cmp(r5, r0);
__ bgt(&okay); // Signed comparison.
// Out of stack space.
__ LoadP(r4, MemOperand(fp, calleeOffset));
if (argc_is_tagged == kArgcIsUntaggedInt) {
__ SmiTag(argc);
}
__ Push(r4, argc);
__ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
__ bind(&okay);
}
static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
bool is_construct) {
// Called from Generate_JS_Entry
......@@ -854,6 +891,14 @@ static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
__ push(r4);
__ push(r5);
// Check if we have enough stack space to push all arguments.
// The function is the first thing that was pushed above after entering
// the internal frame.
const int kFunctionOffset =
InternalFrameConstants::kCodeOffset - kPointerSize;
// Clobbers r5.
Generate_CheckStackOverflow(masm, kFunctionOffset, r6, kArgcIsUntaggedInt);
// Copy arguments to the stack in a loop.
// r4: function
// r6: argc
......@@ -1366,30 +1411,6 @@ void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
}
static void Generate_CheckStackOverflow(MacroAssembler* masm,
const int calleeOffset) {
// Check the stack for overflow. We are not trying to catch
// interruptions (e.g. debug break and preemption) here, so the "real stack
// limit" is checked.
Label okay;
__ LoadRoot(r5, Heap::kRealStackLimitRootIndex);
// Make r5 the space we have left. The stack might already be overflowed
// here which will cause r5 to become negative.
__ sub(r5, sp, r5);
// Check if the arguments will overflow the stack.
__ SmiToPtrArrayOffset(r0, r3);
__ cmp(r5, r0);
__ bgt(&okay); // Signed comparison.
// Out of stack space.
__ LoadP(r4, MemOperand(fp, calleeOffset));
__ Push(r4, r3);
__ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
__ bind(&okay);
}
static void Generate_PushAppliedArguments(MacroAssembler* masm,
const int argumentsOffset,
const int indexOffset,
......@@ -1447,7 +1468,7 @@ static void Generate_ApplyHelper(MacroAssembler* masm, bool targetIsArgument) {
__ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION);
}
Generate_CheckStackOverflow(masm, kFunctionOffset);
Generate_CheckStackOverflow(masm, kFunctionOffset, r3, kArgcIsSmiTagged);
// Push current limit and index.
const int kIndexOffset =
......@@ -1584,7 +1605,7 @@ static void Generate_ConstructHelper(MacroAssembler* masm) {
__ push(r3);
__ InvokeBuiltin(Builtins::REFLECT_CONSTRUCT_PREPARE, CALL_FUNCTION);
Generate_CheckStackOverflow(masm, kFunctionOffset);
Generate_CheckStackOverflow(masm, kFunctionOffset, r3, kArgcIsSmiTagged);
// Push current limit and index.
const int kIndexOffset =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment