Expose mutable reference to pagemap
This commit is contained in:
committed by
Matthew Parkinson
parent
79486b6331
commit
69c824d54d
@@ -272,6 +272,20 @@ namespace snmalloc
|
||||
return concretePagemap.template get<potentially_out_of_range>(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata associated with a chunk.
|
||||
*
|
||||
* Set template parameter to true if it not an error
|
||||
* to access a location that is not backed by a chunk.
|
||||
*/
|
||||
template<bool potentially_out_of_range = false>
|
||||
SNMALLOC_FAST_PATH static MetaEntry&
|
||||
get_metaentry_mut(LocalState* ls, address_t p)
|
||||
{
|
||||
UNUSED(ls);
|
||||
return concretePagemap.template get_mut<potentially_out_of_range>(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the metadata associated with a chunk.
|
||||
*/
|
||||
|
||||
@@ -236,12 +236,12 @@ namespace snmalloc
|
||||
* read/write.
|
||||
*/
|
||||
template<bool potentially_out_of_range>
|
||||
const T& get(address_t p)
|
||||
T& get_mut(address_t p)
|
||||
{
|
||||
if constexpr (potentially_out_of_range)
|
||||
{
|
||||
if (SNMALLOC_UNLIKELY(body_opt == nullptr))
|
||||
return default_value;
|
||||
return const_cast<T&>(default_value);
|
||||
}
|
||||
|
||||
if constexpr (has_bounds)
|
||||
@@ -250,14 +250,14 @@ namespace snmalloc
|
||||
{
|
||||
if constexpr (potentially_out_of_range)
|
||||
{
|
||||
return default_value;
|
||||
return const_cast<T&>(default_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Out of range null should
|
||||
// still return the default value.
|
||||
if (p == 0)
|
||||
return default_value;
|
||||
return const_cast<T&>(default_value);
|
||||
PAL::error("Internal error: Pagemap read access out of range.");
|
||||
}
|
||||
}
|
||||
@@ -278,6 +278,18 @@ namespace snmalloc
|
||||
return body[p >> SHIFT];
|
||||
}
|
||||
|
||||
/**
|
||||
* If the location has not been used before, then
|
||||
* `potentially_out_of_range` should be set to true.
|
||||
* This will ensure there is a location for the
|
||||
* read/write.
|
||||
*/
|
||||
template<bool potentially_out_of_range>
|
||||
const T& get(address_t p)
|
||||
{
|
||||
return get_mut<potentially_out_of_range>(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the pagemap has been initialised.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user