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

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

Issue 1582173002: X87: [builtins] Sanitize receiver patching for API functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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"
(...skipping 2236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 __ CallRuntime(Runtime::kThrowStackOverflow); 2247 __ CallRuntime(Runtime::kThrowStackOverflow);
2248 __ int3(); 2248 __ int3();
2249 } 2249 }
2250 } 2250 }
2251 2251
2252 2252
2253 static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver, 2253 static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
2254 Register function_template_info, 2254 Register function_template_info,
2255 Register scratch0, Register scratch1, 2255 Register scratch0, Register scratch1,
2256 Label* receiver_check_failed) { 2256 Label* receiver_check_failed) {
2257 // If receiver is not an object, jump to receiver_check_failed.
2258 __ CmpObjectType(receiver, FIRST_JS_OBJECT_TYPE, scratch0);
2259 __ j(below, receiver_check_failed);
2260
2261 // If there is no signature, return the holder. 2257 // If there is no signature, return the holder.
2262 __ CompareRoot(FieldOperand(function_template_info, 2258 __ CompareRoot(FieldOperand(function_template_info,
2263 FunctionTemplateInfo::kSignatureOffset), 2259 FunctionTemplateInfo::kSignatureOffset),
2264 Heap::kUndefinedValueRootIndex); 2260 Heap::kUndefinedValueRootIndex);
2265 Label receiver_check_passed; 2261 Label receiver_check_passed;
2266 __ j(equal, &receiver_check_passed, Label::kNear); 2262 __ j(equal, &receiver_check_passed, Label::kNear);
2267 2263
2268 // Walk the prototype chain. 2264 // Walk the prototype chain.
2269 Label prototype_loop_start; 2265 Label prototype_loop_start;
2270 __ bind(&prototype_loop_start); 2266 __ bind(&prototype_loop_start);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 // -- eax : number of arguments (not including the receiver) 2320 // -- eax : number of arguments (not including the receiver)
2325 // -- edi : callee 2321 // -- edi : callee
2326 // -- esi : context 2322 // -- esi : context
2327 // -- esp[0] : return address 2323 // -- esp[0] : return address
2328 // -- esp[4] : last argument 2324 // -- esp[4] : last argument
2329 // -- ... 2325 // -- ...
2330 // -- esp[eax * 4] : first argument 2326 // -- esp[eax * 4] : first argument
2331 // -- esp[(eax + 1) * 4] : receiver 2327 // -- esp[(eax + 1) * 4] : receiver
2332 // ----------------------------------- 2328 // -----------------------------------
2333 2329
2334 // Load the receiver.
2335 Operand receiver_operand(esp, eax, times_pointer_size, kPCOnStackSize);
2336 __ mov(ecx, receiver_operand);
2337
2338 // Update the receiver if this is a contextual call.
2339 Label set_global_proxy, valid_receiver;
2340 __ CompareRoot(ecx, Heap::kUndefinedValueRootIndex);
2341 __ j(equal, &set_global_proxy);
2342 __ bind(&valid_receiver);
2343
2344 // Load the FunctionTemplateInfo. 2330 // Load the FunctionTemplateInfo.
2345 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); 2331 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
2346 __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kFunctionDataOffset)); 2332 __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kFunctionDataOffset));
2347 2333
2348 // Do the compatible receiver check. 2334 // Do the compatible receiver check.
2349 Label receiver_check_failed; 2335 Label receiver_check_failed;
2336 __ mov(ecx, Operand(esp, eax, times_pointer_size, kPCOnStackSize));
2350 __ Push(eax); 2337 __ Push(eax);
2351 CompatibleReceiverCheck(masm, ecx, ebx, edx, eax, &receiver_check_failed); 2338 CompatibleReceiverCheck(masm, ecx, ebx, edx, eax, &receiver_check_failed);
2352 __ Pop(eax); 2339 __ Pop(eax);
2353 // Get the callback offset from the FunctionTemplateInfo, and jump to the 2340 // Get the callback offset from the FunctionTemplateInfo, and jump to the
2354 // beginning of the code. 2341 // beginning of the code.
2355 __ mov(edx, FieldOperand(ebx, FunctionTemplateInfo::kCallCodeOffset)); 2342 __ mov(edx, FieldOperand(ebx, FunctionTemplateInfo::kCallCodeOffset));
2356 __ mov(edx, FieldOperand(edx, CallHandlerInfo::kFastHandlerOffset)); 2343 __ mov(edx, FieldOperand(edx, CallHandlerInfo::kFastHandlerOffset));
2357 __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); 2344 __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag));
2358 __ jmp(edx); 2345 __ jmp(edx);
2359 2346
2360 __ bind(&set_global_proxy);
2361 __ mov(ecx, NativeContextOperand());
2362 __ mov(ecx, ContextOperand(ecx, Context::GLOBAL_PROXY_INDEX));
2363 __ mov(receiver_operand, ecx);
2364 __ jmp(&valid_receiver, Label::kNear);
2365
2366 // Compatible receiver check failed: pop return address, arguments and 2347 // Compatible receiver check failed: pop return address, arguments and
2367 // receiver and throw an Illegal Invocation exception. 2348 // receiver and throw an Illegal Invocation exception.
2368 __ bind(&receiver_check_failed); 2349 __ bind(&receiver_check_failed);
2369 __ Pop(eax); 2350 __ Pop(eax);
2370 __ PopReturnAddressTo(ebx); 2351 __ PopReturnAddressTo(ebx);
2371 __ lea(eax, Operand(eax, times_pointer_size, 1 * kPointerSize)); 2352 __ lea(eax, Operand(eax, times_pointer_size, 1 * kPointerSize));
2372 __ add(esp, eax); 2353 __ add(esp, eax);
2373 __ PushReturnAddressFrom(ebx); 2354 __ PushReturnAddressFrom(ebx);
2374 { 2355 {
2375 FrameScope scope(masm, StackFrame::INTERNAL); 2356 FrameScope scope(masm, StackFrame::INTERNAL);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 2412
2432 __ bind(&ok); 2413 __ bind(&ok);
2433 __ ret(0); 2414 __ ret(0);
2434 } 2415 }
2435 2416
2436 #undef __ 2417 #undef __
2437 } // namespace internal 2418 } // namespace internal
2438 } // namespace v8 2419 } // namespace v8
2439 2420
2440 #endif // V8_TARGET_ARCH_X87 2421 #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