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 "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 2511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2522 return jsgraph()->RelocatableIntPtrConstant( | 2522 return jsgraph()->RelocatableIntPtrConstant( |
2523 reinterpret_cast<uintptr_t>(module_->instance->mem_start + offset), | 2523 reinterpret_cast<uintptr_t>(module_->instance->mem_start + offset), |
2524 RelocInfo::WASM_MEMORY_REFERENCE); | 2524 RelocInfo::WASM_MEMORY_REFERENCE); |
2525 } | 2525 } |
2526 } | 2526 } |
2527 | 2527 |
2528 Node* WasmGraphBuilder::MemSize(uint32_t offset) { | 2528 Node* WasmGraphBuilder::MemSize(uint32_t offset) { |
2529 DCHECK(module_ && module_->instance); | 2529 DCHECK(module_ && module_->instance); |
2530 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); | 2530 uint32_t size = static_cast<uint32_t>(module_->instance->mem_size); |
2531 if (offset == 0) { | 2531 if (offset == 0) { |
2532 if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size); | 2532 if (!mem_size_) |
| 2533 mem_size_ = jsgraph()->RelocatableInt32Constant( |
| 2534 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
2533 return mem_size_; | 2535 return mem_size_; |
2534 } else { | 2536 } else { |
2535 return jsgraph()->Int32Constant(size + offset); | 2537 return jsgraph()->RelocatableInt32Constant( |
| 2538 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
2536 } | 2539 } |
2537 } | 2540 } |
2538 | 2541 |
2539 Node* WasmGraphBuilder::FunctionTable() { | 2542 Node* WasmGraphBuilder::FunctionTable() { |
2540 DCHECK(module_ && module_->instance && | 2543 DCHECK(module_ && module_->instance && |
2541 !module_->instance->function_table.is_null()); | 2544 !module_->instance->function_table.is_null()); |
2542 if (!function_table_) { | 2545 if (!function_table_) { |
2543 function_table_ = HeapConstant(module_->instance->function_table); | 2546 function_table_ = HeapConstant(module_->instance->function_table); |
2544 } | 2547 } |
2545 return function_table_; | 2548 return function_table_; |
(...skipping 26 matching lines...) Expand all Loading... |
2572 return node; | 2575 return node; |
2573 } | 2576 } |
2574 | 2577 |
2575 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, | 2578 void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, |
2576 uint32_t offset, | 2579 uint32_t offset, |
2577 wasm::WasmCodePosition position) { | 2580 wasm::WasmCodePosition position) { |
2578 DCHECK(module_ && module_->instance); | 2581 DCHECK(module_ && module_->instance); |
2579 size_t size = module_->instance->mem_size; | 2582 size_t size = module_->instance->mem_size; |
2580 byte memsize = wasm::WasmOpcodes::MemSize(memtype); | 2583 byte memsize = wasm::WasmOpcodes::MemSize(memtype); |
2581 | 2584 |
| 2585 // Check against the effective size. |
| 2586 size_t effective_size; |
2582 if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { | 2587 if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { |
2583 // The access will always throw (unless memory is grown). | 2588 effective_size = 0; |
2584 Node* cond = jsgraph()->Int32Constant(0); | 2589 } else { |
2585 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2590 effective_size = size - offset - memsize + 1; |
2586 return; | |
2587 } | 2591 } |
2588 | |
2589 // Check against the effective size. | |
2590 size_t effective_size = size - offset - memsize; | |
2591 CHECK(effective_size <= kMaxUInt32); | 2592 CHECK(effective_size <= kMaxUInt32); |
2592 | 2593 |
2593 Uint32Matcher m(index); | 2594 Uint32Matcher m(index); |
2594 if (m.HasValue()) { | 2595 if (m.HasValue()) { |
2595 uint32_t value = m.Value(); | 2596 uint32_t value = m.Value(); |
2596 if (value <= effective_size) { | 2597 if (value < effective_size) { |
2597 // The bounds check will always succeed. | 2598 // The bounds check will always succeed. |
2598 return; | 2599 return; |
2599 } | 2600 } |
2600 } | 2601 } |
2601 | 2602 |
2602 Node* cond = graph()->NewNode( | 2603 Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index, |
2603 jsgraph()->machine()->Uint32LessThanOrEqual(), index, | 2604 jsgraph()->RelocatableInt32Constant( |
2604 jsgraph()->Int32Constant(static_cast<uint32_t>(effective_size))); | 2605 static_cast<uint32_t>(effective_size), |
| 2606 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
2605 | 2607 |
2606 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); | 2608 trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
2607 } | 2609 } |
2608 | 2610 |
2609 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment, | 2611 MachineType WasmGraphBuilder::GetTypeForUnalignedAccess(uint32_t alignment, |
2610 bool signExtend) { | 2612 bool signExtend) { |
2611 switch (alignment) { | 2613 switch (alignment) { |
2612 case 0: | 2614 case 0: |
2613 return signExtend ? MachineType::Int8() : MachineType::Uint8(); | 2615 return signExtend ? MachineType::Int8() : MachineType::Uint8(); |
2614 case 1: | 2616 case 1: |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3284 function_->code_start_offset), | 3286 function_->code_start_offset), |
3285 compile_ms); | 3287 compile_ms); |
3286 } | 3288 } |
3287 | 3289 |
3288 return code; | 3290 return code; |
3289 } | 3291 } |
3290 | 3292 |
3291 } // namespace compiler | 3293 } // namespace compiler |
3292 } // namespace internal | 3294 } // namespace internal |
3293 } // namespace v8 | 3295 } // namespace v8 |
OLD | NEW |