Kernel: get_free_contiguous_pages works with non-page aligned addresses

also fix bug in ordering
This commit is contained in:
Bananymous 2023-06-06 02:03:23 +03:00
parent 86f58f60cb
commit 2b9900e56e
1 changed files with 5 additions and 4 deletions

View File

@ -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);