From 5babd7b4f2edc9bc9331fae776bb12b54deb4472 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 21 Jul 2023 12:01:50 +0300 Subject: [PATCH] Kernel: remove PAGE_FLAGS_MASK as that was not correct anymore After I added NXE bit, the flags mask is no longer valid --- kernel/arch/x86_64/PageTable.cpp | 15 ++++++++++----- kernel/include/kernel/Memory/Types.h | 1 - 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/arch/x86_64/PageTable.cpp b/kernel/arch/x86_64/PageTable.cpp index 9af3acf771..b6d977077e 100644 --- a/kernel/arch/x86_64/PageTable.cpp +++ b/kernel/arch/x86_64/PageTable.cpp @@ -44,6 +44,11 @@ namespace Kernel return addr; } + static inline PageTable::flags_t parse_flags(uint64_t entry) + { + return (s_has_nxe && !(entry & (1ull << 63)) ? PageTable::Flags::Execute : 0) | (entry & 0b111); + } + void PageTable::initialize() { if (CPUID::has_nxe()) @@ -342,8 +347,7 @@ namespace Kernel PageTable::flags_t PageTable::get_page_flags(vaddr_t addr) const { - uint64_t page_data = get_page_data(addr); - return (page_data & (1ull << 63) ? Flags::Execute : 0) | (page_data & PAGE_FLAG_MASK); + return parse_flags(get_page_data(addr)); } paddr_t PageTable::physical_address_of(vaddr_t addr) const @@ -463,9 +467,10 @@ namespace Kernel { if (start == 0) return; - dprintln("{}-{}: {}{}{}", + dprintln("{}-{}: {}{}{}{}", (void*)canonicalize(start), (void*)canonicalize(end - 1), + flags & PageTable::Flags::Execute ? 'x' : '-', flags & PageTable::Flags::UserSupervisor ? 'u' : '-', flags & PageTable::Flags::ReadWrite ? 'w' : '-', flags & PageTable::Flags::Present ? 'r' : '-' @@ -509,7 +514,7 @@ namespace Kernel uint64_t* pt = (uint64_t*)P2V(pd[pde] & PAGE_ADDR_MASK); for (uint64_t pte = 0; pte < 512; pte++) { - if ((pt[pte] & PAGE_FLAG_MASK) != flags) + if (parse_flags(pt[pte]) != flags) { dump_range(start, (pml4e << 39) | (pdpte << 30) | (pde << 21) | (pte << 12), flags); start = 0; @@ -520,7 +525,7 @@ namespace Kernel if (start == 0) { - flags = pt[pte] & PAGE_FLAG_MASK; + flags = parse_flags(pt[pte]); start = (pml4e << 39) | (pdpte << 30) | (pde << 21) | (pte << 12); } } diff --git a/kernel/include/kernel/Memory/Types.h b/kernel/include/kernel/Memory/Types.h index 9820cdea09..a8fccda8f7 100644 --- a/kernel/include/kernel/Memory/Types.h +++ b/kernel/include/kernel/Memory/Types.h @@ -11,7 +11,6 @@ #endif #define PAGE_SIZE ((uintptr_t)4096) -#define PAGE_FLAG_MASK ((uintptr_t)0xF) #define PAGE_ADDR_MASK (~(uintptr_t)0xFFF) namespace Kernel