diff --git a/src/mem/pagemap.h b/src/mem/pagemap.h index d69b951..364b904 100644 --- a/src/mem/pagemap.h +++ b/src/mem/pagemap.h @@ -315,7 +315,7 @@ namespace snmalloc * stores a T. **/ template - class FlatPagemap + class alignas(OS_PAGE_SIZE) FlatPagemap { private: static constexpr size_t COVERED_BITS = @@ -375,5 +375,24 @@ namespace snmalloc length--; } while (length > 0); } + + /** + * Returns the index within a page for the specified address. + */ + size_t index_for_address(uintptr_t p) + { + return reinterpret_cast((p >> SHIFT) & (OS_PAGE_SIZE - 1)); + } + + /** + * Returns the address of the page containing the pagemap address p. + */ + void* page_for_address(uintptr_t p) + { + assert((reinterpret_cast(&top) & (OS_PAGE_SIZE - 1)) == 0); + return reinterpret_cast( + reinterpret_cast(&top[p >> SHIFT]) & ~(OS_PAGE_SIZE - 1)); + } + }; } // namespace snmalloc