diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-12 10:59:50 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-12 10:59:50 +0000 |
| commit | d10bc808b29b0b647cbbb6c92d253fbb8c5cf431 (patch) | |
| tree | bf6b97248f521e163053484bc75ab4a54da89e9c /arch | |
| parent | 38e5d23fb325c983751f5d3e4f54a60bf1b1e47a (diff) | |
| download | teachos-d10bc808b29b0b647cbbb6c92d253fbb8c5cf431.tar.xz teachos-d10bc808b29b0b647cbbb6c92d253fbb8c5cf431.zip | |
Fix next table overwriting old page handle
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/include/arch/memory/paging/page_table.hpp | 11 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/paging/page_table.cpp | 5 |
2 files changed, 9 insertions, 7 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 9449ef2..7a15875 100644 --- a/arch/x86_64/include/arch/memory/paging/page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp @@ -72,7 +72,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) -> std::optional<page_table_handle>; + auto next_table(std::size_t table_index) const -> std::optional<page_table_handle>; /** * @brief Call next_table and then checks if the table already exists, if it does not it will use the given @@ -120,8 +120,8 @@ namespace teachos::arch::memory::paging auto operator[](std::size_t index) const -> entry const &; /** - * @brief Decrements the page table level enum by one, is defined so we can use it as a replacement for an - * int index in a range based for loop. + * @brief Pre decrement operator on the page table level enum, is defined so we can use it as a replacement + * for an int index in a range based for loop. * * @note Will halt execution if called with page_table_handle::LEVEL1, because there is no level below. Has to be * defined as either a friend function or inline header method, because we define an operator of another type. In @@ -132,12 +132,13 @@ namespace teachos::arch::memory::paging * header file. * * @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, ... + * @return New level value decrement by one, meaning the level is also decrement by one Level4 --> Level3, ... */ friend auto operator--(level & value) -> level &; private: - page_table * table; ///< Handle to underlying page table, can never be null (invariant ensured by constructor) + page_table * table; ///< Handle to underlying page table, can never be null (invariant ensured by + ///< constructor) level table_level; ///< Level page table is currently on, depends on how often next_level was ///< called successfully. }; diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp index a39c235..eb11810 100644 --- a/arch/x86_64/src/memory/paging/page_table.cpp +++ b/arch/x86_64/src/memory/paging/page_table.cpp @@ -100,14 +100,15 @@ namespace teachos::arch::memory::paging auto page_table_handle::is_empty() const -> bool { return table->is_empty(); } - auto page_table_handle::next_table(std::size_t table_index) -> std::optional<page_table_handle> + auto page_table_handle::next_table(std::size_t table_index) const -> std::optional<page_table_handle> { exception_handling::assert(table_level != page_table_handle::LEVEL1, "[Page Table] Attempted to call next_table on level 1 page table"); auto const next_table = table->next_table(table_index); if (next_table.has_value()) { - return page_table_handle{next_table.value(), --table_level}; + auto const new_level = static_cast<page_table_handle::level>(table_level - 1); + return page_table_handle{next_table.value(), new_level}; } return std::nullopt; } |
