From 31267f9d8554999f6a462dee4b690f78c4bb0fdc Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 15 Jul 2019 13:39:03 +0100 Subject: [PATCH] Add two APIs that are missing from the flat pagemap. --- src/mem/pagemap.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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