Follow-up on #469 for Linux this time, overriding read only pages cod… (#471)

* Follow-up on #469 for Linux this time, overriding read only pages code path too.
This commit is contained in:
David CARLIER
2022-03-04 11:29:11 +00:00
committed by GitHub
parent 1a75316ba2
commit cf9b6290c7

View File

@@ -34,6 +34,14 @@ namespace snmalloc
*/
static constexpr int default_mmap_flags = MAP_NORESERVE;
static void* reserve(size_t size) noexcept
{
void* p = PALPOSIX<PALLinux>::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<page_size>(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<PALLinux>::notify_using_readonly(p, size);
madvise(p, size, MADV_DONTDUMP);
}
/**
* Notify platform that we will be using these pages.
*/
template<ZeroMem zero_mem>
static void notify_using(void* p, size_t size) noexcept
{
PALPOSIX<PALLinux>::notify_using<zero_mem>(p, size);
madvise(p, size, MADV_DODUMP);
}
static uint64_t get_entropy64()