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/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 | 10 |
(...skipping 2776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2787 | 2787 |
2788 *effect_ = call; | 2788 *effect_ = call; |
2789 return result; | 2789 return result; |
2790 } | 2790 } |
2791 | 2791 |
2792 Node* WasmGraphBuilder::MemSize(uint32_t offset) { | 2792 Node* WasmGraphBuilder::MemSize(uint32_t offset) { |
2793 DCHECK(module_ && module_->instance); | 2793 DCHECK(module_ && module_->instance); |
2794 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); | 2794 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); |
2795 if (offset == 0) { | 2795 if (offset == 0) { |
2796 if (!mem_size_) | 2796 if (!mem_size_) |
| 2797 // The memory size rmode in this case does not matter so using dword as |
| 2798 // default |
2797 mem_size_ = jsgraph()->RelocatableInt32Constant( | 2799 mem_size_ = jsgraph()->RelocatableInt32Constant( |
2798 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); | 2800 size, RelocInfo::WASM_MEMORY_DWORD_SIZE_REFERENCE); |
2799 return mem_size_; | 2801 return mem_size_; |
2800 } else { | 2802 } else { |
2801 return jsgraph()->RelocatableInt32Constant( | 2803 return jsgraph()->RelocatableInt32Constant( |
2802 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); | 2804 size + offset, RelocInfo::WASM_MEMORY_DWORD_SIZE_REFERENCE); |
2803 } | 2805 } |
2804 } | 2806 } |
2805 | 2807 |
2806 Node* WasmGraphBuilder::FunctionTable(uint32_t index) { | 2808 Node* WasmGraphBuilder::FunctionTable(uint32_t index) { |
2807 DCHECK(module_ && module_->instance && | 2809 DCHECK(module_ && module_->instance && |
2808 index < module_->instance->function_tables.size()); | 2810 index < module_->instance->function_tables.size()); |
2809 if (!function_tables_.size()) { | 2811 if (!function_tables_.size()) { |
2810 for (size_t i = 0; i < module_->instance->function_tables.size(); ++i) { | 2812 for (size_t i = 0; i < module_->instance->function_tables.size(); ++i) { |
2811 DCHECK(!module_->instance->function_tables[i].is_null()); | 2813 DCHECK(!module_->instance->function_tables[i].is_null()); |
2812 function_tables_.push_back( | 2814 function_tables_.push_back( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2844 *effect_ = node; | 2846 *effect_ = node; |
2845 return node; | 2847 return node; |
2846 } | 2848 } |
2847 | 2849 |
2848 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, | 2850 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, |
2849 uint32_t offset, | 2851 uint32_t offset, |
2850 wasm::WasmCodePosition position) { | 2852 wasm::WasmCodePosition position) { |
2851 DCHECK(module_ && module_->instance); | 2853 DCHECK(module_ && module_->instance); |
2852 uint32_t size = module_->instance->mem_size; | 2854 uint32_t size = module_->instance->mem_size; |
2853 byte memsize = wasm::WasmOpcodes::MemSize(memtype); | 2855 byte memsize = wasm::WasmOpcodes::MemSize(memtype); |
| 2856 RelocInfo::Mode size_rmode; |
| 2857 switch (memsize) { |
| 2858 case 1: |
| 2859 size_rmode = RelocInfo::WASM_MEMORY_BYTE_SIZE_REFERENCE; |
| 2860 break; |
| 2861 case 2: |
| 2862 size_rmode = RelocInfo::WASM_MEMORY_WORD_SIZE_REFERENCE; |
| 2863 break; |
| 2864 case 4: |
| 2865 size_rmode = RelocInfo::WASM_MEMORY_DWORD_SIZE_REFERENCE; |
| 2866 break; |
| 2867 case 8: |
| 2868 size_rmode = RelocInfo::WASM_MEMORY_QWORD_SIZE_REFERENCE; |
| 2869 break; |
| 2870 default: |
| 2871 size_rmode = RelocInfo::NONE32; |
| 2872 } |
2854 | 2873 |
2855 // Check against the effective size. | 2874 // Check against the effective size. |
2856 size_t effective_size; | 2875 size_t effective_size; |
2857 if (size == 0) { | 2876 if (size == 0) { |
2858 effective_size = 0; | 2877 effective_size = 0; |
2859 } else if (offset >= size || | 2878 } else if (offset >= size || |
2860 (static_cast<uint64_t>(offset) + memsize) > size) { | 2879 (static_cast<uint64_t>(offset) + memsize) > size) { |
2861 // Two checks are needed in the case where the offset is statically | 2880 // Two checks are needed in the case where the offset is statically |
2862 // out of bounds; one check for the offset being in bounds, and the next for | 2881 // out of bounds; one check for the offset being in bounds, and the next for |
2863 // the offset + index being out of bounds for code to be patched correctly | 2882 // the offset + index being out of bounds for code to be patched correctly |
2864 // on relocation. | 2883 // on relocation. |
2865 effective_size = size - memsize + 1; | 2884 effective_size = size - memsize + 1; |
2866 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), | 2885 Node* cond = graph()->NewNode( |
2867 jsgraph()->IntPtrConstant(offset), | 2886 jsgraph()->machine()->Uint32LessThan(), |
2868 jsgraph()->RelocatableInt32Constant( | 2887 jsgraph()->IntPtrConstant(offset), |
2869 static_cast<uint32_t>(effective_size), | 2888 jsgraph()->RelocatableInt32Constant( |
2870 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | 2889 static_cast<uint32_t>(effective_size), size_rmode)); |
2871 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2890 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
2872 DCHECK(offset >= effective_size); | 2891 DCHECK(offset >= effective_size); |
2873 effective_size = offset - effective_size; | 2892 effective_size = offset - effective_size; |
2874 } else { | 2893 } else { |
2875 effective_size = size - offset - memsize + 1; | 2894 effective_size = size - offset - memsize + 1; |
2876 CHECK(effective_size <= kMaxUInt32); | 2895 CHECK(effective_size <= kMaxUInt32); |
2877 | 2896 |
2878 Uint32Matcher m(index); | 2897 Uint32Matcher m(index); |
2879 if (m.HasValue()) { | 2898 if (m.HasValue()) { |
2880 uint32_t value = m.Value(); | 2899 uint32_t value = m.Value(); |
2881 if (value < effective_size) { | 2900 if (value < effective_size) { |
2882 // The bounds check will always succeed. | 2901 // The bounds check will always succeed. |
2883 return; | 2902 return; |
2884 } | 2903 } |
2885 } | 2904 } |
2886 } | 2905 } |
2887 | 2906 |
2888 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, | 2907 Node* cond = |
2889 jsgraph()->RelocatableInt32Constant( | 2908 graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, |
2890 static_cast<uint32_t>(effective_size), | 2909 jsgraph()->RelocatableInt32Constant( |
2891 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | 2910 static_cast<uint32_t>(effective_size), size_rmode)); |
2892 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2911 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
2893 } | 2912 } |
2894 | 2913 |
2895 | 2914 |
2896 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, | 2915 Node* WasmGraphBuilder::LoadMem(wasm::LocalType type, MachineType memtype, |
2897 Node* index, uint32_t offset, | 2916 Node* index, uint32_t offset, |
2898 uint32_t alignment, | 2917 uint32_t alignment, |
2899 wasm::WasmCodePosition position) { | 2918 wasm::WasmCodePosition position) { |
2900 Node* load; | 2919 Node* load; |
2901 | 2920 |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3409 function_->code_start_offset), | 3428 function_->code_start_offset), |
3410 compile_ms); | 3429 compile_ms); |
3411 } | 3430 } |
3412 | 3431 |
3413 return code; | 3432 return code; |
3414 } | 3433 } |
3415 | 3434 |
3416 } // namespace compiler | 3435 } // namespace compiler |
3417 } // namespace internal | 3436 } // namespace internal |
3418 } // namespace v8 | 3437 } // namespace v8 |
OLD | NEW |