Commit 84010cb2 authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: Make arguments adaptor not clobber new.target.

  port c1e7c8d9 (r32171)

  original commit message:
  This ensures that the ArgumentsAdaptorTrampoline does not clobber the
  new.target value, but rather passes it through to the callee unaltered.
  Note that callees do not yet use the new.target value so far.

  This is a preparatory CL to allows us passing new.target in a register
  instead of via a side-channel through the construct stub frame.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#32192}
parent e3905047
...@@ -1376,24 +1376,24 @@ static void ArgumentsAdaptorStackCheck(MacroAssembler* masm, ...@@ -1376,24 +1376,24 @@ static void ArgumentsAdaptorStackCheck(MacroAssembler* masm,
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : actual number of arguments // -- eax : actual number of arguments
// -- ebx : expected number of arguments // -- ebx : expected number of arguments
// -- edi : function (passed through to callee) // -- edx : new target (passed through to callee)
// ----------------------------------- // -----------------------------------
// Check the stack for overflow. We are not trying to catch // Check the stack for overflow. We are not trying to catch
// interruptions (e.g. debug break and preemption) here, so the "real stack // interruptions (e.g. debug break and preemption) here, so the "real stack
// limit" is checked. // limit" is checked.
ExternalReference real_stack_limit = ExternalReference real_stack_limit =
ExternalReference::address_of_real_stack_limit(masm->isolate()); ExternalReference::address_of_real_stack_limit(masm->isolate());
__ mov(edx, Operand::StaticVariable(real_stack_limit)); __ mov(edi, Operand::StaticVariable(real_stack_limit));
// Make ecx the space we have left. The stack might already be overflowed // Make ecx the space we have left. The stack might already be overflowed
// here which will cause ecx to become negative. // here which will cause ecx to become negative.
__ mov(ecx, esp); __ mov(ecx, esp);
__ sub(ecx, edx); __ sub(ecx, edi);
// Make edx the space we need for the array when it is unrolled onto the // Make edi the space we need for the array when it is unrolled onto the
// stack. // stack.
__ mov(edx, ebx); __ mov(edi, ebx);
__ shl(edx, kPointerSizeLog2); __ shl(edi, kPointerSizeLog2);
// Check if the arguments will overflow the stack. // Check if the arguments will overflow the stack.
__ cmp(ecx, edx); __ cmp(ecx, edi);
__ j(less_equal, stack_overflow); // Signed comparison. __ j(less_equal, stack_overflow); // Signed comparison.
} }
...@@ -1673,17 +1673,14 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -1673,17 +1673,14 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : actual number of arguments // -- eax : actual number of arguments
// -- ebx : expected number of arguments // -- ebx : expected number of arguments
// -- edx : new target (passed through to callee)
// -- edi : function (passed through to callee) // -- edi : function (passed through to callee)
// ----------------------------------- // -----------------------------------
Label invoke, dont_adapt_arguments; Label invoke, dont_adapt_arguments, stack_overflow;
__ IncrementCounter(masm->isolate()->counters()->arguments_adaptors(), 1); __ IncrementCounter(masm->isolate()->counters()->arguments_adaptors(), 1);
Label stack_overflow;
ArgumentsAdaptorStackCheck(masm, &stack_overflow);
Label enough, too_few; Label enough, too_few;
__ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset));
__ cmp(eax, ebx); __ cmp(eax, ebx);
__ j(less, &too_few); __ j(less, &too_few);
__ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel); __ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
...@@ -1692,6 +1689,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -1692,6 +1689,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
{ // Enough parameters: Actual >= expected. { // Enough parameters: Actual >= expected.
__ bind(&enough); __ bind(&enough);
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
ArgumentsAdaptorStackCheck(masm, &stack_overflow);
// Copy receiver and all expected arguments. // Copy receiver and all expected arguments.
const int offset = StandardFrameConstants::kCallerSPOffset; const int offset = StandardFrameConstants::kCallerSPOffset;
...@@ -1733,6 +1731,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -1733,6 +1731,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
__ bind(&no_strong_error); __ bind(&no_strong_error);
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
ArgumentsAdaptorStackCheck(masm, &stack_overflow);
// Remember expected arguments in ecx. // Remember expected arguments in ecx.
__ mov(ecx, ebx); __ mov(ecx, ebx);
...@@ -1771,8 +1770,10 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -1771,8 +1770,10 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// Restore function pointer. // Restore function pointer.
__ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
// eax : expected number of arguments // eax : expected number of arguments
// edx : new target (passed through to callee)
// edi : function (passed through to callee) // edi : function (passed through to callee)
__ call(edx); __ mov(ecx, FieldOperand(edi, JSFunction::kCodeEntryOffset));
__ call(ecx);
// Store offset of return address for deoptimizer. // Store offset of return address for deoptimizer.
masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset()); masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset());
...@@ -1785,12 +1786,12 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -1785,12 +1786,12 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
// Dont adapt arguments. // Dont adapt arguments.
// ------------------------------------------- // -------------------------------------------
__ bind(&dont_adapt_arguments); __ bind(&dont_adapt_arguments);
__ jmp(edx); __ mov(ecx, FieldOperand(edi, JSFunction::kCodeEntryOffset));
__ jmp(ecx);
__ bind(&stack_overflow); __ bind(&stack_overflow);
{ {
FrameScope frame(masm, StackFrame::MANUAL); FrameScope frame(masm, StackFrame::MANUAL);
EnterArgumentsAdaptorFrame(masm);
__ CallRuntime(Runtime::kThrowStackOverflow, 0); __ CallRuntime(Runtime::kThrowStackOverflow, 0);
__ int3(); __ int3();
} }
......
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