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

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

Issue 2173403002: Replace SmartArrayPointer<T> with unique_ptr<T[]> (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates 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
« no previous file with comments | « src/wasm/decoder.h ('k') | src/wasm/wasm-module.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/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
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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 pc_ = start_; 451 pc_ = start_;
452 function->sig = consume_sig(); // read signature 452 function->sig = consume_sig(); // read signature
453 function->name_offset = 0; // ---- name 453 function->name_offset = 0; // ---- name
454 function->name_length = 0; // ---- name length 454 function->name_length = 0; // ---- name length
455 function->code_start_offset = off(pc_); // ---- code start 455 function->code_start_offset = off(pc_); // ---- code start
456 function->code_end_offset = off(limit_); // ---- code end 456 function->code_end_offset = off(limit_); // ---- code end
457 457
458 if (ok()) VerifyFunctionBody(0, module_env, function); 458 if (ok()) VerifyFunctionBody(0, module_env, function);
459 459
460 FunctionResult result; 460 FunctionResult result;
461 result.CopyFrom(result_); // Copy error code and location. 461 result.MoveFrom(result_); // Copy error code and location.
462 result.val = function; 462 result.val = function;
463 return result; 463 return result;
464 } 464 }
465 465
466 // Decodes a single function signature at {start}. 466 // Decodes a single function signature at {start}.
467 FunctionSig* DecodeFunctionSignature(const byte* start) { 467 FunctionSig* DecodeFunctionSignature(const byte* start) {
468 pc_ = start; 468 pc_ = start;
469 FunctionSig* result = consume_sig(); 469 FunctionSig* result = consume_sig();
470 return ok() ? result : nullptr; 470 return ok() ? result : nullptr;
471 } 471 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 str << "in function " << WasmFunctionName(function, menv) << ": "; 555 str << "in function " << WasmFunctionName(function, menv) << ": ";
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_.MoveFrom(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
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
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
OLDNEW
« no previous file with comments | « src/wasm/decoder.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698