Commit 3b4cc88e authored by ziyang's avatar ziyang Committed by Commit bot

PPC/s390: [Interpreter] Adds stackcheck in InterpreterPushArgsAndCall/Construct builtins.

    Port 7f3d15aa

    Original commit message:
    In ignition, arguments to function calls and function constructors are
    pushed onto the stack before calling the function. It is required to check
    that stack does not overflow when pushing the arguments.

    R=mythria@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com, mbrandy@us.ibm.com
BUG=

Review-Url: https://codereview.chromium.org/2356583003
Cr-Commit-Position: refs/heads/master@{#39561}
parent c819a1e2
...@@ -1199,10 +1199,29 @@ void Builtins::Generate_InterpreterMarkBaselineOnReturn(MacroAssembler* masm) { ...@@ -1199,10 +1199,29 @@ void Builtins::Generate_InterpreterMarkBaselineOnReturn(MacroAssembler* masm) {
__ blr(); __ blr();
} }
static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args,
Register scratch,
Label* stack_overflow) {
// 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.
__ LoadRoot(scratch, Heap::kRealStackLimitRootIndex);
// Make scratch the space we have left. The stack might already be overflowed
// here which will cause scratch to become negative.
__ sub(scratch, sp, scratch);
// Check if the arguments will overflow the stack.
__ ShiftLeftImm(r0, num_args, Operand(kPointerSizeLog2));
__ cmp(scratch, r0);
__ ble(stack_overflow); // Signed comparison.
}
static void Generate_InterpreterPushArgs(MacroAssembler* masm, static void Generate_InterpreterPushArgs(MacroAssembler* masm,
Register num_args, Register index, Register num_args, Register index,
Register count, Register scratch) { Register count, Register scratch,
// TODO(mythria): Add a stack check before pushing arguments. Label* stack_overflow) {
// A stack check before pushing arguments.
Generate_StackOverflowCheck(masm, num_args, scratch, stack_overflow);
Label loop; Label loop;
__ addi(index, index, Operand(kPointerSize)); // Bias up for LoadPU __ addi(index, index, Operand(kPointerSize)); // Bias up for LoadPU
__ mtctr(count); __ mtctr(count);
...@@ -1223,13 +1242,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl( ...@@ -1223,13 +1242,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl(
// they are to be pushed onto the stack. // they are to be pushed onto the stack.
// -- r4 : the target to call (can be any Object). // -- r4 : the target to call (can be any Object).
// ----------------------------------- // -----------------------------------
Label stack_overflow;
// Calculate number of arguments (add one for receiver). // Calculate number of arguments (add one for receiver).
__ addi(r6, r3, Operand(1)); __ addi(r6, r3, Operand(1));
// TODO(mythria): Add a stack check before pushing arguments.
// Push the arguments. r5, r6, r7 will be modified. // Push the arguments. r5, r6, r7 will be modified.
Generate_InterpreterPushArgs(masm, r6, r5, r6, r7); Generate_InterpreterPushArgs(masm, r6, r5, r6, r7, &stack_overflow);
// Call the target. // Call the target.
if (function_type == CallableType::kJSFunction) { if (function_type == CallableType::kJSFunction) {
...@@ -1242,6 +1261,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl( ...@@ -1242,6 +1261,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl(
tail_call_mode), tail_call_mode),
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
__ bind(&stack_overflow);
{
__ TailCallRuntime(Runtime::kThrowStackOverflow);
// Unreachable Code.
__ bkpt(0);
}
} }
// static // static
...@@ -1254,6 +1280,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl( ...@@ -1254,6 +1280,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
// -- r5 : allocation site feedback if available, undefined otherwise. // -- r5 : allocation site feedback if available, undefined otherwise.
// -- r7 : address of the first argument // -- r7 : address of the first argument
// ----------------------------------- // -----------------------------------
Label stack_overflow;
// Push a slot for the receiver to be constructed. // Push a slot for the receiver to be constructed.
__ li(r0, Operand::Zero()); __ li(r0, Operand::Zero());
...@@ -1264,7 +1291,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl( ...@@ -1264,7 +1291,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
__ cmpi(r3, Operand::Zero()); __ cmpi(r3, Operand::Zero());
__ beq(&skip); __ beq(&skip);
// Push the arguments. r8, r7, r9 will be modified. // Push the arguments. r8, r7, r9 will be modified.
Generate_InterpreterPushArgs(masm, r3, r7, r3, r8); Generate_InterpreterPushArgs(masm, r3, r7, r3, r8, &stack_overflow);
__ bind(&skip); __ bind(&skip);
__ AssertUndefinedOrAllocationSite(r5, r8); __ AssertUndefinedOrAllocationSite(r5, r8);
...@@ -1284,6 +1311,13 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl( ...@@ -1284,6 +1311,13 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
// Call the constructor with r3, r4, and r6 unmodified. // Call the constructor with r3, r4, and r6 unmodified.
__ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
} }
__ bind(&stack_overflow);
{
__ TailCallRuntime(Runtime::kThrowStackOverflow);
// Unreachable Code.
__ bkpt(0);
}
} }
// static // static
...@@ -1295,18 +1329,25 @@ void Builtins::Generate_InterpreterPushArgsAndConstructArray( ...@@ -1295,18 +1329,25 @@ void Builtins::Generate_InterpreterPushArgsAndConstructArray(
// -- r5 : allocation site feedback if available, undefined otherwise. // -- r5 : allocation site feedback if available, undefined otherwise.
// -- r6 : address of the first argument // -- r6 : address of the first argument
// ----------------------------------- // -----------------------------------
Label stack_overflow;
__ addi(r7, r3, Operand(1)); // Add one for receiver. __ addi(r7, r3, Operand(1)); // Add one for receiver.
// TODO(mythria): Add a stack check before pushing arguments.
// Push the arguments. r6, r8, r3 will be modified. // Push the arguments. r6, r8, r3 will be modified.
Generate_InterpreterPushArgs(masm, r7, r6, r7, r8); Generate_InterpreterPushArgs(masm, r7, r6, r7, r8, &stack_overflow);
// Array constructor expects constructor in r6. It is same as r4 here. // Array constructor expects constructor in r6. It is same as r4 here.
__ mr(r6, r4); __ mr(r6, r4);
ArrayConstructorStub stub(masm->isolate()); ArrayConstructorStub stub(masm->isolate());
__ TailCallStub(&stub); __ TailCallStub(&stub);
__ bind(&stack_overflow);
{
__ TailCallRuntime(Runtime::kThrowStackOverflow);
// Unreachable code.
__ bkpt(0);
}
} }
void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
...@@ -2152,27 +2193,6 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) { ...@@ -2152,27 +2193,6 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
} }
} }
static void ArgumentAdaptorStackCheck(MacroAssembler* masm,
Label* stack_overflow) {
// ----------- S t a t e -------------
// -- r3 : actual number of arguments
// -- r4 : function (passed through to callee)
// -- r5 : expected number of arguments
// -- r6 : new target (passed through to callee)
// -----------------------------------
// 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.
__ LoadRoot(r8, Heap::kRealStackLimitRootIndex);
// Make r8 the space we have left. The stack might already be overflowed
// here which will cause r8 to become negative.
__ sub(r8, sp, r8);
// Check if the arguments will overflow the stack.
__ ShiftLeftImm(r0, r5, Operand(kPointerSizeLog2));
__ cmp(r8, r0);
__ ble(stack_overflow); // Signed comparison.
}
static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
__ SmiTag(r3); __ SmiTag(r3);
__ LoadSmiLiteral(r7, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); __ LoadSmiLiteral(r7, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
...@@ -2882,7 +2902,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -2882,7 +2902,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
{ // Enough parameters: actual >= expected { // Enough parameters: actual >= expected
__ bind(&enough); __ bind(&enough);
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
ArgumentAdaptorStackCheck(masm, &stack_overflow); Generate_StackOverflowCheck(masm, r5, r8, &stack_overflow);
// Calculate copy start address into r3 and copy end address into r7. // Calculate copy start address into r3 and copy end address into r7.
// r3: actual number of arguments as a smi // r3: actual number of arguments as a smi
...@@ -2920,7 +2940,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -2920,7 +2940,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
__ bind(&too_few); __ bind(&too_few);
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
ArgumentAdaptorStackCheck(masm, &stack_overflow); Generate_StackOverflowCheck(masm, r5, r8, &stack_overflow);
// Calculate copy start address into r0 and copy end address is fp. // Calculate copy start address into r0 and copy end address is fp.
// r3: actual number of arguments as a smi // r3: actual number of arguments as a smi
......
...@@ -1202,10 +1202,29 @@ void Builtins::Generate_InterpreterMarkBaselineOnReturn(MacroAssembler* masm) { ...@@ -1202,10 +1202,29 @@ void Builtins::Generate_InterpreterMarkBaselineOnReturn(MacroAssembler* masm) {
__ Ret(); __ Ret();
} }
static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args,
Register scratch,
Label* stack_overflow) {
// 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.
__ LoadRoot(scratch, Heap::kRealStackLimitRootIndex);
// Make scratch the space we have left. The stack might already be overflowed
// here which will cause scratch to become negative.
__ SubP(scratch, sp, scratch);
// Check if the arguments will overflow the stack.
__ ShiftLeftP(r0, num_args, Operand(kPointerSizeLog2));
__ CmpP(scratch, r0);
__ ble(stack_overflow); // Signed comparison.
}
static void Generate_InterpreterPushArgs(MacroAssembler* masm, static void Generate_InterpreterPushArgs(MacroAssembler* masm,
Register num_args, Register index, Register num_args, Register index,
Register count, Register scratch) { Register count, Register scratch,
// TODO(mythria): Add a stack check before pushing arguments. Label* stack_overflow) {
// Add a stack check before pushing arguments.
Generate_StackOverflowCheck(masm, num_args, scratch, stack_overflow);
Label loop; Label loop;
__ AddP(index, index, Operand(kPointerSize)); // Bias up for LoadPU __ AddP(index, index, Operand(kPointerSize)); // Bias up for LoadPU
__ LoadRR(r0, count); __ LoadRR(r0, count);
...@@ -1228,12 +1247,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl( ...@@ -1228,12 +1247,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl(
// they are to be pushed onto the stack. // they are to be pushed onto the stack.
// -- r3 : the target to call (can be any Object). // -- r3 : the target to call (can be any Object).
// ----------------------------------- // -----------------------------------
Label stack_overflow;
// Calculate number of arguments (AddP one for receiver). // Calculate number of arguments (AddP one for receiver).
__ AddP(r5, r2, Operand(1)); __ AddP(r5, r2, Operand(1));
// Push the arguments. // Push the arguments.
Generate_InterpreterPushArgs(masm, r5, r4, r5, r6); Generate_InterpreterPushArgs(masm, r5, r4, r5, r6, &stack_overflow);
// Call the target. // Call the target.
if (function_type == CallableType::kJSFunction) { if (function_type == CallableType::kJSFunction) {
...@@ -1246,6 +1266,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl( ...@@ -1246,6 +1266,13 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl(
tail_call_mode), tail_call_mode),
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
__ bind(&stack_overflow);
{
__ TailCallRuntime(Runtime::kThrowStackOverflow);
// Unreachable Code.
__ bkpt(0);
}
} }
// static // static
...@@ -1258,6 +1285,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl( ...@@ -1258,6 +1285,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
// -- r4 : allocation site feedback if available, undefined otherwise. // -- r4 : allocation site feedback if available, undefined otherwise.
// -- r6 : address of the first argument // -- r6 : address of the first argument
// ----------------------------------- // -----------------------------------
Label stack_overflow;
// Push a slot for the receiver to be constructed. // Push a slot for the receiver to be constructed.
__ LoadImmP(r0, Operand::Zero()); __ LoadImmP(r0, Operand::Zero());
...@@ -1267,7 +1295,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl( ...@@ -1267,7 +1295,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
Label skip; Label skip;
__ CmpP(r2, Operand::Zero()); __ CmpP(r2, Operand::Zero());
__ beq(&skip); __ beq(&skip);
Generate_InterpreterPushArgs(masm, r2, r6, r2, r7); Generate_InterpreterPushArgs(masm, r2, r6, r2, r7, &stack_overflow);
__ bind(&skip); __ bind(&skip);
__ AssertUndefinedOrAllocationSite(r4, r7); __ AssertUndefinedOrAllocationSite(r4, r7);
...@@ -1287,6 +1315,13 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl( ...@@ -1287,6 +1315,13 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
// Call the constructor with r2, r3, and r5 unmodified. // Call the constructor with r2, r3, and r5 unmodified.
__ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
} }
__ bind(&stack_overflow);
{
__ TailCallRuntime(Runtime::kThrowStackOverflow);
// Unreachable Code.
__ bkpt(0);
}
} }
// static // static
...@@ -1298,18 +1333,25 @@ void Builtins::Generate_InterpreterPushArgsAndConstructArray( ...@@ -1298,18 +1333,25 @@ void Builtins::Generate_InterpreterPushArgsAndConstructArray(
// -- r4 : allocation site feedback if available, undefined otherwise. // -- r4 : allocation site feedback if available, undefined otherwise.
// -- r5 : address of the first argument // -- r5 : address of the first argument
// ----------------------------------- // -----------------------------------
Label stack_overflow;
__ AddP(r6, r2, Operand(1)); // Add one for receiver. __ AddP(r6, r2, Operand(1)); // Add one for receiver.
// TODO(mythria): Add a stack check before pushing arguments.
// Push the arguments. r6, r8, r3 will be modified. // Push the arguments. r6, r8, r3 will be modified.
Generate_InterpreterPushArgs(masm, r6, r5, r6, r7); Generate_InterpreterPushArgs(masm, r6, r5, r6, r7, &stack_overflow);
// Array constructor expects constructor in r5. It is same as r3 here. // Array constructor expects constructor in r5. It is same as r3 here.
__ LoadRR(r5, r3); __ LoadRR(r5, r3);
ArrayConstructorStub stub(masm->isolate()); ArrayConstructorStub stub(masm->isolate());
__ TailCallStub(&stub); __ TailCallStub(&stub);
__ bind(&stack_overflow);
{
__ TailCallRuntime(Runtime::kThrowStackOverflow);
// Unreachable Code.
__ bkpt(0);
}
} }
void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
...@@ -2151,27 +2193,6 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) { ...@@ -2151,27 +2193,6 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
} }
} }
static void ArgumentAdaptorStackCheck(MacroAssembler* masm,
Label* stack_overflow) {
// ----------- S t a t e -------------
// -- r2 : actual number of arguments
// -- r3 : function (passed through to callee)
// -- r4 : expected number of arguments
// -- r5 : new target (passed through to callee)
// -----------------------------------
// 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.
__ LoadRoot(r7, Heap::kRealStackLimitRootIndex);
// Make r7 the space we have left. The stack might already be overflowed
// here which will cause r7 to become negative.
__ SubP(r7, sp, r7);
// Check if the arguments will overflow the stack.
__ ShiftLeftP(r0, r4, Operand(kPointerSizeLog2));
__ CmpP(r7, r0);
__ ble(stack_overflow); // Signed comparison.
}
static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
__ SmiTag(r2); __ SmiTag(r2);
__ LoadSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); __ LoadSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
...@@ -2892,7 +2913,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -2892,7 +2913,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
{ // Enough parameters: actual >= expected { // Enough parameters: actual >= expected
__ bind(&enough); __ bind(&enough);
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
ArgumentAdaptorStackCheck(masm, &stack_overflow); Generate_StackOverflowCheck(masm, r4, r7, &stack_overflow);
// Calculate copy start address into r2 and copy end address into r6. // Calculate copy start address into r2 and copy end address into r6.
// r2: actual number of arguments as a smi // r2: actual number of arguments as a smi
...@@ -2930,7 +2951,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -2930,7 +2951,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
__ bind(&too_few); __ bind(&too_few);
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
ArgumentAdaptorStackCheck(masm, &stack_overflow); Generate_StackOverflowCheck(masm, r4, r7, &stack_overflow);
// Calculate copy start address into r0 and copy end address is fp. // Calculate copy start address into r0 and copy end address is fp.
// r2: actual number of arguments as a smi // r2: actual number of arguments as a smi
......
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