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

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

Issue 215853005: Check stack limit in ArgumentAdaptorTrampoline. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix ws Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.js ('k') | test/mjsunit/regress/regress-353058.js » ('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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 // Make rdx the space we need for the array when it is unrolled onto the 1010 // Make rdx the space we need for the array when it is unrolled onto the
1011 // stack. 1011 // stack.
1012 __ PositiveSmiTimesPowerOfTwoToInteger64(rdx, rax, kPointerSizeLog2); 1012 __ PositiveSmiTimesPowerOfTwoToInteger64(rdx, rax, kPointerSizeLog2);
1013 // Check if the arguments will overflow the stack. 1013 // Check if the arguments will overflow the stack.
1014 __ cmpp(rcx, rdx); 1014 __ cmpp(rcx, rdx);
1015 __ j(greater, &okay); // Signed comparison. 1015 __ j(greater, &okay); // Signed comparison.
1016 1016
1017 // Out of stack space. 1017 // Out of stack space.
1018 __ Push(Operand(rbp, kFunctionOffset)); 1018 __ Push(Operand(rbp, kFunctionOffset));
1019 __ Push(rax); 1019 __ Push(rax);
1020 __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_FUNCTION); 1020 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
1021 __ bind(&okay); 1021 __ bind(&okay);
1022 // End of stack check. 1022 // End of stack check.
1023 1023
1024 // Push current index and limit. 1024 // Push current index and limit.
1025 const int kLimitOffset = 1025 const int kLimitOffset =
1026 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize; 1026 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize;
1027 const int kIndexOffset = kLimitOffset - 1 * kPointerSize; 1027 const int kIndexOffset = kLimitOffset - 1 * kPointerSize;
1028 __ Push(rax); // limit 1028 __ Push(rax); // limit
1029 __ Push(Immediate(0)); // index 1029 __ Push(Immediate(0)); // index
1030 1030
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 __ IncrementCounter(counters->string_ctor_gc_required(), 1); 1315 __ IncrementCounter(counters->string_ctor_gc_required(), 1);
1316 { 1316 {
1317 FrameScope scope(masm, StackFrame::INTERNAL); 1317 FrameScope scope(masm, StackFrame::INTERNAL);
1318 __ Push(rbx); 1318 __ Push(rbx);
1319 __ CallRuntime(Runtime::kNewStringWrapper, 1); 1319 __ CallRuntime(Runtime::kNewStringWrapper, 1);
1320 } 1320 }
1321 __ ret(0); 1321 __ ret(0);
1322 } 1322 }
1323 1323
1324 1324
1325 static void ArgumentsAdaptorStackCheck(MacroAssembler* masm,
1326 Label* stack_overflow) {
1327 // ----------- S t a t e -------------
1328 // -- rax : actual number of arguments
1329 // -- rbx : expected number of arguments
1330 // -- rdi: function (passed through to callee)
1331 // -----------------------------------
1332 // Check the stack for overflow. We are not trying to catch
1333 // interruptions (e.g. debug break and preemption) here, so the "real stack
1334 // limit" is checked.
1335 Label okay;
1336 __ LoadRoot(rdx, Heap::kRealStackLimitRootIndex);
1337 __ movp(rcx, rsp);
1338 // Make rcx the space we have left. The stack might already be overflowed
1339 // here which will cause rcx to become negative.
1340 __ subp(rcx, rdx);
1341 // Make rdx the space we need for the array when it is unrolled onto the
1342 // stack.
1343 __ PositiveSmiTimesPowerOfTwoToInteger64(rdx, rax, kPointerSizeLog2);
1344 // Check if the arguments will overflow the stack.
1345 __ cmpp(rcx, rdx);
1346 __ j(less_equal, stack_overflow); // Signed comparison.
1347 }
1348
1349
1325 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { 1350 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
1326 __ pushq(rbp); 1351 __ pushq(rbp);
1327 __ movp(rbp, rsp); 1352 __ movp(rbp, rsp);
1328 1353
1329 // Store the arguments adaptor context sentinel. 1354 // Store the arguments adaptor context sentinel.
1330 __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); 1355 __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1331 1356
1332 // Push the function on the stack. 1357 // Push the function on the stack.
1333 __ Push(rdi); 1358 __ Push(rdi);
1334 1359
(...skipping 25 matching lines...) Expand all
1360 // ----------- S t a t e ------------- 1385 // ----------- S t a t e -------------
1361 // -- rax : actual number of arguments 1386 // -- rax : actual number of arguments
1362 // -- rbx : expected number of arguments 1387 // -- rbx : expected number of arguments
1363 // -- rdi: function (passed through to callee) 1388 // -- rdi: function (passed through to callee)
1364 // ----------------------------------- 1389 // -----------------------------------
1365 1390
1366 Label invoke, dont_adapt_arguments; 1391 Label invoke, dont_adapt_arguments;
1367 Counters* counters = masm->isolate()->counters(); 1392 Counters* counters = masm->isolate()->counters();
1368 __ IncrementCounter(counters->arguments_adaptors(), 1); 1393 __ IncrementCounter(counters->arguments_adaptors(), 1);
1369 1394
1395 Label stack_overflow;
1396 ArgumentsAdaptorStackCheck(masm, &stack_overflow);
1397
1370 Label enough, too_few; 1398 Label enough, too_few;
1371 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); 1399 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset));
1372 __ cmpp(rax, rbx); 1400 __ cmpp(rax, rbx);
1373 __ j(less, &too_few); 1401 __ j(less, &too_few);
1374 __ cmpp(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); 1402 __ cmpp(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
1375 __ j(equal, &dont_adapt_arguments); 1403 __ j(equal, &dont_adapt_arguments);
1376 1404
1377 { // Enough parameters: Actual >= expected. 1405 { // Enough parameters: Actual >= expected.
1378 __ bind(&enough); 1406 __ bind(&enough);
1379 EnterArgumentsAdaptorFrame(masm); 1407 EnterArgumentsAdaptorFrame(masm);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 1460
1433 // Leave frame and return. 1461 // Leave frame and return.
1434 LeaveArgumentsAdaptorFrame(masm); 1462 LeaveArgumentsAdaptorFrame(masm);
1435 __ ret(0); 1463 __ ret(0);
1436 1464
1437 // ------------------------------------------- 1465 // -------------------------------------------
1438 // Dont adapt arguments. 1466 // Dont adapt arguments.
1439 // ------------------------------------------- 1467 // -------------------------------------------
1440 __ bind(&dont_adapt_arguments); 1468 __ bind(&dont_adapt_arguments);
1441 __ jmp(rdx); 1469 __ jmp(rdx);
1470
1471 __ bind(&stack_overflow);
1472 EnterArgumentsAdaptorFrame(masm);
1473 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, JUMP_FUNCTION);
1474 __ int3();
1442 } 1475 }
1443 1476
1444 1477
1445 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { 1478 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1446 // Lookup the function in the JavaScript frame. 1479 // Lookup the function in the JavaScript frame.
1447 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1480 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1448 { 1481 {
1449 FrameScope scope(masm, StackFrame::INTERNAL); 1482 FrameScope scope(masm, StackFrame::INTERNAL);
1450 // Pass function as argument. 1483 // Pass function as argument.
1451 __ Push(rax); 1484 __ Push(rax);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 __ bind(&ok); 1526 __ bind(&ok);
1494 __ ret(0); 1527 __ ret(0);
1495 } 1528 }
1496 1529
1497 1530
1498 #undef __ 1531 #undef __
1499 1532
1500 } } // namespace v8::internal 1533 } } // namespace v8::internal
1501 1534
1502 #endif // V8_TARGET_ARCH_X64 1535 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/runtime.js ('k') | test/mjsunit/regress/regress-353058.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698