Make pagemap check for init on some gets.

When we are accessing potentially out of range, then we might be
accessing before the pagemap has been initialised.  Move the check
into the pagemap for better codegen.
This commit is contained in:
Matthew Parkinson
2021-08-25 16:26:12 +01:00
committed by Matthew Parkinson
parent 44416ed70e
commit 27c4a6a55e
2 changed files with 46 additions and 36 deletions

View File

@@ -599,45 +599,38 @@ namespace snmalloc
{
#ifndef SNMALLOC_PASS_THROUGH
// TODO bring back the CHERI bits. Wes to review if required.
if (likely(is_initialised()))
MetaEntry entry =
SharedStateHandle::template get_meta_data<true>(address_cast(p_raw));
auto sizeclass = entry.get_sizeclass();
if (likely(entry.get_remote() != SharedStateHandle::fake_large_remote))
{
MetaEntry entry =
SharedStateHandle::template get_meta_data<true>(address_cast(p_raw));
auto sizeclass = entry.get_sizeclass();
if (likely(entry.get_remote() != SharedStateHandle::fake_large_remote))
auto rsize = sizeclass_to_size(sizeclass);
auto offset =
address_cast(p_raw) & (sizeclass_to_slab_size(sizeclass) - 1);
auto start_offset = round_by_sizeclass(sizeclass, offset);
if constexpr (location == Start)
{
auto rsize = sizeclass_to_size(sizeclass);
auto offset =
address_cast(p_raw) & (sizeclass_to_slab_size(sizeclass) - 1);
auto start_offset = round_by_sizeclass(sizeclass, offset);
if constexpr (location == Start)
{
UNUSED(rsize);
return pointer_offset(p_raw, start_offset - offset);
}
else if constexpr (location == End)
return pointer_offset(p_raw, rsize + start_offset - offset - 1);
else
return pointer_offset(p_raw, rsize + start_offset - offset);
}
// Sizeclass zero of a large allocation is used for not managed by us.
if (likely(sizeclass != 0))
{
// This is a large allocation, find start by masking.
auto rsize = bits::one_at_bit(sizeclass);
auto start = pointer_align_down(p_raw, rsize);
if constexpr (location == Start)
return start;
else if constexpr (location == End)
return pointer_offset(start, rsize);
else
return pointer_offset(start, rsize - 1);
UNUSED(rsize);
return pointer_offset(p_raw, start_offset - offset);
}
else if constexpr (location == End)
return pointer_offset(p_raw, rsize + start_offset - offset - 1);
else
return pointer_offset(p_raw, rsize + start_offset - offset);
}
else
// Sizeclass zero of a large allocation is used for not managed by us.
if (likely(sizeclass != 0))
{
// Allocator not initialised, so definitely not our allocation
// This is a large allocation, find start by masking.
auto rsize = bits::one_at_bit(sizeclass);
auto start = pointer_align_down(p_raw, rsize);
if constexpr (location == Start)
return start;
else if constexpr (location == End)
return pointer_offset(start, rsize);
else
return pointer_offset(start, rsize - 1);
}
#else
UNUSED(p_raw);