From f9f047f519d0100c40b914d3ce777ac2f8430b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 28 Oct 2024 15:18:31 +0000 Subject: Add is empty check method for page table --- arch/x86_64/include/arch/memory/paging/page_mapper.hpp | 2 +- arch/x86_64/include/arch/memory/paging/page_table.hpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp index d852fbc..6a0c989 100644 --- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp @@ -146,10 +146,10 @@ namespace teachos::arch::memory::paging exception_handling::assert(level1_frame.has_value(), "[Page Mapper] Attempted to unmap page, which has not been mapped previously"); level1_entry.set_unused(); - invalidate_page_cache(&level1_entry); // TODO: Deallocate and unmap level 1, 2, 3 page table entry if this was the last page in them. // TODO: Fix deallocate because it is not yet implemented. allocator.deallocate_frame(level1_frame.value()); + invalidate_page_cache(&level1_entry); } } // namespace teachos::arch::memory::paging diff --git a/arch/x86_64/include/arch/memory/paging/page_table.hpp b/arch/x86_64/include/arch/memory/paging/page_table.hpp index e4847e3..07e7e22 100644 --- a/arch/x86_64/include/arch/memory/paging/page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp @@ -56,6 +56,11 @@ namespace teachos::arch::memory::paging */ auto zero_entries() -> void; + /** + * @brief Checks if all entries of this page are unused. + */ + auto is_empty() const -> bool; + /** * @brief Returns the next page table level from the given page table index. Meaning we * use an index into a Level 4 page table to get the according Level 3 page table. @@ -97,13 +102,21 @@ namespace teachos::arch::memory::paging } /** - * @brief Index operator overload to access specific immutable entry directy. + * @brief Index operator overload to access specific mutable entry directy. * * @param index Index of the entry we want to access and only read. * @return Entry at the given table index. */ auto operator[](std::size_t index) -> entry &; + /** + * @brief Index operator overload to access specific immutable entry directy. + * + * @param index Index of the entry we want to access and read or write. + * @return Entry at the given table index. + */ + auto operator[](std::size_t index) const -> entry const &; + /** * @brief Decrements the page table handle level enum by one, is defined so we can use it as a replacement for an * int index in a range based for loop. -- cgit v1.2.3