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/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 if (limit_ < start_) { | 37 if (limit_ < start_) { |
38 error(start_, "end is less than start"); | 38 error(start_, "end is less than start"); |
39 limit_ = start_; | 39 limit_ = start_; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 virtual void onFirstError() { | 43 virtual void onFirstError() { |
44 pc_ = limit_; // On error, terminate section decoding loop. | 44 pc_ = limit_; // On error, terminate section decoding loop. |
45 } | 45 } |
46 | 46 |
47 static void DumpModule(WasmModule* module, ModuleResult result) { | 47 static void DumpModule(WasmModule* module, const ModuleResult& result) { |
48 std::string path; | 48 std::string path; |
49 if (FLAG_dump_wasm_module_path) { | 49 if (FLAG_dump_wasm_module_path) { |
50 path = FLAG_dump_wasm_module_path; | 50 path = FLAG_dump_wasm_module_path; |
51 if (path.size() && | 51 if (path.size() && |
52 !base::OS::isDirectorySeparator(path[path.size() - 1])) { | 52 !base::OS::isDirectorySeparator(path[path.size() - 1])) { |
53 path += base::OS::DirectorySeparator(); | 53 path += base::OS::DirectorySeparator(); |
54 } | 54 } |
55 } | 55 } |
56 // File are named `HASH.{ok,failed}.wasm`. | 56 // File are named `HASH.{ok,failed}.wasm`. |
57 size_t hash = base::hash_range(module->module_start, module->module_end); | 57 size_t hash = base::hash_range(module->module_start, module->module_end); |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 str << result; | 556 str << result; |
557 std::string strval = str.str(); | 557 std::string strval = str.str(); |
558 const char* raw = strval.c_str(); | 558 const char* raw = strval.c_str(); |
559 size_t len = strlen(raw); | 559 size_t len = strlen(raw); |
560 char* buffer = new char[len]; | 560 char* buffer = new char[len]; |
561 strncpy(buffer, raw, len); | 561 strncpy(buffer, raw, len); |
562 buffer[len - 1] = 0; | 562 buffer[len - 1] = 0; |
563 | 563 |
564 // Copy error code and location. | 564 // Copy error code and location. |
565 result_.CopyFrom(result); | 565 result_.CopyFrom(result); |
566 result_.error_msg.Reset(buffer); | 566 result_.error_msg.reset(buffer); |
567 } | 567 } |
568 } | 568 } |
569 | 569 |
570 // Reads a single 32-bit unsigned integer interpreted as an offset, checking | 570 // Reads a single 32-bit unsigned integer interpreted as an offset, checking |
571 // the offset is within bounds and advances. | 571 // the offset is within bounds and advances. |
572 uint32_t consume_offset(const char* name = nullptr) { | 572 uint32_t consume_offset(const char* name = nullptr) { |
573 uint32_t offset = consume_u32(name ? name : "offset"); | 573 uint32_t offset = consume_u32(name ? name : "offset"); |
574 if (offset > static_cast<uint32_t>(limit_ - start_)) { | 574 if (offset > static_cast<uint32_t>(limit_ - start_)) { |
575 error(pc_ - sizeof(uint32_t), "offset out of bounds of module"); | 575 error(pc_ - sizeof(uint32_t), "offset out of bounds of module"); |
576 } | 576 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 | 683 |
684 // Helpers for nice error messages. | 684 // Helpers for nice error messages. |
685 class ModuleError : public ModuleResult { | 685 class ModuleError : public ModuleResult { |
686 public: | 686 public: |
687 explicit ModuleError(const char* msg) { | 687 explicit ModuleError(const char* msg) { |
688 error_code = kError; | 688 error_code = kError; |
689 size_t len = strlen(msg) + 1; | 689 size_t len = strlen(msg) + 1; |
690 char* result = new char[len]; | 690 char* result = new char[len]; |
691 strncpy(result, msg, len); | 691 strncpy(result, msg, len); |
692 result[len - 1] = 0; | 692 result[len - 1] = 0; |
693 error_msg.Reset(result); | 693 error_msg.reset(result); |
694 } | 694 } |
695 }; | 695 }; |
696 | 696 |
697 // Helpers for nice error messages. | 697 // Helpers for nice error messages. |
698 class FunctionError : public FunctionResult { | 698 class FunctionError : public FunctionResult { |
699 public: | 699 public: |
700 explicit FunctionError(const char* msg) { | 700 explicit FunctionError(const char* msg) { |
701 error_code = kError; | 701 error_code = kError; |
702 size_t len = strlen(msg) + 1; | 702 size_t len = strlen(msg) + 1; |
703 char* result = new char[len]; | 703 char* result = new char[len]; |
704 strncpy(result, msg, len); | 704 strncpy(result, msg, len); |
705 result[len - 1] = 0; | 705 result[len - 1] = 0; |
706 error_msg.Reset(result); | 706 error_msg.reset(result); |
707 } | 707 } |
708 }; | 708 }; |
709 | 709 |
710 Vector<const byte> FindSection(const byte* module_start, const byte* module_end, | 710 Vector<const byte> FindSection(const byte* module_start, const byte* module_end, |
711 WasmSection::Code code) { | 711 WasmSection::Code code) { |
712 Decoder decoder(module_start, module_end); | 712 Decoder decoder(module_start, module_end); |
713 | 713 |
714 uint32_t magic_word = decoder.consume_u32("wasm magic"); | 714 uint32_t magic_word = decoder.consume_u32("wasm magic"); |
715 if (magic_word != kWasmMagic) decoder.error("wrong magic word"); | 715 if (magic_word != kWasmMagic) decoder.error("wrong magic word"); |
716 | 716 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 decoder.consume_bytes(size); | 808 decoder.consume_bytes(size); |
809 } | 809 } |
810 if (decoder.more()) decoder.error("unexpected additional bytes"); | 810 if (decoder.more()) decoder.error("unexpected additional bytes"); |
811 | 811 |
812 return decoder.toResult(std::move(table)); | 812 return decoder.toResult(std::move(table)); |
813 } | 813 } |
814 | 814 |
815 } // namespace wasm | 815 } // namespace wasm |
816 } // namespace internal | 816 } // namespace internal |
817 } // namespace v8 | 817 } // namespace v8 |
OLD | NEW |