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 2752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 | 2763 |
2764 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, | 2764 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, |
2765 uint32_t offset, | 2765 uint32_t offset, |
2766 wasm::WasmCodePosition position) { | 2766 wasm::WasmCodePosition position) { |
2767 DCHECK(module_ && module_->instance); | 2767 DCHECK(module_ && module_->instance); |
2768 uint32_t size = module_->instance->mem_size; | 2768 uint32_t size = module_->instance->mem_size; |
2769 byte memsize = wasm::WasmOpcodes::MemSize(memtype); | 2769 byte memsize = wasm::WasmOpcodes::MemSize(memtype); |
2770 | 2770 |
2771 // Check against the effective size. | 2771 // Check against the effective size. |
2772 size_t effective_size; | 2772 size_t effective_size; |
2773 if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { | 2773 if (size == 0) { |
2774 effective_size = 0; | 2774 effective_size = 0; |
2775 } else if (offset >= size || | |
2776 (static_cast<uint64_t>(offset) + memsize) > size) { | |
titzer
2016/09/28 18:09:51
Can you please add a comment here what is going on
gdeepti
2016/09/28 20:29:15
Done.
| |
2777 effective_size = size - memsize + 1; | |
2778 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), | |
2779 jsgraph()->IntPtrConstant(offset), | |
2780 jsgraph()->RelocatableInt32Constant( | |
2781 static_cast<uint32_t>(effective_size), | |
2782 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | |
2783 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | |
2784 DCHECK(offset >= effective_size); | |
2785 effective_size = offset - effective_size; | |
2775 } else { | 2786 } else { |
2776 effective_size = size - offset - memsize + 1; | 2787 effective_size = size - offset - memsize + 1; |
2777 } | 2788 CHECK(effective_size <= kMaxUInt32); |
2778 CHECK(effective_size <= kMaxUInt32); | |
2779 | 2789 |
2780 Uint32Matcher m(index); | 2790 Uint32Matcher m(index); |
2781 if (m.HasValue()) { | 2791 if (m.HasValue()) { |
2782 uint32_t value = m.Value(); | 2792 uint32_t value = m.Value(); |
2783 if (value < effective_size) { | 2793 if (value < effective_size) { |
2784 // The bounds check will always succeed. | 2794 // The bounds check will always succeed. |
2785 return; | 2795 return; |
2796 } | |
2786 } | 2797 } |
2787 } | 2798 } |
2788 | 2799 |
2789 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, | 2800 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, |
2790 jsgraph()->RelocatableInt32Constant( | 2801 jsgraph()->RelocatableInt32Constant( |
2791 static_cast<uint32_t>(effective_size), | 2802 static_cast<uint32_t>(effective_size), |
2792 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); | 2803 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
2793 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2804 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
2794 } | 2805 } |
2795 | 2806 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3310 function_->code_start_offset), | 3321 function_->code_start_offset), |
3311 compile_ms); | 3322 compile_ms); |
3312 } | 3323 } |
3313 | 3324 |
3314 return code; | 3325 return code; |
3315 } | 3326 } |
3316 | 3327 |
3317 } // namespace compiler | 3328 } // namespace compiler |
3318 } // namespace internal | 3329 } // namespace internal |
3319 } // namespace v8 | 3330 } // namespace v8 |
OLD | NEW |