Make address space manager use pagemap for next pointers (#356)

* Make address space manager use pagemap for next pointers

The address space manager uses the pagemap entry to form linked lists of
unused address space above MIN_CHUNK_SIZE.  It continues to use
references in the block below that threshold.

In the CHECK_CLIENT mode this makes it hard to corrupt the ASM as only
meta-data uses allocations below MIN_CHUNK_SIZE from the ASM. This
allocations will be protected with guard pages by the backend.

* address_space_core: use FreeChunk struct

Purely stylistic, NFCI.  This hides some somewhat gnarly reinterpret_cast-s in
favor of more, but hopefully less gnarly, casts elsewhere.

* Apply suggestions from code review

Co-authored-by: Nathaniel Wesley Filardo <nfilardo@microsoft.com>
This commit is contained in:
Matthew Parkinson
2021-07-23 15:09:30 +01:00
committed by GitHub
parent 84a5fb9450
commit b69505fc5d
3 changed files with 133 additions and 82 deletions

View File

@@ -90,7 +90,8 @@ namespace snmalloc
fixed_range_ == fixed_range, "Don't set SFINAE parameter!");
auto [heap_base, heap_length] = pagemap.init(base, length);
address_space.add_range(CapPtr<void, CBChunk>(heap_base), heap_length);
address_space.add_range(
CapPtr<void, CBChunk>(heap_base), heap_length, pagemap);
if constexpr (!fixed_range)
{
@@ -155,7 +156,7 @@ namespace snmalloc
auto& local = local_state->local_address_space;
#endif
p = local.template reserve_with_left_over<PAL>(size);
p = local.template reserve_with_left_over<PAL>(size, h.pagemap);
if (p != nullptr)
{
return p;
@@ -174,10 +175,10 @@ namespace snmalloc
}
#endif
PAL::template notify_using<NoZero>(refill.unsafe_ptr(), refill_size);
local.template add_range<PAL>(refill, refill_size);
local.template add_range<PAL>(refill, refill_size, h.pagemap);
// This should succeed
return local.template reserve_with_left_over<PAL>(size);
return local.template reserve_with_left_over<PAL>(size, h.pagemap);
}
#ifdef SNMALLOC_CHECK_CLIENT