From d2f3d029081122bd21146275317de88d69302e89 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 25 Nov 2019 03:19:22 +1100 Subject: pre-fill things allocated with operator new with 0xcd in debug builds (value can be changed by setting global g_mame_new_prefill_byte with a debugger) - this is gonna hurt performance, but it will help catch issues exposed when we remove pre-clearing before constructing devices --- scripts/src/lib.lua | 1 + src/lib/util/corealloc.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/lib/util/corealloc.cpp diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index 28fb3b7c9a6..b66b41d2313 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -47,6 +47,7 @@ project "utils" MAME_DIR .. "src/lib/util/client_https.hpp", MAME_DIR .. "src/lib/util/client_ws.hpp", MAME_DIR .. "src/lib/util/client_wss.hpp", + MAME_DIR .. "src/lib/util/corealloc.cpp", MAME_DIR .. "src/lib/util/corealloc.h", MAME_DIR .. "src/lib/util/corefile.cpp", MAME_DIR .. "src/lib/util/corefile.h", diff --git a/src/lib/util/corealloc.cpp b/src/lib/util/corealloc.cpp new file mode 100644 index 00000000000..e3b7a458dbf --- /dev/null +++ b/src/lib/util/corealloc.cpp @@ -0,0 +1,34 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb +#include "corealloc.h" + +#include +#include +#include +#include + + +#ifdef MAME_DEBUG + +std::uint8_t g_mame_new_prefill_byte(0xcd); + +void *operator new(std::size_t n) +{ + void *const result(std::malloc(sz)); + if (ptr) + { + std::fill_n(reinterpret_cast(ptr), n, g_mame_new_prefill_byte); + return ptr; + } + else + { + throw std::bad_alloc(); + } +} + +void operator delete(void *ptr) noexcept +{ + std::free(ptr); +} + +#endif // MAME_DEBUG -- cgit v1.2.3