Skip to content

Commit

Permalink
PALSolaris AlignedAllocation feature implementation attempt.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Dec 25, 2024
1 parent 141cdd9 commit aad55f9
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/snmalloc/pal/pal_solaris.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>((size + page_size - 1) & ~(page_size - 1));

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

0 comments on commit aad55f9

Please sign in to comment.