Added reverse lookup to Pagemap
This commit is contained in:
@@ -185,6 +185,21 @@ namespace snmalloc
|
||||
body = new_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of entries.
|
||||
*/
|
||||
constexpr size_t num_entries() const
|
||||
{
|
||||
if constexpr (has_bounds)
|
||||
{
|
||||
return size >> GRANULARITY_BITS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return bits::one_at_bit(bits::ADDRESS_BITS - GRANULARITY_BITS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the location has not been used before, then
|
||||
* `potentially_out_of_range` should be set to true.
|
||||
@@ -223,6 +238,21 @@ namespace snmalloc
|
||||
return body[p >> SHIFT];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the starting address corresponding to a given entry within the
|
||||
* Pagemap. Also checks that the reference actually points to a valid entry.
|
||||
*/
|
||||
address_t get_address(const T& t) const
|
||||
{
|
||||
address_t entry_offset = address_cast(&t) - address_cast(body);
|
||||
address_t entry_index = entry_offset / sizeof(T);
|
||||
if (entry_offset % sizeof(T) != 0 || entry_index >= num_entries())
|
||||
{
|
||||
PAL::error("Internal error: Invalid Pagemap entry for reverse lookup.");
|
||||
}
|
||||
return base + (entry_index << GRANULARITY_BITS);
|
||||
}
|
||||
|
||||
void set(address_t p, T t)
|
||||
{
|
||||
#ifdef SNMALLOC_TRACING
|
||||
|
||||
Reference in New Issue
Block a user