From 841584ccbd15b128214df51c7f206ac5b1299f24 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 6 Jun 2023 02:03:23 +0300 Subject: [PATCH] Kernel: get_free_contiguous_pages works with non-page aligned addresses also fix bug in ordering --- kernel/arch/x86_64/PageTable.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/arch/x86_64/PageTable.cpp b/kernel/arch/x86_64/PageTable.cpp index dae2c1041a..071d3355f2 100644 --- a/kernel/arch/x86_64/PageTable.cpp +++ b/kernel/arch/x86_64/PageTable.cpp @@ -188,9 +188,6 @@ namespace Kernel { LockGuard _(m_lock); - ASSERT(is_canonical(vaddr)); - vaddr = uncanonicalize(vaddr); - vaddr &= PAGE_ADDR_MASK; if (is_page_free(vaddr)) @@ -199,6 +196,9 @@ namespace Kernel return; } + ASSERT(is_canonical(vaddr)); + vaddr = uncanonicalize(vaddr); + uint64_t pml4e = (vaddr >> 39) & 0x1FF; uint64_t pdpte = (vaddr >> 30) & 0x1FF; uint64_t pde = (vaddr >> 21) & 0x1FF; @@ -384,7 +384,8 @@ namespace Kernel vaddr_t PageTable::get_free_contiguous_pages(size_t page_count, vaddr_t first_address) const { - ASSERT(first_address % PAGE_SIZE == 0); + if (first_address % PAGE_SIZE) + first_address = (first_address + PAGE_SIZE - 1) & PAGE_ADDR_MASK; LockGuard _(m_lock);