From c7bc900ef9293045265f503696277b0405119c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Wed, 23 Oct 2024 14:29:08 +0000 Subject: Use virtual level 4 address again --- arch/x86_64/src/memory/paging/page_mapper.cpp | 6 ++++-- arch/x86_64/src/memory/paging/page_table.cpp | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'arch/x86_64/src') diff --git a/arch/x86_64/src/memory/paging/page_mapper.cpp b/arch/x86_64/src/memory/paging/page_mapper.cpp index 995f2c3..687bffd 100644 --- a/arch/x86_64/src/memory/paging/page_mapper.cpp +++ b/arch/x86_64/src/memory/paging/page_mapper.cpp @@ -6,13 +6,15 @@ namespace teachos::arch::memory::paging { namespace { - static page_table * PAGE_TABLE_LEVEL_4_ADDRESS = boot::page_map_level_4; + constexpr size_t PAGE_TABLE_LEVEL_4_ADDRESS = 0xfffffffffffff000; } // namespace auto create_or_get() -> page_table_handle { + // Perhaps we need to access boot::page_map_level_4; so we do not crash when returning entry? + static page_table * const active_page = reinterpret_cast(PAGE_TABLE_LEVEL_4_ADDRESS); // We can not save page_table_handle as a static variable directly, if we do the program will fail to link. - return page_table_handle{PAGE_TABLE_LEVEL_4_ADDRESS, page_table_handle::LEVEL4}; + return page_table_handle{active_page, page_table_handle::LEVEL4}; } auto translate_page(virtual_page page) -> std::optional diff --git a/arch/x86_64/src/memory/paging/page_table.cpp b/arch/x86_64/src/memory/paging/page_table.cpp index 40662e3..bfd91da 100644 --- a/arch/x86_64/src/memory/paging/page_table.cpp +++ b/arch/x86_64/src/memory/paging/page_table.cpp @@ -51,6 +51,7 @@ namespace teachos::arch::memory::paging auto page_table::zero_entries() -> void { constexpr size_t entry_amount = sizeof(entries) / sizeof(entries[0]); + static_assert(entry_amount == PAGE_TABLE_ENTRY_COUNT); for (size_t i = 0; i < entry_amount; ++i) { auto entry = this->operator[](i); @@ -73,7 +74,8 @@ namespace teachos::arch::memory::paging // 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. exception_handling::assert(index < PAGE_TABLE_ENTRY_COUNT, "[Page Table] Index out of bounds"); - return entries[index]; + auto & entry = entries[index]; + return entry; } auto page_table::next_table_address(std::size_t table_index) -> std::optional -- cgit v1.2.3