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

Side by Side Diff: src/wasm/ast-decoder.cc

Issue 2447683004: [wasm] fix simd opcode read and error case for bad simd opcodes (Closed)
Patch Set: [wasm] fix simd opcode read and error case for bad simd opcodes Created 4 years, 1 month 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 | test/unittests/wasm/ast-decoder-unittest.cc » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 #include "src/signature.h" 5 #include "src/signature.h"
6 6
7 #include "src/bit-vector.h" 7 #include "src/bit-vector.h"
8 #include "src/flags.h" 8 #include "src/flags.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/zone/zone-containers.h" 10 #include "src/zone/zone-containers.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ImmI64Operand operand(this, pc); 317 ImmI64Operand operand(this, pc);
318 return 1 + operand.length; 318 return 1 + operand.length;
319 } 319 }
320 case kExprI8Const: 320 case kExprI8Const:
321 return 2; 321 return 2;
322 case kExprF32Const: 322 case kExprF32Const:
323 return 5; 323 return 5;
324 case kExprF64Const: 324 case kExprF64Const:
325 return 9; 325 return 9;
326 case kSimdPrefix: { 326 case kSimdPrefix: {
327 byte simd_index = *(pc + 1); 327 byte simd_index = checked_read_u8(pc, 1, "simd_index");
328 WasmOpcode opcode = 328 WasmOpcode opcode =
329 static_cast<WasmOpcode>(kSimdPrefix << 8 | simd_index); 329 static_cast<WasmOpcode>(kSimdPrefix << 8 | simd_index);
330 switch (opcode) { 330 switch (opcode) {
331 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: 331 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name:
332 FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE) 332 FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE)
333 #undef DECLARE_OPCODE_CASE 333 #undef DECLARE_OPCODE_CASE
334 { 334 {
335 return 2; 335 return 2;
336 } 336 }
337 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: 337 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name:
338 FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE) 338 FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE)
339 #undef DECLARE_OPCODE_CASE 339 #undef DECLARE_OPCODE_CASE
340 { 340 {
341 return 3; 341 return 3;
342 } 342 }
343 default: 343 default:
344 UNREACHABLE(); 344 error("invalid SIMD opcode");
345 return 2;
345 } 346 }
346 } 347 }
347 default: 348 default:
348 return 1; 349 return 1;
349 } 350 }
350 } 351 }
351 }; 352 };
352 353
353 static const int32_t kNullCatch = -1; 354 static const int32_t kNullCatch = -1;
354 355
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 TFNode** rets = nullptr; 1133 TFNode** rets = nullptr;
1133 BUILD(CallIndirect, operand.index, buffer, &rets, position()); 1134 BUILD(CallIndirect, operand.index, buffer, &rets, position());
1134 PushReturns(operand.sig, rets); 1135 PushReturns(operand.sig, rets);
1135 } 1136 }
1136 len = 1 + operand.length; 1137 len = 1 + operand.length;
1137 break; 1138 break;
1138 } 1139 }
1139 case kSimdPrefix: { 1140 case kSimdPrefix: {
1140 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); 1141 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype);
1141 len++; 1142 len++;
1142 byte simd_index = *(pc_ + 1); 1143 byte simd_index = checked_read_u8(pc_, 1, "simd index");
1143 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); 1144 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index);
1144 TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix, 1145 TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix,
1145 simd_index, WasmOpcodes::ShortOpcodeName(opcode)); 1146 simd_index, WasmOpcodes::ShortOpcodeName(opcode));
1146 len += DecodeSimdOpcode(opcode); 1147 len += DecodeSimdOpcode(opcode);
1147 break; 1148 break;
1148 } 1149 }
1149 default: { 1150 default: {
1150 // Deal with special asmjs opcodes. 1151 // Deal with special asmjs opcodes.
1151 if (module_ && module_->origin == kAsmJsOrigin) { 1152 if (module_ && module_->origin == kAsmJsOrigin) {
1152 sig = WasmOpcodes::AsmjsSignature(opcode); 1153 sig = WasmOpcodes::AsmjsSignature(opcode);
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, 1999 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
1999 const byte* start, const byte* end) { 2000 const byte* start, const byte* end) {
2000 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; 2001 FunctionBody body = {nullptr, nullptr, nullptr, start, end};
2001 WasmFullDecoder decoder(zone, nullptr, body); 2002 WasmFullDecoder decoder(zone, nullptr, body);
2002 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); 2003 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals);
2003 } 2004 }
2004 2005
2005 } // namespace wasm 2006 } // namespace wasm
2006 } // namespace internal 2007 } // namespace internal
2007 } // namespace v8 2008 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698