diff --git a/src/backend/backend.h b/src/backend/backend.h index 232445e..e529ad8 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -272,6 +272,20 @@ namespace snmalloc return concretePagemap.template get(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 + SNMALLOC_FAST_PATH static MetaEntry& + get_metaentry_mut(LocalState* ls, address_t p) + { + UNUSED(ls); + return concretePagemap.template get_mut(p); + } + /** * Set the metadata associated with a chunk. */ diff --git a/src/backend/pagemap.h b/src/backend/pagemap.h index cbd32b9..18463b9 100644 --- a/src/backend/pagemap.h +++ b/src/backend/pagemap.h @@ -236,12 +236,12 @@ namespace snmalloc * read/write. */ template - 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(default_value); } if constexpr (has_bounds) @@ -250,14 +250,14 @@ namespace snmalloc { if constexpr (potentially_out_of_range) { - return default_value; + return const_cast(default_value); } else { // Out of range null should // still return the default value. if (p == 0) - return default_value; + return const_cast(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 + const T& get(address_t p) + { + return get_mut(p); + } + /** * Check if the pagemap has been initialised. */