Commit 58275c32 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[ia32,root] Ensure Construct* builtins preserve kRootRegister (ebx)

This CL changes Construct, ConstructVarargs, ConstructForwardVarargs and
ConstructFunctionForwardVarargs to preserve the kRootRegister (ebx).

Bug: v8:6666
Change-Id: Ia2c328e419506c029cda76fc210bbd45d9eb5952
Reviewed-on: https://chromium-review.googlesource.com/1233654Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56111}
parent 9ea182dd
...@@ -68,15 +68,24 @@ void Builtins::Generate_Call_ReceiverIsAny(MacroAssembler* masm) { ...@@ -68,15 +68,24 @@ void Builtins::Generate_Call_ReceiverIsAny(MacroAssembler* masm) {
} }
void Builtins::Generate_CallVarargs(MacroAssembler* masm) { void Builtins::Generate_CallVarargs(MacroAssembler* masm) {
#ifdef V8_TARGET_ARCH_IA32
Assembler::SupportsRootRegisterScope supports_root_register(masm);
#endif
Generate_CallOrConstructVarargs(masm, masm->isolate()->builtins()->Call()); Generate_CallOrConstructVarargs(masm, masm->isolate()->builtins()->Call());
} }
void Builtins::Generate_CallForwardVarargs(MacroAssembler* masm) { void Builtins::Generate_CallForwardVarargs(MacroAssembler* masm) {
#ifdef V8_TARGET_ARCH_IA32
Assembler::SupportsRootRegisterScope supports_root_register(masm);
#endif
Generate_CallOrConstructForwardVarargs(masm, CallOrConstructMode::kCall, Generate_CallOrConstructForwardVarargs(masm, CallOrConstructMode::kCall,
masm->isolate()->builtins()->Call()); masm->isolate()->builtins()->Call());
} }
void Builtins::Generate_CallFunctionForwardVarargs(MacroAssembler* masm) { void Builtins::Generate_CallFunctionForwardVarargs(MacroAssembler* masm) {
#ifdef V8_TARGET_ARCH_IA32
Assembler::SupportsRootRegisterScope supports_root_register(masm);
#endif
Generate_CallOrConstructForwardVarargs( Generate_CallOrConstructForwardVarargs(
masm, CallOrConstructMode::kCall, masm, CallOrConstructMode::kCall,
masm->isolate()->builtins()->CallFunction()); masm->isolate()->builtins()->CallFunction());
......
...@@ -19,17 +19,26 @@ namespace v8 { ...@@ -19,17 +19,26 @@ namespace v8 {
namespace internal { namespace internal {
void Builtins::Generate_ConstructVarargs(MacroAssembler* masm) { void Builtins::Generate_ConstructVarargs(MacroAssembler* masm) {
#ifdef V8_TARGET_ARCH_IA32
Assembler::SupportsRootRegisterScope supports_root_register(masm);
#endif
Generate_CallOrConstructVarargs(masm, Generate_CallOrConstructVarargs(masm,
BUILTIN_CODE(masm->isolate(), Construct)); BUILTIN_CODE(masm->isolate(), Construct));
} }
void Builtins::Generate_ConstructForwardVarargs(MacroAssembler* masm) { void Builtins::Generate_ConstructForwardVarargs(MacroAssembler* masm) {
#ifdef V8_TARGET_ARCH_IA32
Assembler::SupportsRootRegisterScope supports_root_register(masm);
#endif
Generate_CallOrConstructForwardVarargs( Generate_CallOrConstructForwardVarargs(
masm, CallOrConstructMode::kConstruct, masm, CallOrConstructMode::kConstruct,
BUILTIN_CODE(masm->isolate(), Construct)); BUILTIN_CODE(masm->isolate(), Construct));
} }
void Builtins::Generate_ConstructFunctionForwardVarargs(MacroAssembler* masm) { void Builtins::Generate_ConstructFunctionForwardVarargs(MacroAssembler* masm) {
#ifdef V8_TARGET_ARCH_IA32
Assembler::SupportsRootRegisterScope supports_root_register(masm);
#endif
Generate_CallOrConstructForwardVarargs( Generate_CallOrConstructForwardVarargs(
masm, CallOrConstructMode::kConstruct, masm, CallOrConstructMode::kConstruct,
BUILTIN_CODE(masm->isolate(), ConstructFunction)); BUILTIN_CODE(masm->isolate(), ConstructFunction));
......
...@@ -1709,8 +1709,10 @@ static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { ...@@ -1709,8 +1709,10 @@ static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
// static // static
void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm, void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm,
Handle<Code> code) { Handle<Code> code) {
Assembler::SupportsRootRegisterScope supports_root_register(masm);
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- edi : target // -- edi : target
// -- esi : context for the Call / Construct builtin
// -- eax : number of parameters on the stack (not including the receiver) // -- eax : number of parameters on the stack (not including the receiver)
// -- ecx : len (number of elements to from args) // -- ecx : len (number of elements to from args)
// -- ecx : new.target (checked to be constructor or undefined) // -- ecx : new.target (checked to be constructor or undefined)
...@@ -1718,13 +1720,14 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm, ...@@ -1718,13 +1720,14 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm,
// -- esp[0] : return address. // -- esp[0] : return address.
// ----------------------------------- // -----------------------------------
// We need to preserve eax, edi and ebx. // We need to preserve eax, edi, esi and ebx.
__ movd(xmm0, edx); __ movd(xmm0, edx);
__ movd(xmm1, edi); __ movd(xmm1, edi);
__ movd(xmm2, eax); __ movd(xmm2, eax);
__ movd(xmm3, esi); // Spill the context.
// TODO(v8:6666): Remove this usage of ebx to enable kRootRegister support. // TODO(v8:6666): Remove this usage of ebx to enable kRootRegister support.
const Register kArgumentsList = ebx; const Register kArgumentsList = esi;
const Register kArgumentsLength = ecx; const Register kArgumentsLength = ecx;
__ PopReturnAddressTo(edx); __ PopReturnAddressTo(edx);
...@@ -1778,6 +1781,7 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm, ...@@ -1778,6 +1781,7 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm,
} }
// Restore eax, edi and edx. // Restore eax, edi and edx.
__ movd(esi, xmm3); // Restore the context.
__ movd(eax, xmm2); __ movd(eax, xmm2);
__ movd(edi, xmm1); __ movd(edi, xmm1);
__ movd(edx, xmm0); __ movd(edx, xmm0);
...@@ -1789,6 +1793,7 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm, ...@@ -1789,6 +1793,7 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm,
__ Jump(code, RelocInfo::CODE_TARGET); __ Jump(code, RelocInfo::CODE_TARGET);
__ bind(&stack_overflow); __ bind(&stack_overflow);
__ movd(esi, xmm3); // Restore the context.
__ TailCallRuntime(Runtime::kThrowStackOverflow); __ TailCallRuntime(Runtime::kThrowStackOverflow);
} }
...@@ -1796,19 +1801,25 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm, ...@@ -1796,19 +1801,25 @@ void Builtins::Generate_CallOrConstructVarargs(MacroAssembler* masm,
void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm, void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
CallOrConstructMode mode, CallOrConstructMode mode,
Handle<Code> code) { Handle<Code> code) {
Assembler::SupportsRootRegisterScope supports_root_register(masm);
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : the number of arguments (not including the receiver) // -- eax : the number of arguments (not including the receiver)
// -- edi : the target to call (can be any Object) // -- edi : the target to call (can be any Object)
// -- esi : context for the Call / Construct builtin
// -- edx : the new target (for [[Construct]] calls) // -- edx : the new target (for [[Construct]] calls)
// -- ecx : start index (to support rest parameters) // -- ecx : start index (to support rest parameters)
// ----------------------------------- // -----------------------------------
__ movd(xmm0, esi); // Spill the context.
Register scratch = esi;
// Check if new.target has a [[Construct]] internal method. // Check if new.target has a [[Construct]] internal method.
if (mode == CallOrConstructMode::kConstruct) { if (mode == CallOrConstructMode::kConstruct) {
Label new_target_constructor, new_target_not_constructor; Label new_target_constructor, new_target_not_constructor;
__ JumpIfSmi(edx, &new_target_not_constructor, Label::kNear); __ JumpIfSmi(edx, &new_target_not_constructor, Label::kNear);
__ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset));
__ test_b(FieldOperand(ebx, Map::kBitFieldOffset), __ test_b(FieldOperand(scratch, Map::kBitFieldOffset),
Immediate(Map::IsConstructorBit::kMask)); Immediate(Map::IsConstructorBit::kMask));
__ j(not_zero, &new_target_constructor, Label::kNear); __ j(not_zero, &new_target_constructor, Label::kNear);
__ bind(&new_target_not_constructor); __ bind(&new_target_not_constructor);
...@@ -1816,18 +1827,18 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm, ...@@ -1816,18 +1827,18 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
FrameScope scope(masm, StackFrame::MANUAL); FrameScope scope(masm, StackFrame::MANUAL);
__ EnterFrame(StackFrame::INTERNAL); __ EnterFrame(StackFrame::INTERNAL);
__ Push(edx); __ Push(edx);
__ movd(esi, xmm0); // Restore the context.
__ CallRuntime(Runtime::kThrowNotConstructor); __ CallRuntime(Runtime::kThrowNotConstructor);
} }
__ bind(&new_target_constructor); __ bind(&new_target_constructor);
} }
// Preserve new.target (in case of [[Construct]]). __ movd(xmm1, edx); // Preserve new.target (in case of [[Construct]]).
__ movd(xmm0, edx);
// Check if we have an arguments adaptor frame below the function frame. // Check if we have an arguments adaptor frame below the function frame.
Label arguments_adaptor, arguments_done; Label arguments_adaptor, arguments_done;
__ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); __ mov(scratch, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
__ cmp(Operand(ebx, CommonFrameConstants::kContextOrFrameTypeOffset), __ cmp(Operand(scratch, CommonFrameConstants::kContextOrFrameTypeOffset),
Immediate(StackFrame::TypeToMarker(StackFrame::ARGUMENTS_ADAPTOR))); Immediate(StackFrame::TypeToMarker(StackFrame::ARGUMENTS_ADAPTOR)));
__ j(equal, &arguments_adaptor, Label::kNear); __ j(equal, &arguments_adaptor, Label::kNear);
{ {
...@@ -1835,13 +1846,14 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm, ...@@ -1835,13 +1846,14 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
__ mov(edx, FieldOperand(edx, JSFunction::kSharedFunctionInfoOffset)); __ mov(edx, FieldOperand(edx, JSFunction::kSharedFunctionInfoOffset));
__ movzx_w(edx, FieldOperand( __ movzx_w(edx, FieldOperand(
edx, SharedFunctionInfo::kFormalParameterCountOffset)); edx, SharedFunctionInfo::kFormalParameterCountOffset));
__ mov(ebx, ebp); __ mov(scratch, ebp);
} }
__ jmp(&arguments_done, Label::kNear); __ jmp(&arguments_done, Label::kNear);
__ bind(&arguments_adaptor); __ bind(&arguments_adaptor);
{ {
// Just load the length from the ArgumentsAdaptorFrame. // Just load the length from the ArgumentsAdaptorFrame.
__ mov(edx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); __ mov(edx,
Operand(scratch, ArgumentsAdaptorFrameConstants::kLengthOffset));
__ SmiUntag(edx); __ SmiUntag(edx);
} }
__ bind(&arguments_done); __ bind(&arguments_done);
...@@ -1859,7 +1871,7 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm, ...@@ -1859,7 +1871,7 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
__ PopReturnAddressTo(ecx); __ PopReturnAddressTo(ecx);
__ bind(&loop); __ bind(&loop);
{ {
__ Push(Operand(ebx, edx, times_pointer_size, 1 * kPointerSize)); __ Push(Operand(scratch, edx, times_pointer_size, 1 * kPointerSize));
__ dec(edx); __ dec(edx);
__ j(not_zero, &loop); __ j(not_zero, &loop);
} }
...@@ -1868,13 +1880,14 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm, ...@@ -1868,13 +1880,14 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
} }
__ bind(&stack_done); __ bind(&stack_done);
// Restore new.target (in case of [[Construct]]). __ movd(edx, xmm1); // Restore new.target (in case of [[Construct]]).
__ movd(edx, xmm0); __ movd(esi, xmm0); // Restore the context.
// Tail-call to the {code} handler. // Tail-call to the {code} handler.
__ Jump(code, RelocInfo::CODE_TARGET); __ Jump(code, RelocInfo::CODE_TARGET);
__ bind(&stack_overflow); __ bind(&stack_overflow);
__ movd(esi, xmm0); // Restore the context.
__ TailCallRuntime(Runtime::kThrowStackOverflow); __ TailCallRuntime(Runtime::kThrowStackOverflow);
} }
...@@ -2150,6 +2163,7 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) { ...@@ -2150,6 +2163,7 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
// static // static
void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
Assembler::SupportsRootRegisterScope supports_root_register(masm);
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : the number of arguments (not including the receiver) // -- eax : the number of arguments (not including the receiver)
// -- edx : the new target (checked to be a constructor) // -- edx : the new target (checked to be a constructor)
...@@ -2210,6 +2224,7 @@ void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) { ...@@ -2210,6 +2224,7 @@ void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) {
// static // static
void Builtins::Generate_Construct(MacroAssembler* masm) { void Builtins::Generate_Construct(MacroAssembler* masm) {
Assembler::SupportsRootRegisterScope supports_root_register(masm);
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- eax : the number of arguments (not including the receiver) // -- eax : the number of arguments (not including the receiver)
// -- edx : the new target (either the same as the constructor or // -- edx : the new target (either the same as the constructor or
......
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