bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
+ CHECK(InVM(address, size));
return CommitRegion(address, size, is_executable);
}
bool VirtualMemory::Uncommit(void* address, size_t size) {
+ CHECK(InVM(address, size));
return UncommitRegion(address, size);
}
bool VirtualMemory::Guard(void* address) {
+ CHECK(InVM(address, OS::CommitPageSize()));
OS::Guard(address, OS::CommitPageSize());
return true;
}
DISALLOW_IMPLICIT_CONSTRUCTORS(OS);
};
+
// Represents and controls an area of reserved memory.
// Control of the reserved memory can be assigned to another VirtualMemory
// object by assignment or copy-contructing. This removes the reserved memory
// inside the allocated region.
void* address = address_;
size_t size = size_;
+ CHECK(InVM(address, size));
Reset();
bool result = ReleaseRegion(address, size);
USE(result);
static bool HasLazyCommits();
private:
+ bool InVM(void* address, size_t size) {
+ return (reinterpret_cast<intptr_t>(address_) <=
+ reinterpret_cast<intptr_t>(address)) &&
+ (reinterpret_cast<intptr_t>(address_) + size_ >=
+ reinterpret_cast<intptr_t>(address) + size);
+ }
+
void* address_; // Start address of the virtual memory.
size_t size_; // Size of the virtual memory.
};
Address CodeRange::AllocateRawMemory(const size_t requested_size,
const size_t commit_size,
size_t* allocated) {
- DCHECK(commit_size <= requested_size);
+ // request_size includes guards while committed_size does not. Make sure
+ // callers know about the invariant.
+ CHECK_LE(commit_size,
+ requested_size - 2 * MemoryAllocator::CodePageGuardSize());
FreeBlock current;
if (!ReserveBlock(requested_size, ¤t)) {
*allocated = 0;
CodePageGuardSize();
// Check executable memory limit.
- if (size_executable_ + chunk_size > capacity_executable_) {
+ if ((size_executable_ + chunk_size) > capacity_executable_) {
LOG(isolate_, StringEvent("MemoryAllocator::AllocateRawMemory",
"V8 Executable Allocation capacity exceeded"));
return NULL;
##############################################################################
['system == windows', {
- # BUG(3005).
- 'test-alloc/CodeRange': [PASS, FAIL],
-
# BUG(3331). Fails on windows.
'test-heap/NoWeakHashTableLeakWithIncrementalMarking': [SKIP],
(Page::kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) +
Pseudorandom() % 5000 + 1;
size_t allocated = 0;
- Address base = code_range.AllocateRawMemory(requested,
- requested,
- &allocated);
+
+ // The request size has to be at least 2 code guard pages larger than the
+ // actual commit size.
+ Address base = code_range.AllocateRawMemory(
+ requested, requested - (2 * MemoryAllocator::CodePageGuardSize()),
+ &allocated);
CHECK(base != NULL);
blocks.Add(::Block(base, static_cast<int>(allocated)));
current_allocated += static_cast<int>(allocated);
v8::internal::MemoryAllocator::CodePageAreaSize())) {
return;
}
+
Address address;
size_t size;
+ size_t request_size = code_range_size - 2 * pageSize;
address = code_range->AllocateRawMemory(
- code_range_size - 2 * pageSize, code_range_size - 2 * pageSize, &size);
+ request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()),
+ &size);
CHECK(address != NULL);
+
Address null_address;
size_t null_size;
+ request_size = code_range_size - pageSize;
null_address = code_range->AllocateRawMemory(
- code_range_size - pageSize, code_range_size - pageSize, &null_size);
+ request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()),
+ &null_size);
CHECK(null_address == NULL);
+
code_range->FreeRawMemory(address, size);
delete code_range;
memory_allocator->TearDown();