Commit 77aba17a authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[heap] Verify that newly allocated MemoryChunks are pre-initialzed with 0.

Bug: chromium:829771
Change-Id: I78eab59fded3f41c93ecb3d5d8a30e1bddc4576e
Reviewed-on: https://chromium-review.googlesource.com/1039747Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52925}
parent 996fe2d2
......@@ -883,6 +883,9 @@ MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size,
size_executable_.Increment(reservation.size());
}
VerifyCleared(base, CodePageGuardStartOffset());
VerifyCleared(base + CodePageAreaStartOffset(), commit_area_size);
if (Heap::ShouldZapGarbage()) {
ZapBlock(base, CodePageGuardStartOffset());
ZapBlock(base + CodePageAreaStartOffset(), commit_area_size);
......@@ -902,6 +905,8 @@ MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size,
if (base == kNullAddress) return nullptr;
VerifyCleared(base, Page::kObjectStartOffset + commit_area_size);
if (Heap::ShouldZapGarbage()) {
ZapBlock(base, Page::kObjectStartOffset + commit_area_size);
}
......@@ -1216,6 +1221,14 @@ void MemoryAllocator::ZapBlock(Address start, size_t size) {
}
}
void MemoryAllocator::VerifyCleared(Address start, size_t size) {
#ifdef VERIFY_HEAP
for (size_t i = 0; i < size / kPointerSize; i++) {
CHECK_EQ(reinterpret_cast<uintptr_t*>(start)[i], kClearedFreeMemoryValue);
}
#endif // VERIFY_HEAP
}
size_t MemoryAllocator::CodePageGuardStartOffset() {
// We are guarding code pages: the first OS page after the header
// will be protected as non-writable.
......
......@@ -1393,6 +1393,9 @@ class V8_EXPORT_PRIVATE MemoryAllocator {
// filling it up with a recognizable non-nullptr bit pattern.
void ZapBlock(Address start, size_t size);
// Checks if the memory [start..(start+size)[ is initialized with 0.
void VerifyCleared(Address start, size_t size);
V8_WARN_UNUSED_RESULT bool CommitExecutableMemory(VirtualMemory* vm,
Address start,
size_t commit_size,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment