NFC: Introduce and switch to pal_zero
This wrapper will allow us to pass `AuthPtr<T,B> p` to zero() without needing to write `p.unsafe_auth_ptr` to get to a `T*` inside. Moreover, it will give us a convenient point to assert that `B` is such that the pointer can be used to manipulate the memory map (i.e. is not exported).
This commit is contained in:
committed by
Nathaniel Wesley Filardo
parent
4cfcf344fc
commit
7f841ff081
@@ -1026,7 +1026,8 @@ namespace snmalloc
|
||||
void* p = remove_cache_friendly_offset(fl.take(entropy), sizeclass);
|
||||
if constexpr (zero_mem == YesZero)
|
||||
{
|
||||
MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass));
|
||||
pal_zero<typename MemoryProvider::Pal>(
|
||||
p, sizeclass_to_size(sizeclass));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -1138,7 +1139,7 @@ namespace snmalloc
|
||||
|
||||
if constexpr (zero_mem == YesZero)
|
||||
{
|
||||
MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass));
|
||||
pal_zero<typename MemoryProvider::Pal>(p, sizeclass_to_size(sizeclass));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace snmalloc
|
||||
// The first page is already in "use" for the stack element,
|
||||
// this will need zeroing for a YesZero call.
|
||||
if constexpr (zero_mem == YesZero)
|
||||
MemoryProvider::Pal::template zero<true>(p, OS_PAGE_SIZE);
|
||||
pal_zero<typename MemoryProvider::Pal, true>(p, OS_PAGE_SIZE);
|
||||
|
||||
// Notify we are using the rest of the allocation.
|
||||
// Passing zero_mem ensures the PAL provides zeroed pages if
|
||||
@@ -331,7 +331,7 @@ namespace snmalloc
|
||||
{
|
||||
// This is a superslab that has not been decommitted.
|
||||
if constexpr (zero_mem == YesZero)
|
||||
MemoryProvider::Pal::template zero<true>(
|
||||
pal_zero<typename MemoryProvider::Pal, true>(
|
||||
p, bits::align_up(size, OS_PAGE_SIZE));
|
||||
else
|
||||
UNUSED(size);
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace snmalloc
|
||||
self->free--;
|
||||
|
||||
if constexpr (zero_mem == YesZero)
|
||||
PAL::zero(p, size);
|
||||
pal_zero<PAL>(p, size);
|
||||
else
|
||||
UNUSED(size);
|
||||
|
||||
|
||||
@@ -181,9 +181,9 @@ namespace snmalloc
|
||||
if constexpr (zero_mem == YesZero)
|
||||
{
|
||||
if (rsize < PAGE_ALIGNED_SIZE)
|
||||
PAL::zero(p, rsize);
|
||||
pal_zero<PAL>(p, rsize);
|
||||
else
|
||||
PAL::template zero<true>(p, rsize);
|
||||
pal_zero<PAL, true>(p, rsize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -69,6 +69,16 @@ namespace snmalloc
|
||||
// Used to keep Superslab metadata committed.
|
||||
static constexpr size_t OS_PAGE_SIZE = Pal::page_size;
|
||||
|
||||
/**
|
||||
* A centralized, inlinable wrapper around PAL::zero. This will matter more
|
||||
* when we introduce AuthPtr-s.
|
||||
*/
|
||||
template<typename PAL, bool page_aligned = false>
|
||||
static SNMALLOC_FAST_PATH void pal_zero(void* p, size_t sz)
|
||||
{
|
||||
PAL::template zero<page_aligned>(p, sz);
|
||||
}
|
||||
|
||||
static_assert(
|
||||
bits::is_pow2(OS_PAGE_SIZE), "OS_PAGE_SIZE must be a power of two");
|
||||
static_assert(
|
||||
|
||||
Reference in New Issue
Block a user