PALSolaris AlignedAllocation feature implementation attempt. (#723)

This commit is contained in:
David CARLIER
2025-01-02 14:11:58 +00:00
committed by GitHub
parent 515b97d996
commit fb29a5e085

View File

@@ -17,13 +17,49 @@ namespace snmalloc
* PAL supports.
*
*/
static constexpr uint64_t pal_features = PALPOSIX::pal_features;
static constexpr uint64_t pal_features =
AlignedAllocation | PALPOSIX::pal_features;
static constexpr size_t page_size =
Aal::aal_name == Sparc ? 0x2000 : 0x1000;
static constexpr size_t minimum_alloc_size = page_size;
/**
* Solaris requires an explicit no-reserve flag in `mmap` to guarantee lazy
* commit.
*/
static constexpr int default_mmap_flags = MAP_NORESERVE;
/**
* Reserve memory at a specific alignment.
*/
template<bool state_using>
static void* reserve_aligned(size_t size) noexcept
{
// Alignment must be a power of 2.
SNMALLOC_ASSERT(bits::is_pow2(size));
SNMALLOC_ASSERT(size >= minimum_alloc_size);
UNUSED(state_using);
uintptr_t alignment =
static_cast<uintptr_t>(bits::align_up(size, page_size));
auto prot =
!mitigations(pal_enforce_access) ? PROT_READ | PROT_WRITE : PROT_NONE;
void* p = mmap(
(void*)alignment,
size,
prot,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGN | default_mmap_flags,
-1,
0);
if (p == MAP_FAILED)
return nullptr;
return p;
}
};
} // namespace snmalloc
#endif