From 31267f9d8554999f6a462dee4b690f78c4bb0fdc Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 15 Jul 2019 13:39:03 +0100 Subject: [PATCH 1/2] 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 From 5e9727c8cab2d4256dd42e8ca95d793666b13c20 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 15 Jul 2019 15:01:45 +0100 Subject: [PATCH 2/2] [NFC] clang format. --- src/mem/pagemap.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mem/pagemap.h b/src/mem/pagemap.h index 364b904..b8ef6fd 100644 --- a/src/mem/pagemap.h +++ b/src/mem/pagemap.h @@ -391,8 +391,7 @@ namespace snmalloc { assert((reinterpret_cast(&top) & (OS_PAGE_SIZE - 1)) == 0); return reinterpret_cast( - reinterpret_cast(&top[p >> SHIFT]) & ~(OS_PAGE_SIZE - 1)); + reinterpret_cast(&top[p >> SHIFT]) & ~(OS_PAGE_SIZE - 1)); } - }; } // namespace snmalloc