diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-20 06:32:02 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-20 06:32:02 +0000 |
| commit | 7ebfe9e09efa84044d1470132b7f55ebf53a7f89 (patch) | |
| tree | b5f0c21be0411c6586a1202b2d92d5aad72bf3db | |
| parent | 7ca089125b8c5e55dd584648cd33612883cc004d (diff) | |
| download | teachos-7ebfe9e09efa84044d1470132b7f55ebf53a7f89.tar.xz teachos-7ebfe9e09efa84044d1470132b7f55ebf53a7f89.zip | |
Fix next_table_address
| -rw-r--r-- | arch/x86_64/include/arch/memory/paging/page_table.hpp | 2 | ||||
| -rw-r--r-- | 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<std::size_t>; + auto next_table_address(std::size_t table_index) -> std::optional<std::size_t>; 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<table_content *>(*address); + current_table = reinterpret_cast<table_content *>(address.value()); current_level = static_cast<level>(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<std::size_t> + auto page_table::next_table_address(std::size_t table_index) -> std::optional<std::size_t> { 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<std::size_t>(this); + std::size_t const table_address = reinterpret_cast<std::size_t>(current_table); return (table_address << 9) | (table_index << 12); } // TODO: Implement behaviour for huge pages currently not done |
