From 6477d6c21eb3d8e2afbd80053beb1227e6ac5f26 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 27 Oct 2013 12:06:02 -0700 Subject: [PATCH] --scribble_heap, which memsets all allocated memory. Already exposing bugs. --- src/xenia/memory.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index b7127af34..73de43739 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -40,6 +40,9 @@ DEFINE_bool( DEFINE_uint64( heap_guard_pages, 0, "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); } + 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); } @@ -539,6 +547,11 @@ uint32_t xe_memory_heap_t::Free(uint32_t address, uint32_t size) { 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)); if (FLAGS_heap_guard_pages) { DWORD old_protect;