| OLD | NEW |
| 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/decoder.h" | 8 #include "src/wasm/decoder.h" |
| 9 #include "src/wasm/function-body-decoder.h" | 9 #include "src/wasm/function-body-decoder.h" |
| 10 #include "src/wasm/wasm-external-refs.h" | 10 #include "src/wasm/wasm-external-refs.h" |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 657 } |
| 658 | 658 |
| 659 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) { | 659 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) { |
| 660 return bit_cast<int64_t>(a); | 660 return bit_cast<int64_t>(a); |
| 661 } | 661 } |
| 662 | 662 |
| 663 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages, | 663 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages, |
| 664 WasmInstance* instance) { | 664 WasmInstance* instance) { |
| 665 // TODO(ahaas): Move memory allocation to wasm-module.cc for better | 665 // TODO(ahaas): Move memory allocation to wasm-module.cc for better |
| 666 // encapsulation. | 666 // encapsulation. |
| 667 if (delta_pages > wasm::kV8MaxWasmMemoryPages) { | 667 if (delta_pages > wasm::kV8MaxWasmMemoryPages || |
| 668 delta_pages > instance->module->max_mem_pages) { |
| 668 return -1; | 669 return -1; |
| 669 } | 670 } |
| 670 uint32_t old_size = instance->mem_size; | 671 uint32_t old_size = instance->mem_size; |
| 671 uint32_t new_size; | 672 uint32_t new_size; |
| 672 byte* new_mem_start; | 673 byte* new_mem_start; |
| 673 if (instance->mem_size == 0) { | 674 if (instance->mem_size == 0) { |
| 674 // TODO(gdeepti): Fix bounds check to take into account size of memtype. | 675 // TODO(gdeepti): Fix bounds check to take into account size of memtype. |
| 675 new_size = delta_pages * wasm::WasmModule::kPageSize; | 676 new_size = delta_pages * wasm::WasmModule::kPageSize; |
| 676 new_mem_start = static_cast<byte*>(calloc(new_size, sizeof(byte))); | 677 new_mem_start = static_cast<byte*>(calloc(new_size, sizeof(byte))); |
| 677 if (!new_mem_start) { | 678 if (!new_mem_start) { |
| 678 return -1; | 679 return -1; |
| 679 } | 680 } |
| 680 } else { | 681 } else { |
| 681 DCHECK_NOT_NULL(instance->mem_start); | 682 DCHECK_NOT_NULL(instance->mem_start); |
| 682 new_size = old_size + delta_pages * wasm::WasmModule::kPageSize; | 683 new_size = old_size + delta_pages * wasm::WasmModule::kPageSize; |
| 683 if (new_size > wasm::kV8MaxWasmMemoryPages * wasm::WasmModule::kPageSize) { | 684 if (new_size / wasm::WasmModule::kPageSize > wasm::kV8MaxWasmMemoryPages || |
| 685 new_size / wasm::WasmModule::kPageSize > |
| 686 instance->module->max_mem_pages) { |
| 684 return -1; | 687 return -1; |
| 685 } | 688 } |
| 686 new_mem_start = static_cast<byte*>(realloc(instance->mem_start, new_size)); | 689 new_mem_start = static_cast<byte*>(realloc(instance->mem_start, new_size)); |
| 687 if (!new_mem_start) { | 690 if (!new_mem_start) { |
| 688 return -1; | 691 return -1; |
| 689 } | 692 } |
| 690 // Zero initializing uninitialized memory from realloc | 693 // Zero initializing uninitialized memory from realloc |
| 691 memset(new_mem_start + old_size, 0, new_size - old_size); | 694 memset(new_mem_start + old_size, 0, new_size - old_size); |
| 692 } | 695 } |
| 693 instance->mem_start = new_mem_start; | 696 instance->mem_start = new_mem_start; |
| (...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 | 1885 |
| 1883 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1886 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
| 1884 Zone* zone, const byte* start, const byte* end) { | 1887 Zone* zone, const byte* start, const byte* end) { |
| 1885 ControlTransfers targets(zone, nullptr, start, end); | 1888 ControlTransfers targets(zone, nullptr, start, end); |
| 1886 return targets.map_; | 1889 return targets.map_; |
| 1887 } | 1890 } |
| 1888 | 1891 |
| 1889 } // namespace wasm | 1892 } // namespace wasm |
| 1890 } // namespace internal | 1893 } // namespace internal |
| 1891 } // namespace v8 | 1894 } // namespace v8 |
| OLD | NEW |