From 22c9891c4f8973e92fc62396b1efd9087b540432 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 7 Sep 2023 12:51:41 -0400 Subject: [PATCH] Add page_address() --- src/hulk/pagetable.d | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hulk/pagetable.d b/src/hulk/pagetable.d index 81468fe..61ed22f 100644 --- a/src/hulk/pagetable.d +++ b/src/hulk/pagetable.d @@ -183,3 +183,11 @@ struct PageTable } } static assert(PageTable.sizeof == 4096u); + +/** + * Get the base address of the page containing the given address. + */ +T page_address(T)(T address) +{ + return cast(T)(cast(ulong)address & ~(PAGE_SIZE - 1u)); +}