From 56eb6fb4ce95de85ccb1e14e71220f9f2b3091c5 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 30 May 2023 23:56:07 +0300 Subject: [PATCH] Kernel: PageTable::map_range_at maps correctly the last page --- kernel/arch/x86_64/PageTable.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/arch/x86_64/PageTable.cpp b/kernel/arch/x86_64/PageTable.cpp index ce57a2c491..88533b8fde 100644 --- a/kernel/arch/x86_64/PageTable.cpp +++ b/kernel/arch/x86_64/PageTable.cpp @@ -284,7 +284,7 @@ namespace Kernel pt[pte] = paddr | flags; } - void PageTable::map_range_at(paddr_t paddr, vaddr_t vaddr, size_t bytes, flags_t flags) + void PageTable::map_range_at(paddr_t paddr, vaddr_t vaddr, size_t size, flags_t flags) { LockGuard _(m_lock); @@ -293,8 +293,11 @@ namespace Kernel ASSERT(paddr % PAGE_SIZE == 0); ASSERT(vaddr % PAGE_SIZE == 0); - for (size_t offset = 0; offset < bytes; offset += PAGE_SIZE) - map_page_at(paddr + offset, vaddr + offset, flags); + size_t first_page = vaddr / PAGE_SIZE; + size_t last_page = (vaddr + size - 1) / PAGE_SIZE; + size_t page_count = last_page - first_page + 1; + for (size_t page = 0; page < page_count; page++) + map_page_at(paddr + page * PAGE_SIZE, vaddr + page * PAGE_SIZE, flags); } uint64_t PageTable::get_page_data(vaddr_t vaddr) const