diff --git a/src/pal/pal_linux.h b/src/pal/pal_linux.h index 139a6af..aa28ded 100644 --- a/src/pal/pal_linux.h +++ b/src/pal/pal_linux.h @@ -34,6 +34,14 @@ namespace snmalloc */ static constexpr int default_mmap_flags = MAP_NORESERVE; + static void* reserve(size_t size) noexcept + { + void* p = PALPOSIX::reserve(size); + if (p) + madvise(p, size, MADV_DONTDUMP); + return p; + } + /** * OS specific function for zeroing memory. * @@ -68,20 +76,40 @@ namespace snmalloc { SNMALLOC_ASSERT(is_aligned_block(p, size)); + // Fill memory so that when we switch the pages back on we don't make + // assumptions on the content. + if constexpr (DEBUG) + memset(p, 0x5a, size); + + madvise(p, size, MADV_DONTDUMP); + madvise(p, size, MADV_FREE); + if constexpr (PalEnforceAccess) { - // Fill memory so that when we switch the pages back on we don't make - // assumptions on the content. - if constexpr (DEBUG) - memset(p, 0x5a, size); - - madvise(p, size, MADV_FREE); mprotect(p, size, PROT_NONE); } - else - { - madvise(p, size, MADV_FREE); - } + } + + /** + * Notify platform that we will be using these pages for reading. + * + * This is used only for pages full of zeroes and so we exclude them from + * core dumps. + */ + static void notify_using_readonly(void* p, size_t size) noexcept + { + PALPOSIX::notify_using_readonly(p, size); + madvise(p, size, MADV_DONTDUMP); + } + + /** + * Notify platform that we will be using these pages. + */ + template + static void notify_using(void* p, size_t size) noexcept + { + PALPOSIX::notify_using(p, size); + madvise(p, size, MADV_DODUMP); } static uint64_t get_entropy64()