From 4b175fceeb9910953b3c49225c39963dde5e1fa3 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 29 Jan 2020 17:52:29 +0000 Subject: [PATCH] Make Posix platforms check Commit in Debug By turning page access on and off, we can simulate the Windows Commit/Decommit states on Posix platforms. This is just enabled in Debug for now. --- src/pal/pal_posix.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index 7c5b6b2..680c49c 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -54,8 +54,12 @@ namespace snmalloc void notify_not_using(void* p, size_t size) noexcept { assert(is_aligned_block(p, size)); +#ifndef NDEBUG + mprotect(p, size, PROT_NONE); +#else UNUSED(p); UNUSED(size); +#endif } /** @@ -72,11 +76,14 @@ namespace snmalloc if constexpr (zero_mem == YesZero) static_cast(this)->template zero(p, size); - else - { - UNUSED(p); - UNUSED(size); - } + +#ifndef NDEBUG + mprotect(p, size, PROT_READ | PROT_WRITE); +#else + UNUSED(p); + UNUSED(size); +#endif + } /**