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

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

Issue 1066843003: MIPS: 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
« src/mips/builtins-mips.cc ('K') | « src/mips/builtins-mips.cc ('k') | no next file » | 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 5
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #if V8_TARGET_ARCH_MIPS64 9 #if V8_TARGET_ARCH_MIPS64
10 10
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // Leave construct frame. 850 // Leave construct frame.
851 } 851 }
852 852
853 __ SmiScale(at, a1, kPointerSizeLog2); 853 __ SmiScale(at, a1, kPointerSizeLog2);
854 __ Daddu(sp, sp, Operand(at)); 854 __ Daddu(sp, sp, Operand(at));
855 __ Daddu(sp, sp, Operand(kPointerSize)); 855 __ Daddu(sp, sp, Operand(kPointerSize));
856 __ Jump(ra); 856 __ Jump(ra);
857 } 857 }
858 858
859 859
860 enum IsTagged { kArgcIsSmiTagged, kArgcIsUntaggedInt };
861
862
863 // Clobbers a2; preserves all other registers.
864 static void Generate_CheckStackOverflow(MacroAssembler* masm,
865 const int calleeOffset, Register argc,
866 IsTagged argc_is_tagged) {
867 // Check the stack for overflow. We are not trying to catch
868 // interruptions (e.g. debug break and preemption) here, so the "real stack
869 // limit" is checked.
870 Label okay;
871 __ LoadRoot(a2, Heap::kRealStackLimitRootIndex);
872 // Make a2 the space we have left. The stack might already be overflowed
873 // here which will cause r2 to become negative.
874 __ dsubu(a2, sp, a2);
875 // Check if the arguments will overflow the stack.
876 if (argc_is_tagged == kArgcIsSmiTagged) {
877 __ SmiScale(a7, v0, kPointerSizeLog2);
878 } else {
879 DCHECK(argc_is_tagged == kArgcIsUntaggedInt);
880 __ dsll(a7, argc, kPointerSizeLog2);
881 }
882 __ Branch(&okay, gt, a2, Operand(a7)); // Signed comparison.
883
884 // Out of stack space.
885 __ ld(a1, MemOperand(fp, calleeOffset));
886 __ Push(a1, argc);
887 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
888
889 __ bind(&okay);
890 }
891
892
860 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, 893 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
861 bool is_construct) { 894 bool is_construct) {
862 // Called from JSEntryStub::GenerateBody 895 // Called from JSEntryStub::GenerateBody
863 896
864 // ----------- S t a t e ------------- 897 // ----------- S t a t e -------------
865 // -- a0: code entry 898 // -- a0: code entry
866 // -- a1: function 899 // -- a1: function
867 // -- a2: receiver_pointer 900 // -- a2: receiver_pointer
868 // -- a3: argc 901 // -- a3: argc
869 // -- s0: argv 902 // -- s0: argv
870 // ----------------------------------- 903 // -----------------------------------
871 ProfileEntryHookStub::MaybeCallEntryHook(masm); 904 ProfileEntryHookStub::MaybeCallEntryHook(masm);
872 // Clear the context before we push it when entering the JS frame. 905 // Clear the context before we push it when entering the JS frame.
873 __ mov(cp, zero_reg); 906 __ mov(cp, zero_reg);
874 907
875 // Enter an internal frame. 908 // Enter an internal frame.
876 { 909 {
877 FrameScope scope(masm, StackFrame::INTERNAL); 910 FrameScope scope(masm, StackFrame::INTERNAL);
878 911
879 // Set up the context from the function argument. 912 // Set up the context from the function argument.
880 __ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); 913 __ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
881 914
882 // Push the function and the receiver onto the stack. 915 // Push the function and the receiver onto the stack.
883 __ Push(a1, a2); 916 __ Push(a1, a2);
884 917
918 // Check if we have enough stack space to push all arguments.
919 // The function is the first thing that was pushed above after entering
920 // the internal frame.
921 const int kFunctionOffset =
922 InternalFrameConstants::kCodeOffset - kPointerSize;
923 // Clobbers a2.
924 Generate_CheckStackOverflow(masm, kFunctionOffset, a3, kArgcIsUntaggedInt);
925
885 // Copy arguments to the stack in a loop. 926 // Copy arguments to the stack in a loop.
886 // a3: argc 927 // a3: argc
887 // s0: argv, i.e. points to first arg 928 // s0: argv, i.e. points to first arg
888 Label loop, entry; 929 Label loop, entry;
889 __ dsll(a4, a3, kPointerSizeLog2); 930 __ dsll(a4, a3, kPointerSizeLog2);
890 __ daddu(a6, s0, a4); 931 __ daddu(a6, s0, a4);
891 __ b(&entry); 932 __ b(&entry);
892 __ nop(); // Branch delay slot nop. 933 __ nop(); // Branch delay slot nop.
893 // a6 points past last arg. 934 // a6 points past last arg.
894 __ bind(&loop); 935 __ bind(&loop);
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 // Check formal and actual parameter counts. 1393 // Check formal and actual parameter counts.
1353 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), 1394 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
1354 RelocInfo::CODE_TARGET, ne, a2, Operand(a0)); 1395 RelocInfo::CODE_TARGET, ne, a2, Operand(a0));
1355 1396
1356 __ ld(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); 1397 __ ld(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
1357 ParameterCount expected(0); 1398 ParameterCount expected(0);
1358 __ InvokeCode(a3, expected, expected, JUMP_FUNCTION, NullCallWrapper()); 1399 __ InvokeCode(a3, expected, expected, JUMP_FUNCTION, NullCallWrapper());
1359 } 1400 }
1360 1401
1361 1402
1362 static void Generate_CheckStackOverflow(MacroAssembler* masm,
1363 const int calleeOffset) {
1364 // Check the stack for overflow. We are not trying to catch
1365 // interruptions (e.g. debug break and preemption) here, so the "real stack
1366 // limit" is checked.
1367 Label okay;
1368 __ LoadRoot(a2, Heap::kRealStackLimitRootIndex);
1369 // Make a2 the space we have left. The stack might already be overflowed
1370 // here which will cause a2 to become negative.
1371 __ dsubu(a2, sp, a2);
1372 // Check if the arguments will overflow the stack.
1373 __ SmiScale(a7, v0, kPointerSizeLog2);
1374 __ Branch(&okay, gt, a2, Operand(a7)); // Signed comparison.
1375
1376 // Out of stack space.
1377 __ ld(a1, MemOperand(fp, calleeOffset));
1378 __ Push(a1, v0);
1379 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
1380
1381 __ bind(&okay);
1382 }
1383
1384
1385 static void Generate_PushAppliedArguments(MacroAssembler* masm, 1403 static void Generate_PushAppliedArguments(MacroAssembler* masm,
1386 const int argumentsOffset, 1404 const int argumentsOffset,
1387 const int indexOffset, 1405 const int indexOffset,
1388 const int limitOffset) { 1406 const int limitOffset) {
1389 Label entry, loop; 1407 Label entry, loop;
1390 __ ld(a0, MemOperand(fp, indexOffset)); 1408 __ ld(a0, MemOperand(fp, indexOffset));
1391 __ Branch(&entry); 1409 __ Branch(&entry);
1392 1410
1393 // Load the current argument from the arguments array and push it to the 1411 // Load the current argument from the arguments array and push it to the
1394 // stack. 1412 // stack.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 __ push(a0); 1452 __ push(a0);
1435 1453
1436 // Returns (in v0) number of arguments to copy to stack as Smi. 1454 // Returns (in v0) number of arguments to copy to stack as Smi.
1437 if (targetIsArgument) { 1455 if (targetIsArgument) {
1438 __ InvokeBuiltin(Builtins::REFLECT_APPLY_PREPARE, CALL_FUNCTION); 1456 __ InvokeBuiltin(Builtins::REFLECT_APPLY_PREPARE, CALL_FUNCTION);
1439 } else { 1457 } else {
1440 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION); 1458 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION);
1441 } 1459 }
1442 1460
1443 // Returns the result in v0. 1461 // Returns the result in v0.
1444 Generate_CheckStackOverflow(masm, kFunctionOffset); 1462 Generate_CheckStackOverflow(masm, kFunctionOffset, v0, kArgcIsSmiTagged);
1445 1463
1446 // Push current limit and index. 1464 // Push current limit and index.
1447 const int kIndexOffset = 1465 const int kIndexOffset =
1448 StandardFrameConstants::kExpressionsOffset - (2 * kPointerSize); 1466 StandardFrameConstants::kExpressionsOffset - (2 * kPointerSize);
1449 const int kLimitOffset = 1467 const int kLimitOffset =
1450 StandardFrameConstants::kExpressionsOffset - (1 * kPointerSize); 1468 StandardFrameConstants::kExpressionsOffset - (1 * kPointerSize);
1451 __ mov(a1, zero_reg); 1469 __ mov(a1, zero_reg);
1452 __ Push(v0, a1); // Limit and initial index. 1470 __ Push(v0, a1); // Limit and initial index.
1453 1471
1454 // Get the receiver. 1472 // Get the receiver.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 __ ld(a0, MemOperand(fp, kFunctionOffset)); // get the function 1581 __ ld(a0, MemOperand(fp, kFunctionOffset)); // get the function
1564 __ push(a0); 1582 __ push(a0);
1565 __ ld(a0, MemOperand(fp, kArgumentsOffset)); // get the args array 1583 __ ld(a0, MemOperand(fp, kArgumentsOffset)); // get the args array
1566 __ push(a0); 1584 __ push(a0);
1567 __ ld(a0, MemOperand(fp, kNewTargetOffset)); // get the new.target 1585 __ ld(a0, MemOperand(fp, kNewTargetOffset)); // get the new.target
1568 __ push(a0); 1586 __ push(a0);
1569 // Returns argument count in v0. 1587 // Returns argument count in v0.
1570 __ InvokeBuiltin(Builtins::REFLECT_CONSTRUCT_PREPARE, CALL_FUNCTION); 1588 __ InvokeBuiltin(Builtins::REFLECT_CONSTRUCT_PREPARE, CALL_FUNCTION);
1571 1589
1572 // Returns result in v0. 1590 // Returns result in v0.
1573 Generate_CheckStackOverflow(masm, kFunctionOffset); 1591 Generate_CheckStackOverflow(masm, kFunctionOffset, v0, kArgcIsSmiTagged);
1574 1592
1575 // Push current limit and index. 1593 // Push current limit and index.
1576 const int kIndexOffset = 1594 const int kIndexOffset =
1577 StandardFrameConstants::kExpressionsOffset - (2 * kPointerSize); 1595 StandardFrameConstants::kExpressionsOffset - (2 * kPointerSize);
1578 const int kLimitOffset = 1596 const int kLimitOffset =
1579 StandardFrameConstants::kExpressionsOffset - (1 * kPointerSize); 1597 StandardFrameConstants::kExpressionsOffset - (1 * kPointerSize);
1580 __ push(v0); // limit 1598 __ push(v0); // limit
1581 __ mov(a1, zero_reg); // initial index 1599 __ mov(a1, zero_reg); // initial index
1582 __ push(a1); 1600 __ push(a1);
1583 // Push newTarget and callee functions 1601 // Push newTarget and callee functions
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 __ break_(0xCC); 1815 __ break_(0xCC);
1798 } 1816 }
1799 } 1817 }
1800 1818
1801 1819
1802 #undef __ 1820 #undef __
1803 1821
1804 } } // namespace v8::internal 1822 } } // namespace v8::internal
1805 1823
1806 #endif // V8_TARGET_ARCH_MIPS64 1824 #endif // V8_TARGET_ARCH_MIPS64
OLDNEW
« src/mips/builtins-mips.cc ('K') | « src/mips/builtins-mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698