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

Side by Side Diff: src/ia32/builtins-ia32.cc

Issue 1056913003: JSEntryTrampoline: check for stack space before pushing arguments (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « src/arm64/builtins-arm64.cc ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_IA32 7 #if V8_TARGET_ARCH_IA32
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 __ mov(ebx, Operand(esp, 0)); 567 __ mov(ebx, Operand(esp, 0));
568 } 568 }
569 569
570 __ pop(ecx); // Return address. 570 __ pop(ecx); // Return address.
571 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); 571 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize));
572 __ push(ecx); 572 __ push(ecx);
573 __ ret(0); 573 __ ret(0);
574 } 574 }
575 575
576 576
577 enum IsTagged { kEaxIsSmiTagged, kEaxIsUntaggedInt };
578
579
580 // Clobbers ecx, edx, edi; preserves all other registers.
581 static void Generate_CheckStackOverflow(MacroAssembler* masm,
582 const int calleeOffset,
583 IsTagged eax_is_tagged) {
584 // eax : the number of items to be pushed to the stack
585 //
586 // Check the stack for overflow. We are not trying to catch
587 // interruptions (e.g. debug break and preemption) here, so the "real stack
588 // limit" is checked.
589 Label okay;
590 ExternalReference real_stack_limit =
591 ExternalReference::address_of_real_stack_limit(masm->isolate());
592 __ mov(edi, Operand::StaticVariable(real_stack_limit));
593 // Make ecx the space we have left. The stack might already be overflowed
594 // here which will cause ecx to become negative.
595 __ mov(ecx, esp);
596 __ sub(ecx, edi);
597 // Make edx the space we need for the array when it is unrolled onto the
598 // stack.
599 __ mov(edx, eax);
600 int smi_tag = eax_is_tagged == kEaxIsSmiTagged ? kSmiTagSize : 0;
601 __ shl(edx, kPointerSizeLog2 - smi_tag);
602 // Check if the arguments will overflow the stack.
603 __ cmp(ecx, edx);
604 __ j(greater, &okay); // Signed comparison.
605
606 // Out of stack space.
607 __ push(Operand(ebp, calleeOffset)); // push this
608 __ push(eax);
609 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
610
611 __ bind(&okay);
612 }
613
614
577 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, 615 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
578 bool is_construct) { 616 bool is_construct) {
579 ProfileEntryHookStub::MaybeCallEntryHook(masm); 617 ProfileEntryHookStub::MaybeCallEntryHook(masm);
580 618
581 // Clear the context before we push it when entering the internal frame. 619 // Clear the context before we push it when entering the internal frame.
582 __ Move(esi, Immediate(0)); 620 __ Move(esi, Immediate(0));
583 621
584 { 622 {
585 FrameScope scope(masm, StackFrame::INTERNAL); 623 FrameScope scope(masm, StackFrame::INTERNAL);
586 624
587 // Load the previous frame pointer (ebx) to access C arguments 625 // Load the previous frame pointer (ebx) to access C arguments
588 __ mov(ebx, Operand(ebp, 0)); 626 __ mov(ebx, Operand(ebp, 0));
589 627
590 // Get the function from the frame and setup the context. 628 // Get the function from the frame and setup the context.
591 __ mov(ecx, Operand(ebx, EntryFrameConstants::kFunctionArgOffset)); 629 __ mov(ecx, Operand(ebx, EntryFrameConstants::kFunctionArgOffset));
592 __ mov(esi, FieldOperand(ecx, JSFunction::kContextOffset)); 630 __ mov(esi, FieldOperand(ecx, JSFunction::kContextOffset));
593 631
594 // Push the function and the receiver onto the stack. 632 // Push the function and the receiver onto the stack.
595 __ push(ecx); 633 __ push(ecx);
596 __ push(Operand(ebx, EntryFrameConstants::kReceiverArgOffset)); 634 __ push(Operand(ebx, EntryFrameConstants::kReceiverArgOffset));
597 635
598 // Load the number of arguments and setup pointer to the arguments. 636 // Load the number of arguments and setup pointer to the arguments.
599 __ mov(eax, Operand(ebx, EntryFrameConstants::kArgcOffset)); 637 __ mov(eax, Operand(ebx, EntryFrameConstants::kArgcOffset));
600 __ mov(ebx, Operand(ebx, EntryFrameConstants::kArgvOffset)); 638 __ mov(ebx, Operand(ebx, EntryFrameConstants::kArgvOffset));
601 639
640 // Check if we have enough stack space to push all arguments.
641 // The function is the first thing that was pushed above after entering
642 // the internal frame.
643 const int kFunctionOffset =
644 InternalFrameConstants::kCodeOffset - kPointerSize;
645 // Expects argument count in eax. Clobbers ecx, edx, edi.
646 Generate_CheckStackOverflow(masm, kFunctionOffset, kEaxIsUntaggedInt);
647
602 // Copy arguments to the stack in a loop. 648 // Copy arguments to the stack in a loop.
603 Label loop, entry; 649 Label loop, entry;
604 __ Move(ecx, Immediate(0)); 650 __ Move(ecx, Immediate(0));
605 __ jmp(&entry); 651 __ jmp(&entry);
606 __ bind(&loop); 652 __ bind(&loop);
607 __ mov(edx, Operand(ebx, ecx, times_4, 0)); // push parameter from argv 653 __ mov(edx, Operand(ebx, ecx, times_4, 0)); // push parameter from argv
608 __ push(Operand(edx, 0)); // dereference handle 654 __ push(Operand(edx, 0)); // dereference handle
609 __ inc(ecx); 655 __ inc(ecx);
610 __ bind(&entry); 656 __ bind(&entry);
611 __ cmp(ecx, eax); 657 __ cmp(ecx, eax);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 __ SmiUntag(ebx); 1029 __ SmiUntag(ebx);
984 __ cmp(eax, ebx); 1030 __ cmp(eax, ebx);
985 __ j(not_equal, 1031 __ j(not_equal,
986 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline()); 1032 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline());
987 1033
988 ParameterCount expected(0); 1034 ParameterCount expected(0);
989 __ InvokeCode(edx, expected, expected, JUMP_FUNCTION, NullCallWrapper()); 1035 __ InvokeCode(edx, expected, expected, JUMP_FUNCTION, NullCallWrapper());
990 } 1036 }
991 1037
992 1038
993 static void Generate_CheckStackOverflow(MacroAssembler* masm,
994 const int calleeOffset) {
995 // eax : the number of items to be pushed to the stack
996 //
997 // Check the stack for overflow. We are not trying to catch
998 // interruptions (e.g. debug break and preemption) here, so the "real stack
999 // limit" is checked.
1000 Label okay;
1001 ExternalReference real_stack_limit =
1002 ExternalReference::address_of_real_stack_limit(masm->isolate());
1003 __ mov(edi, Operand::StaticVariable(real_stack_limit));
1004 // Make ecx the space we have left. The stack might already be overflowed
1005 // here which will cause ecx to become negative.
1006 __ mov(ecx, esp);
1007 __ sub(ecx, edi);
1008 // Make edx the space we need for the array when it is unrolled onto the
1009 // stack.
1010 __ mov(edx, eax);
1011 __ shl(edx, kPointerSizeLog2 - kSmiTagSize);
1012 // Check if the arguments will overflow the stack.
1013 __ cmp(ecx, edx);
1014 __ j(greater, &okay); // Signed comparison.
1015
1016 // Out of stack space.
1017 __ push(Operand(ebp, calleeOffset)); // push this
1018 __ push(eax);
1019 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
1020
1021 __ bind(&okay);
1022 }
1023
1024
1025 static void Generate_PushAppliedArguments(MacroAssembler* masm, 1039 static void Generate_PushAppliedArguments(MacroAssembler* masm,
1026 const int argumentsOffset, 1040 const int argumentsOffset,
1027 const int indexOffset, 1041 const int indexOffset,
1028 const int limitOffset) { 1042 const int limitOffset) {
1029 // Copy all arguments from the array to the stack. 1043 // Copy all arguments from the array to the stack.
1030 Label entry, loop; 1044 Label entry, loop;
1031 Register receiver = LoadDescriptor::ReceiverRegister(); 1045 Register receiver = LoadDescriptor::ReceiverRegister();
1032 Register key = LoadDescriptor::NameRegister(); 1046 Register key = LoadDescriptor::NameRegister();
1033 __ mov(key, Operand(ebp, indexOffset)); 1047 __ mov(key, Operand(ebp, indexOffset));
1034 __ jmp(&entry); 1048 __ jmp(&entry);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 static const int kFunctionOffset = kReceiverOffset + kPointerSize; 1106 static const int kFunctionOffset = kReceiverOffset + kPointerSize;
1093 1107
1094 __ push(Operand(ebp, kFunctionOffset)); // push this 1108 __ push(Operand(ebp, kFunctionOffset)); // push this
1095 __ push(Operand(ebp, kArgumentsOffset)); // push arguments 1109 __ push(Operand(ebp, kArgumentsOffset)); // push arguments
1096 if (targetIsArgument) { 1110 if (targetIsArgument) {
1097 __ InvokeBuiltin(Builtins::REFLECT_APPLY_PREPARE, CALL_FUNCTION); 1111 __ InvokeBuiltin(Builtins::REFLECT_APPLY_PREPARE, CALL_FUNCTION);
1098 } else { 1112 } else {
1099 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION); 1113 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION);
1100 } 1114 }
1101 1115
1102 Generate_CheckStackOverflow(masm, kFunctionOffset); 1116 Generate_CheckStackOverflow(masm, kFunctionOffset, kEaxIsSmiTagged);
1103 1117
1104 // Push current index and limit. 1118 // Push current index and limit.
1105 const int kLimitOffset = 1119 const int kLimitOffset =
1106 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize; 1120 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize;
1107 const int kIndexOffset = kLimitOffset - 1 * kPointerSize; 1121 const int kIndexOffset = kLimitOffset - 1 * kPointerSize;
1108 __ push(eax); // limit 1122 __ push(eax); // limit
1109 __ push(Immediate(0)); // index 1123 __ push(Immediate(0)); // index
1110 1124
1111 // Get the receiver. 1125 // Get the receiver.
1112 __ mov(ebx, Operand(ebp, kReceiverOffset)); 1126 __ mov(ebx, Operand(ebp, kReceiverOffset));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 __ mov(eax, Operand(ebp, kFunctionOffset)); 1236 __ mov(eax, Operand(ebp, kFunctionOffset));
1223 __ mov(Operand(ebp, kNewTargetOffset), eax); 1237 __ mov(Operand(ebp, kNewTargetOffset), eax);
1224 1238
1225 // Validate arguments 1239 // Validate arguments
1226 __ bind(&validate_arguments); 1240 __ bind(&validate_arguments);
1227 __ push(Operand(ebp, kFunctionOffset)); 1241 __ push(Operand(ebp, kFunctionOffset));
1228 __ push(Operand(ebp, kArgumentsOffset)); 1242 __ push(Operand(ebp, kArgumentsOffset));
1229 __ push(Operand(ebp, kNewTargetOffset)); 1243 __ push(Operand(ebp, kNewTargetOffset));
1230 __ InvokeBuiltin(Builtins::REFLECT_CONSTRUCT_PREPARE, CALL_FUNCTION); 1244 __ InvokeBuiltin(Builtins::REFLECT_CONSTRUCT_PREPARE, CALL_FUNCTION);
1231 1245
1232 Generate_CheckStackOverflow(masm, kFunctionOffset); 1246 Generate_CheckStackOverflow(masm, kFunctionOffset, kEaxIsSmiTagged);
1233 1247
1234 // Push current index and limit. 1248 // Push current index and limit.
1235 const int kLimitOffset = 1249 const int kLimitOffset =
1236 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize; 1250 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize;
1237 const int kIndexOffset = kLimitOffset - 1 * kPointerSize; 1251 const int kIndexOffset = kLimitOffset - 1 * kPointerSize;
1238 __ Push(eax); // limit 1252 __ Push(eax); // limit
1239 __ push(Immediate(0)); // index 1253 __ push(Immediate(0)); // index
1240 // Push newTarget and callee functions 1254 // Push newTarget and callee functions
1241 __ push(Operand(ebp, kNewTargetOffset)); 1255 __ push(Operand(ebp, kNewTargetOffset));
1242 __ push(Operand(ebp, kFunctionOffset)); 1256 __ push(Operand(ebp, kFunctionOffset));
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 1687
1674 __ bind(&ok); 1688 __ bind(&ok);
1675 __ ret(0); 1689 __ ret(0);
1676 } 1690 }
1677 1691
1678 #undef __ 1692 #undef __
1679 } 1693 }
1680 } // namespace v8::internal 1694 } // namespace v8::internal
1681 1695
1682 #endif // V8_TARGET_ARCH_IA32 1696 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/arm64/builtins-arm64.cc ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698