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

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

Issue 2229723002: [wasm] Support validation of asm.js modules with != 3 args. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: file change Created 4 years, 4 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
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_X64 5 #if V8_TARGET_ARCH_X64
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 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 1055
1056 void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { 1056 void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) {
1057 // ----------- S t a t e ------------- 1057 // ----------- S t a t e -------------
1058 // -- rax : argument count (preserved for callee) 1058 // -- rax : argument count (preserved for callee)
1059 // -- rdx : new target (preserved for callee) 1059 // -- rdx : new target (preserved for callee)
1060 // -- rdi : target function (preserved for callee) 1060 // -- rdi : target function (preserved for callee)
1061 // ----------------------------------- 1061 // -----------------------------------
1062 Label failed; 1062 Label failed;
1063 { 1063 {
1064 FrameScope scope(masm, StackFrame::INTERNAL); 1064 FrameScope scope(masm, StackFrame::INTERNAL);
1065 // Preserve argument count for later compare.
1066 __ movp(kScratchRegister, rax);
1065 // Push the number of arguments to the callee. 1067 // Push the number of arguments to the callee.
1066 __ Integer32ToSmi(rax, rax); 1068 __ Integer32ToSmi(rax, rax);
1067 __ Push(rax); 1069 __ Push(rax);
1068 // Push a copy of the target function and the new target. 1070 // Push a copy of the target function and the new target.
1069 __ Push(rdi); 1071 __ Push(rdi);
1070 __ Push(rdx); 1072 __ Push(rdx);
1071 1073
1072 // The function. 1074 // The function.
1073 __ Push(rdi); 1075 __ Push(rdi);
1074 // Copy arguments from caller (stdlib, foreign, heap). 1076 // Copy arguments from caller (stdlib, foreign, heap).
1075 for (int i = 2; i >= 0; --i) { 1077 Label args_done;
1076 __ Push(Operand( 1078 for (int j = 0; j < 4; ++j) {
Michael Starzinger 2016/08/11 11:44:10 Does this work correctly in the case where we inst
bradn 2016/08/12 01:17:09 The validator rejects the module above as invalid
1077 rbp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize)); 1079 Label over;
1080 if (j < 3) {
1081 __ cmpp(kScratchRegister, Immediate(j));
1082 __ j(not_equal, &over, Label::kNear);
1083 }
1084 for (int i = j - 1; i >= 0; --i) {
1085 __ Push(Operand(
1086 rbp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize));
1087 }
1088 for (int i = 0; i < 3 - j; ++i) {
1089 __ PushRoot(Heap::kUndefinedValueRootIndex);
1090 }
1091 if (j < 3) {
1092 __ jmp(&args_done, Label::kNear);
1093 __ bind(&over);
1094 }
1078 } 1095 }
1096 __ bind(&args_done);
1097
1079 // Call runtime, on success unwind frame, and parent frame. 1098 // Call runtime, on success unwind frame, and parent frame.
1080 __ CallRuntime(Runtime::kInstantiateAsmJs, 4); 1099 __ CallRuntime(Runtime::kInstantiateAsmJs, 4);
1081 // A smi 0 is returned on failure, an object on success. 1100 // A smi 0 is returned on failure, an object on success.
1082 __ JumpIfSmi(rax, &failed, Label::kNear); 1101 __ JumpIfSmi(rax, &failed, Label::kNear);
1102
1103 __ Pop(kScratchRegister);
1104 __ Pop(kScratchRegister);
Michael Starzinger 2016/08/11 11:44:10 nit: Let's use __ Drop(2) instead of the multi-pop
bradn 2016/08/12 01:17:09 Good idea. Done.
1105 __ Pop(kScratchRegister);
1106 __ SmiToInteger32(kScratchRegister, kScratchRegister);
1083 scope.GenerateLeaveFrame(); 1107 scope.GenerateLeaveFrame();
1084 __ ret(4 * kPointerSize); 1108
1109 __ Pop(rbx);
Michael Starzinger 2016/08/11 11:44:10 nit: Lets use PopReturnAddressTo for readability.
bradn 2016/08/12 01:17:09 Done.
1110 __ incp(kScratchRegister);
1111 __ leap(rsp, Operand(rsp, kScratchRegister, times_pointer_size, 0));
1112 __ Push(rbx);
Michael Starzinger 2016/08/11 11:44:10 nit: Lets use PushReturnAddressFrom for readabilit
bradn 2016/08/12 01:17:09 Done.
1113 __ ret(0);
1085 1114
1086 __ bind(&failed); 1115 __ bind(&failed);
1087 // Restore target function and new target. 1116 // Restore target function and new target.
1088 __ Pop(rdx); 1117 __ Pop(rdx);
1089 __ Pop(rdi); 1118 __ Pop(rdi);
1090 __ Pop(rax); 1119 __ Pop(rax);
1091 __ SmiToInteger32(rax, rax); 1120 __ SmiToInteger32(rax, rax);
1092 } 1121 }
1093 // On failure, tail call back to regular js. 1122 // On failure, tail call back to regular js.
1094 GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy); 1123 GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { 3099 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) {
3071 Generate_OnStackReplacementHelper(masm, true); 3100 Generate_OnStackReplacementHelper(masm, true);
3072 } 3101 }
3073 3102
3074 #undef __ 3103 #undef __
3075 3104
3076 } // namespace internal 3105 } // namespace internal
3077 } // namespace v8 3106 } // namespace v8
3078 3107
3079 #endif // V8_TARGET_ARCH_X64 3108 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698