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

Side by Side Diff: src/wasm/wasm-interpreter.cc

Issue 2454503005: [wasm] Support for restricted table imports. (Closed)
Patch Set: Fix GC stress issue; tables weren't being reset correctly 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 | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-js.h » ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/wasm-interpreter.h" 5 #include "src/wasm/wasm-interpreter.h"
6 6
7 #include "src/utils.h" 7 #include "src/utils.h"
8 #include "src/wasm/ast-decoder.h" 8 #include "src/wasm/ast-decoder.h"
9 #include "src/wasm/decoder.h" 9 #include "src/wasm/decoder.h"
10 #include "src/wasm/wasm-external-refs.h" 10 #include "src/wasm/wasm-external-refs.h"
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 656 }
657 657
658 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) { 658 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) {
659 return bit_cast<int64_t>(a); 659 return bit_cast<int64_t>(a);
660 } 660 }
661 661
662 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages, 662 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages,
663 WasmInstance* instance) { 663 WasmInstance* instance) {
664 // TODO(ahaas): Move memory allocation to wasm-module.cc for better 664 // TODO(ahaas): Move memory allocation to wasm-module.cc for better
665 // encapsulation. 665 // encapsulation.
666 if (delta_pages > wasm::WasmModule::kMaxMemPages) { 666 if (delta_pages > wasm::WasmModule::kV8MaxPages) {
667 return -1; 667 return -1;
668 } 668 }
669 uint32_t old_size = instance->mem_size; 669 uint32_t old_size = instance->mem_size;
670 uint32_t new_size; 670 uint32_t new_size;
671 byte* new_mem_start; 671 byte* new_mem_start;
672 if (instance->mem_size == 0) { 672 if (instance->mem_size == 0) {
673 if (delta_pages > wasm::WasmModule::kMaxMemPages) {
674 return -1;
675 }
676 // TODO(gdeepti): Fix bounds check to take into account size of memtype. 673 // TODO(gdeepti): Fix bounds check to take into account size of memtype.
677 new_size = delta_pages * wasm::WasmModule::kPageSize; 674 new_size = delta_pages * wasm::WasmModule::kPageSize;
678 new_mem_start = static_cast<byte*>(calloc(new_size, sizeof(byte))); 675 new_mem_start = static_cast<byte*>(calloc(new_size, sizeof(byte)));
679 if (!new_mem_start) { 676 if (!new_mem_start) {
680 return -1; 677 return -1;
681 } 678 }
682 } else { 679 } else {
683 DCHECK_NOT_NULL(instance->mem_start); 680 DCHECK_NOT_NULL(instance->mem_start);
684 new_size = old_size + delta_pages * wasm::WasmModule::kPageSize; 681 new_size = old_size + delta_pages * wasm::WasmModule::kPageSize;
685 if (new_size > 682 if (new_size >
686 wasm::WasmModule::kMaxMemPages * wasm::WasmModule::kPageSize) { 683 wasm::WasmModule::kV8MaxPages * wasm::WasmModule::kPageSize) {
687 return -1; 684 return -1;
688 } 685 }
689 new_mem_start = static_cast<byte*>(realloc(instance->mem_start, new_size)); 686 new_mem_start = static_cast<byte*>(realloc(instance->mem_start, new_size));
690 if (!new_mem_start) { 687 if (!new_mem_start) {
691 return -1; 688 return -1;
692 } 689 }
693 // Zero initializing uninitialized memory from realloc 690 // Zero initializing uninitialized memory from realloc
694 memset(new_mem_start + old_size, 0, new_size - old_size); 691 memset(new_mem_start + old_size, 0, new_size - old_size);
695 } 692 }
696 instance->mem_start = new_mem_start; 693 instance->mem_start = new_mem_start;
697 instance->mem_size = new_size; 694 instance->mem_size = new_size;
698 // realloc
699 // update mem_start
700 // update mem_size
701 return static_cast<int32_t>(old_size / WasmModule::kPageSize); 695 return static_cast<int32_t>(old_size / WasmModule::kPageSize);
702 } 696 }
703 697
704 enum InternalOpcode { 698 enum InternalOpcode {
705 #define DECL_INTERNAL_ENUM(name, value) kInternal##name = value, 699 #define DECL_INTERNAL_ENUM(name, value) kInternal##name = value,
706 FOREACH_INTERNAL_OPCODE(DECL_INTERNAL_ENUM) 700 FOREACH_INTERNAL_OPCODE(DECL_INTERNAL_ENUM)
707 #undef DECL_INTERNAL_ENUM 701 #undef DECL_INTERNAL_ENUM
708 }; 702 };
709 703
710 static const char* OpcodeName(uint32_t val) { 704 static const char* OpcodeName(uint32_t val) {
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 1879
1886 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( 1880 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
1887 Zone* zone, const byte* start, const byte* end) { 1881 Zone* zone, const byte* start, const byte* end) {
1888 ControlTransfers targets(zone, nullptr, nullptr, start, end); 1882 ControlTransfers targets(zone, nullptr, nullptr, start, end);
1889 return targets.map_; 1883 return targets.map_;
1890 } 1884 }
1891 1885
1892 } // namespace wasm 1886 } // namespace wasm
1893 } // namespace internal 1887 } // namespace internal
1894 } // namespace v8 1888 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-js.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698