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/wasm/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
6 | 6 |
7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/flags.h" | 9 #include "src/flags.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 if (functions_count != module->num_declared_functions) { | 579 if (functions_count != module->num_declared_functions) { |
580 error(pos, pos, "function body count %u mismatch (%u expected)", | 580 error(pos, pos, "function body count %u mismatch (%u expected)", |
581 functions_count, module->num_declared_functions); | 581 functions_count, module->num_declared_functions); |
582 } | 582 } |
583 for (uint32_t i = 0; ok() && i < functions_count; ++i) { | 583 for (uint32_t i = 0; ok() && i < functions_count; ++i) { |
584 WasmFunction* function = | 584 WasmFunction* function = |
585 &module->functions[i + module->num_imported_functions]; | 585 &module->functions[i + module->num_imported_functions]; |
586 uint32_t size = consume_u32v("body size"); | 586 uint32_t size = consume_u32v("body size"); |
587 function->code_start_offset = pc_offset(); | 587 function->code_start_offset = pc_offset(); |
588 function->code_end_offset = pc_offset() + size; | 588 function->code_end_offset = pc_offset() + size; |
| 589 if (verify_functions) { |
| 590 ModuleEnv module_env; |
| 591 module_env.module = module; |
| 592 module_env.origin = module->origin; |
| 593 |
| 594 VerifyFunctionBody(i + module->num_imported_functions, &module_env, |
| 595 function); |
| 596 } |
589 consume_bytes(size, "function body"); | 597 consume_bytes(size, "function body"); |
590 } | 598 } |
591 section_iter.advance(); | 599 section_iter.advance(); |
592 } | 600 } |
593 | 601 |
594 // ===== Data section ==================================================== | 602 // ===== Data section ==================================================== |
595 if (section_iter.section_code() == kDataSectionCode) { | 603 if (section_iter.section_code() == kDataSectionCode) { |
596 uint32_t data_segments_count = consume_u32v("data segments count"); | 604 uint32_t data_segments_count = consume_u32v("data segments count"); |
597 module->data_segments.reserve(SafeReserve(data_segments_count)); | 605 module->data_segments.reserve(SafeReserve(data_segments_count)); |
598 for (uint32_t i = 0; ok() && i < data_segments_count; ++i) { | 606 for (uint32_t i = 0; ok() && i < data_segments_count; ++i) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 if (section_iter.more() && ok()) { | 647 if (section_iter.more() && ok()) { |
640 error(pc(), pc(), "unexpected section: %s", | 648 error(pc(), pc(), "unexpected section: %s", |
641 SectionName(section_iter.section_code())); | 649 SectionName(section_iter.section_code())); |
642 } | 650 } |
643 | 651 |
644 if (ok()) { | 652 if (ok()) { |
645 CalculateGlobalOffsets(module); | 653 CalculateGlobalOffsets(module); |
646 } | 654 } |
647 const WasmModule* finished_module = module; | 655 const WasmModule* finished_module = module; |
648 ModuleResult result = toResult(finished_module); | 656 ModuleResult result = toResult(finished_module); |
| 657 if (verify_functions && result.ok()) { |
| 658 result.MoveFrom(result_); // Copy error code and location. |
| 659 } |
649 if (FLAG_dump_wasm_module) DumpModule(module, result); | 660 if (FLAG_dump_wasm_module) DumpModule(module, result); |
650 return result; | 661 return result; |
651 } | 662 } |
652 | 663 |
653 uint32_t SafeReserve(uint32_t count) { | 664 uint32_t SafeReserve(uint32_t count) { |
654 // Avoid OOM by only reserving up to a certain size. | 665 // Avoid OOM by only reserving up to a certain size. |
655 const uint32_t kMaxReserve = 20000; | 666 const uint32_t kMaxReserve = 20000; |
656 return count < kMaxReserve ? count : kMaxReserve; | 667 return count < kMaxReserve ? count : kMaxReserve; |
657 } | 668 } |
658 | 669 |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 table.push_back(std::move(func_asm_offsets)); | 1240 table.push_back(std::move(func_asm_offsets)); |
1230 } | 1241 } |
1231 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1242 if (decoder.more()) decoder.error("unexpected additional bytes"); |
1232 | 1243 |
1233 return decoder.toResult(std::move(table)); | 1244 return decoder.toResult(std::move(table)); |
1234 } | 1245 } |
1235 | 1246 |
1236 } // namespace wasm | 1247 } // namespace wasm |
1237 } // namespace internal | 1248 } // namespace internal |
1238 } // namespace v8 | 1249 } // namespace v8 |
OLD | NEW |