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 2838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2849 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), val, | 2849 Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), val, |
2850 *effect_, *control_); | 2850 *effect_, *control_); |
2851 *effect_ = node; | 2851 *effect_ = node; |
2852 return node; | 2852 return node; |
2853 } | 2853 } |
2854 | 2854 |
2855 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, | 2855 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, |
2856 uint32_t offset, | 2856 uint32_t offset, |
2857 wasm::WasmCodePosition position) { | 2857 wasm::WasmCodePosition position) { |
2858 DCHECK(module_ && module_->instance); | 2858 DCHECK(module_ && module_->instance); |
2859 uint32_t size = module_->instance->mem_size; | 2859 uint32_t size = module_->module->min_mem_pages * module_->module->kPageSize; |
2860 byte memsize = wasm::WasmOpcodes::MemSize(memtype); | 2860 byte memsize = wasm::WasmOpcodes::MemSize(memtype); |
2861 | 2861 |
2862 // Check against the effective size. | 2862 // Check against the effective size. |
2863 size_t effective_size; | 2863 size_t effective_size; |
2864 if (size == 0) { | 2864 if (size == 0 || offset >= size || |
bradn
2016/10/14 01:17:07
Drop size==0, always true if the next clause is.
M
gdeepti
2016/10/14 01:28:44
Done.
| |
2865 effective_size = 0; | 2865 (static_cast<uint64_t>(offset) + memsize) > size) { |
2866 } else if (offset >= size || | |
2867 (static_cast<uint64_t>(offset) + memsize) > size) { | |
2868 // Two checks are needed in the case where the offset is statically | 2866 // Two checks are needed in the case where the offset is statically |
2869 // out of bounds; one check for the offset being in bounds, and the next for | 2867 // out of bounds; one check for the offset being in bounds, and the next for |
2870 // the offset + index being out of bounds for code to be patched correctly | 2868 // the offset + index being out of bounds for code to be patched correctly |
2871 // on relocation. | 2869 // on relocation. |
2872 effective_size = size - memsize + 1; | 2870 size_t effective_offset = offset + memsize - 1; |
2873 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), | 2871 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), |
2874 jsgraph()->IntPtrConstant(offset), | 2872 jsgraph()->IntPtrConstant(effective_offset), |
2875 jsgraph()->RelocatableInt32Constant( | 2873 jsgraph()->RelocatableInt32Constant( |
2876 static_cast<uint32_t>(effective_size), | 2874 static_cast<uint32_t>(size), |
2877 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | 2875 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
2878 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2876 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
2879 DCHECK(offset >= effective_size); | 2877 } |
2880 effective_size = offset - effective_size; | 2878 effective_size = size - offset - memsize + 1; |
bradn
2016/10/14 01:17:07
Maybe comment that this relies on the above check
gdeepti
2016/10/14 01:28:44
Done.
| |
2881 } else { | 2879 CHECK(effective_size <= kMaxUInt32); |
2882 effective_size = size - offset - memsize + 1; | |
2883 CHECK(effective_size <= kMaxUInt32); | |
2884 | 2880 |
2885 Uint32Matcher m(index); | 2881 Uint32Matcher m(index); |
2886 if (m.HasValue()) { | 2882 if (m.HasValue()) { |
2887 uint32_t value = m.Value(); | 2883 uint32_t value = m.Value(); |
2888 if (value < effective_size) { | 2884 if (value < effective_size) { |
2889 // The bounds check will always succeed. | 2885 // The bounds check will always succeed. |
2890 return; | 2886 return; |
2891 } | |
2892 } | 2887 } |
2893 } | 2888 } |
2894 | 2889 |
2895 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, | 2890 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, |
2896 jsgraph()->RelocatableInt32Constant( | 2891 jsgraph()->RelocatableInt32Constant( |
2897 static_cast<uint32_t>(effective_size), | 2892 static_cast<uint32_t>(effective_size), |
2898 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | 2893 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
2899 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2894 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
2900 } | 2895 } |
2901 | 2896 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3416 function_->code_start_offset), | 3411 function_->code_start_offset), |
3417 compile_ms); | 3412 compile_ms); |
3418 } | 3413 } |
3419 | 3414 |
3420 return code; | 3415 return code; |
3421 } | 3416 } |
3422 | 3417 |
3423 } // namespace compiler | 3418 } // namespace compiler |
3424 } // namespace internal | 3419 } // namespace internal |
3425 } // namespace v8 | 3420 } // namespace v8 |
OLD | NEW |