OLD | NEW |
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/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
6 #include "src/objects.h" | 6 #include "src/objects.h" |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/wasm/decoder.h" | 9 #include "src/wasm/decoder.h" |
10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 virtual void onFirstError() { | 39 virtual void onFirstError() { |
40 pc_ = limit_; // On error, terminate section decoding loop. | 40 pc_ = limit_; // On error, terminate section decoding loop. |
41 } | 41 } |
42 | 42 |
43 // Decodes an entire module. | 43 // Decodes an entire module. |
44 ModuleResult DecodeModule(WasmModule* module, bool verify_functions = true) { | 44 ModuleResult DecodeModule(WasmModule* module, bool verify_functions = true) { |
45 pc_ = start_; | 45 pc_ = start_; |
46 module->module_start = start_; | 46 module->module_start = start_; |
47 module->module_end = limit_; | 47 module->module_end = limit_; |
48 module->min_mem_size_log2 = 0; | 48 module->min_mem_pages = 0; |
49 module->max_mem_size_log2 = 0; | 49 module->max_mem_pages = 0; |
50 module->mem_export = false; | 50 module->mem_export = false; |
51 module->mem_external = false; | 51 module->mem_external = false; |
52 module->origin = origin_; | 52 module->origin = origin_; |
53 | 53 |
54 bool sections[kMaxModuleSectionCode]; | 54 bool sections[kMaxModuleSectionCode]; |
55 memset(sections, 0, sizeof(sections)); | 55 memset(sections, 0, sizeof(sections)); |
56 | 56 |
57 const byte* pos = pc_; | 57 const byte* pos = pc_; |
58 uint32_t magic_word = consume_u32("wasm magic"); | 58 uint32_t magic_word = consume_u32("wasm magic"); |
59 #define BYTES(x) (x & 0xff), (x >> 8) & 0xff, (x >> 16) & 0xff, (x >> 24) & 0xff | 59 #define BYTES(x) (x & 0xff), (x >> 8) & 0xff, (x >> 16) & 0xff, (x >> 24) & 0xff |
(...skipping 25 matching lines...) Expand all Loading... |
85 CheckForPreviousSection(sections, section, false); | 85 CheckForPreviousSection(sections, section, false); |
86 sections[section] = true; | 86 sections[section] = true; |
87 } | 87 } |
88 | 88 |
89 switch (section) { | 89 switch (section) { |
90 case kDeclEnd: | 90 case kDeclEnd: |
91 // Terminate section decoding. | 91 // Terminate section decoding. |
92 limit_ = pc_; | 92 limit_ = pc_; |
93 break; | 93 break; |
94 case kDeclMemory: | 94 case kDeclMemory: |
95 module->min_mem_size_log2 = consume_u8("min memory"); | 95 int length; |
96 module->max_mem_size_log2 = consume_u8("max memory"); | 96 module->min_mem_pages = consume_u32v(&length, "min memory"); |
| 97 module->max_mem_pages = consume_u32v(&length, "max memory"); |
97 module->mem_export = consume_u8("export memory") != 0; | 98 module->mem_export = consume_u8("export memory") != 0; |
98 break; | 99 break; |
99 case kDeclSignatures: { | 100 case kDeclSignatures: { |
100 int length; | 101 int length; |
101 uint32_t signatures_count = consume_u32v(&length, "signatures count"); | 102 uint32_t signatures_count = consume_u32v(&length, "signatures count"); |
102 module->signatures.reserve(SafeReserve(signatures_count)); | 103 module->signatures.reserve(SafeReserve(signatures_count)); |
103 // Decode signatures. | 104 // Decode signatures. |
104 for (uint32_t i = 0; i < signatures_count; i++) { | 105 for (uint32_t i = 0; i < signatures_count; i++) { |
105 if (failed()) break; | 106 if (failed()) break; |
106 TRACE("DecodeSignature[%d] module+%d\n", i, | 107 TRACE("DecodeSignature[%d] module+%d\n", i, |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 | 458 |
458 // Validate the data is in the module. | 459 // Validate the data is in the module. |
459 uint32_t module_limit = static_cast<uint32_t>(limit_ - start_); | 460 uint32_t module_limit = static_cast<uint32_t>(limit_ - start_); |
460 if (!IsWithinLimit(module_limit, segment->source_offset, | 461 if (!IsWithinLimit(module_limit, segment->source_offset, |
461 segment->source_size)) { | 462 segment->source_size)) { |
462 error(pc_ - sizeof(uint32_t), "segment out of bounds of module"); | 463 error(pc_ - sizeof(uint32_t), "segment out of bounds of module"); |
463 } | 464 } |
464 | 465 |
465 // Validate that the segment will fit into the (minimum) memory. | 466 // Validate that the segment will fit into the (minimum) memory. |
466 uint32_t memory_limit = | 467 uint32_t memory_limit = |
467 1 << (module ? module->min_mem_size_log2 : WasmModule::kMaxMemSize); | 468 WasmModule::kPageSize * (module ? module->min_mem_pages |
| 469 : WasmModule::kMaxMemPages); |
468 if (!IsWithinLimit(memory_limit, segment->dest_addr, | 470 if (!IsWithinLimit(memory_limit, segment->dest_addr, |
469 segment->source_size)) { | 471 segment->source_size)) { |
470 error(pc_ - sizeof(uint32_t), "segment out of bounds of memory"); | 472 error(pc_ - sizeof(uint32_t), "segment out of bounds of memory"); |
471 } | 473 } |
472 } | 474 } |
473 | 475 |
474 // Verifies the body (code) of a given function. | 476 // Verifies the body (code) of a given function. |
475 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, | 477 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, |
476 WasmFunction* function) { | 478 WasmFunction* function) { |
477 if (FLAG_trace_wasm_decode_time) { | 479 if (FLAG_trace_wasm_decode_time) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 if (function_start > function_end) return FunctionError("start > end"); | 652 if (function_start > function_end) return FunctionError("start > end"); |
651 if (size > kMaxFunctionSize) | 653 if (size > kMaxFunctionSize) |
652 return FunctionError("size > maximum function size"); | 654 return FunctionError("size > maximum function size"); |
653 WasmFunction* function = new WasmFunction(); | 655 WasmFunction* function = new WasmFunction(); |
654 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 656 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
655 return decoder.DecodeSingleFunction(module_env, function); | 657 return decoder.DecodeSingleFunction(module_env, function); |
656 } | 658 } |
657 } // namespace wasm | 659 } // namespace wasm |
658 } // namespace internal | 660 } // namespace internal |
659 } // namespace v8 | 661 } // namespace v8 |
OLD | NEW |