Expose notify_using_readonly

This exposes a readonly notify using, so that the underlying platform
can map the range of pages readonly into the application.  This improves
performance of external pointer on platforms that support lazy commit
of pages as it can access anything in the range.
This commit is contained in:
Matthew Parkinson
2021-09-23 15:56:59 +01:00
committed by Matthew Parkinson
parent 0af1ee3bef
commit b4efc40aa6
3 changed files with 45 additions and 11 deletions

View File

@@ -196,7 +196,7 @@ namespace snmalloc
*
* On POSIX platforms, lazy commit means that this is a no-op, unless we
* are also zeroing the pages in which case we call the platform's `zero`
* function.
* function, or we have initially mapped the pages as PROT_NONE.
*/
template<ZeroMem zero_mem>
static void notify_using(void* p, size_t size) noexcept
@@ -215,6 +215,24 @@ namespace snmalloc
zero<true>(p, size);
}
/**
* Notify platform that we will be using these pages for reading.
*
* On POSIX platforms, lazy commit means that this is a no-op, unless
* we have initially mapped the pages as PROT_NONE.
*/
static void notify_using_readonly(void* p, size_t size) noexcept
{
SNMALLOC_ASSERT(is_aligned_block<OS::page_size>(p, size));
#ifdef SNMALLOC_CHECK_CLIENT
mprotect(p, size, PROT_READ);
#else
UNUSED(p);
UNUSED(size);
#endif
}
/**
* OS specific function for zeroing memory.
*