From 7ebfe9e09efa84044d1470132b7f55ebf53a7f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 20 Oct 2024 06:32:02 +0000 Subject: Fix next_table_address --- arch/x86_64/include/arch/memory/paging/page_table.hpp | 2 +- arch/x86_64/src/memory/paging/page_table.cpp | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) 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 da63d8c..73b75ad 100644 --- a/arch/x86_64/include/arch/memory/paging/page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp @@ -89,7 +89,7 @@ namespace teachos::arch::memory::paging * @param table_index Index of this page table in the page table one level higher. * @return An optional of the address of the next page table or null. */ - auto next_table_address(std::size_t table_index) const -> std::optional; + auto next_table_address(std::size_t table_index) -> std::optional; level current_level; ///< Current level of the page table, used to ensure next_table() is never called with a level ///< 1 page table diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp index a1cbc72..786ff69 100644 --- a/arch/x86_64/src/memory/paging/page_table.cpp +++ b/arch/x86_64/src/memory/paging/page_table.cpp @@ -29,7 +29,7 @@ namespace teachos::arch::memory::paging if (address.has_value()) { - current_table = reinterpret_cast(*address); + current_table = reinterpret_cast(address.value()); current_level = static_cast(current_level - 1U); } } @@ -42,21 +42,13 @@ namespace teachos::arch::memory::paging return current_table->entries[index]; } - auto page_table::operator[](std::size_t index) const -> entry const & - { - // C array is not bounds checked, therefore we have to check ourselves, to ensure no out of bounds reads, which - // could be incredibly hard to debug later. - arch::exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] index out of bounds"); - return current_table->entries[index]; - } - - auto page_table::next_table_address(std::size_t table_index) const -> std::optional + auto page_table::next_table_address(std::size_t table_index) -> std::optional { auto entry = this->operator[](table_index); if (entry.contains_flags(entry::PRESENT) && !entry.contains_flags(entry::HUGE_PAGE)) { - std::size_t const table_address = reinterpret_cast(this); + std::size_t const table_address = reinterpret_cast(current_table); return (table_address << 9) | (table_index << 12); } // TODO: Implement behaviour for huge pages currently not done -- cgit v1.2.3