--scribble_heap, which memsets all allocated memory.

Already exposing bugs.
This commit is contained in:
Ben Vanik 2013-10-27 12:06:02 -07:00
parent 082df81f70
commit 6477d6c21e
1 changed files with 13 additions and 0 deletions

View File

@ -40,6 +40,9 @@ DEFINE_bool(
DEFINE_uint64( DEFINE_uint64(
heap_guard_pages, 0, heap_guard_pages, 0,
"Allocate the given number of guard pages around all heap chunks."); "Allocate the given number of guard pages around all heap chunks.");
DEFINE_bool(
scribble_heap, false,
"Scribble 0xCD into all allocated heap memory.");
/** /**
@ -524,6 +527,11 @@ uint32_t xe_memory_heap_t::Alloc(
PAGE_READWRITE); PAGE_READWRITE);
} }
if (FLAGS_scribble_heap) {
// Trash the memory so that we can see bad read-before-write bugs easier.
memset(p, 0xCD, alloc_size);
}
return (uint32_t)((uintptr_t)p - (uintptr_t)memory->mapping_base); return (uint32_t)((uintptr_t)p - (uintptr_t)memory->mapping_base);
} }
@ -539,6 +547,11 @@ uint32_t xe_memory_heap_t::Free(uint32_t address, uint32_t size) {
return 0; return 0;
} }
if (FLAGS_scribble_heap) {
// Trash the memory so that we can see bad read-before-write bugs easier.
memset(p, 0xDC, size);
}
XEIGNORE(xe_mutex_lock(mutex)); XEIGNORE(xe_mutex_lock(mutex));
if (FLAGS_heap_guard_pages) { if (FLAGS_heap_guard_pages) {
DWORD old_protect; DWORD old_protect;