From 7d4139b6fa0214604f467a782951cdc0f90e903f Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Tue, 22 Oct 2024 08:00:57 +0000 Subject: fix page level -- operator --- arch/x86_64/include/arch/memory/paging/page_table.hpp | 4 ++-- arch/x86_64/src/memory/paging/page_table.cpp | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'arch/x86_64') 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 feb327a..e6542a2 100644 --- a/arch/x86_64/include/arch/memory/paging/page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp @@ -58,7 +58,7 @@ namespace teachos::arch::memory::paging * * @param table_index Index of this page table in the page table one level lower. */ - auto next_table(std::size_t table_index) const -> std::optional; + auto next_table(std::size_t table_index) -> std::optional; /** * @brief Index operator overload to access specific immutable entry directy. @@ -83,7 +83,7 @@ namespace teachos::arch::memory::paging * @param value Value we want to decrement on * @return level New level value decrement by one, meaning the level is also decrement by one Level4 --> Level3, ... */ - friend auto operator--(level value, int) -> level; + friend auto operator--(level & value, int) -> level; private: page_table * handle; ///< Handle to underlying page table, can never be null (invariant ensured by constructor) diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp index 555d38a..b229ff7 100644 --- a/arch/x86_64/src/memory/paging/page_table.cpp +++ b/arch/x86_64/src/memory/paging/page_table.cpp @@ -99,25 +99,30 @@ namespace teachos::arch::memory::paging auto page_table_handle::zero_entries() -> void { handle->zero_entries(); } - auto page_table_handle::next_table(std::size_t table_index) const -> std::optional + auto page_table_handle::next_table(std::size_t table_index) -> std::optional { exception_handling::assert(handle_level != page_table_handle::LEVEL1, "[Page Table] Attempted to call next_table on level 1 page table"); auto next_table = handle->next_table(table_index); if (next_table) { - return page_table_handle{next_table.value(), handle_level--}; + handle_level--; + return page_table_handle{next_table.value(), handle_level}; } return std::nullopt; } auto page_table_handle::operator[](std::size_t index) const -> entry { return handle->operator[](index); } - auto operator--(page_table_handle::level value, int) -> page_table_handle::level + auto operator--(page_table_handle::level & value, int) -> page_table_handle::level { exception_handling::assert(value != page_table_handle::LEVEL1, "[Page table] Attempted to decrement enum to value outside of range"); + + page_table_handle::level original_value = value; auto new_value = static_cast::type>(value); - return static_cast(--new_value); + value = static_cast(--new_value); + + return original_value; } } // namespace teachos::arch::memory::paging -- cgit v1.2.3