aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86_64/src/memory/paging/page_mapper.cpp6
-rw-r--r--arch/x86_64/src/memory/paging/page_table.cpp4
2 files changed, 7 insertions, 3 deletions
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 *>(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<allocator::physical_frame>
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<std::size_t>