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

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

Issue 1418533009: X87: [builtins] Make sure argument count is always valid for C++ builtins. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | 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 #if V8_TARGET_ARCH_X87 5 #if V8_TARGET_ARCH_X87
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/codegen.h" 8 #include "src/codegen.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
11 #include "src/x87/frames-x87.h" 11 #include "src/x87/frames-x87.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 16
17 #define __ ACCESS_MASM(masm) 17 #define __ ACCESS_MASM(masm)
18 18
19 19
20 void Builtins::Generate_Adaptor(MacroAssembler* masm, 20 void Builtins::Generate_Adaptor(MacroAssembler* masm,
21 CFunctionId id, 21 CFunctionId id,
22 BuiltinExtraArguments extra_args) { 22 BuiltinExtraArguments extra_args) {
23 // ----------- S t a t e ------------- 23 // ----------- S t a t e -------------
24 // -- eax : number of arguments excluding receiver 24 // -- eax : number of arguments excluding receiver
25 // -- edi : called function (only guaranteed when 25 // (only guaranteed when the called function
26 // extra_args requires it) 26 // is not marked as DontAdaptArguments)
27 // -- edi : called function
27 // -- esp[0] : return address 28 // -- esp[0] : return address
28 // -- esp[4] : last argument 29 // -- esp[4] : last argument
29 // -- ... 30 // -- ...
30 // -- esp[4 * argc] : first argument (argc == eax) 31 // -- esp[4 * argc] : first argument
31 // -- esp[4 * (argc +1)] : receiver 32 // -- esp[4 * (argc +1)] : receiver
32 // ----------------------------------- 33 // -----------------------------------
33 __ AssertFunction(edi); 34 __ AssertFunction(edi);
34 35
35 // Make sure we operate in the context of the called function (for example 36 // Make sure we operate in the context of the called function (for example
36 // ConstructStubs implemented in C++ will be run in the context of the caller 37 // ConstructStubs implemented in C++ will be run in the context of the caller
37 // instead of the callee, due to the way that [[Construct]] is defined for 38 // instead of the callee, due to the way that [[Construct]] is defined for
38 // ordinary functions). 39 // ordinary functions).
39 // TODO(bmeurer): Can we make this more robust? 40 // TODO(bmeurer): Can we make this more robust?
40 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); 41 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
41 42
42 // Insert extra arguments. 43 // Insert extra arguments.
43 int num_extra_args = 0; 44 int num_extra_args = 0;
44 if (extra_args == NEEDS_CALLED_FUNCTION) { 45 if (extra_args == NEEDS_CALLED_FUNCTION) {
45 num_extra_args = 1; 46 num_extra_args = 1;
46 Register scratch = ebx; 47 Register scratch = ebx;
47 __ pop(scratch); // Save return address. 48 __ pop(scratch); // Save return address.
48 __ push(edi); 49 __ push(edi);
49 __ push(scratch); // Restore return address. 50 __ push(scratch); // Restore return address.
50 } else { 51 } else {
51 DCHECK(extra_args == NO_EXTRA_ARGUMENTS); 52 DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
52 } 53 }
53 54
54 // JumpToExternalReference expects eax to contain the number of arguments 55 // JumpToExternalReference expects eax to contain the number of arguments
55 // including the receiver and the extra arguments. 56 // including the receiver and the extra arguments. But eax is only valid
57 // if the called function is marked as DontAdaptArguments, otherwise we
58 // need to load the argument count from the SharedFunctionInfo.
59 Label argc, done_argc;
60 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
61 __ mov(ebx,
62 FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
63 __ SmiUntag(ebx);
64 __ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
65 __ j(equal, &argc, Label::kNear);
66 __ lea(eax, Operand(ebx, num_extra_args + 1));
67 __ jmp(&done_argc, Label::kNear);
68 __ bind(&argc);
56 __ add(eax, Immediate(num_extra_args + 1)); 69 __ add(eax, Immediate(num_extra_args + 1));
70 __ bind(&done_argc);
71
57 __ JumpToExternalReference(ExternalReference(id, masm->isolate())); 72 __ JumpToExternalReference(ExternalReference(id, masm->isolate()));
58 } 73 }
59 74
60 75
61 static void CallRuntimePassFunction( 76 static void CallRuntimePassFunction(
62 MacroAssembler* masm, Runtime::FunctionId function_id) { 77 MacroAssembler* masm, Runtime::FunctionId function_id) {
63 FrameScope scope(masm, StackFrame::INTERNAL); 78 FrameScope scope(masm, StackFrame::INTERNAL);
64 // Push a copy of the function. 79 // Push a copy of the function.
65 __ push(edi); 80 __ push(edi);
66 // Function is also the parameter to the runtime call. 81 // Function is also the parameter to the runtime call.
(...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 1847
1833 __ bind(&ok); 1848 __ bind(&ok);
1834 __ ret(0); 1849 __ ret(0);
1835 } 1850 }
1836 1851
1837 #undef __ 1852 #undef __
1838 } // namespace internal 1853 } // namespace internal
1839 } // namespace v8 1854 } // namespace v8
1840 1855
1841 #endif // V8_TARGET_ARCH_X87 1856 #endif // V8_TARGET_ARCH_X87
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698