From b403155ca90fc366fc713cbdea6b91a677709451 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 4 Jun 2023 01:15:48 +0300 Subject: [PATCH] Kernel: You can specify first vaddr for getting free pages --- kernel/arch/x86_64/PageTable.cpp | 6 ++++-- kernel/include/kernel/Memory/PageTable.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/arch/x86_64/PageTable.cpp b/kernel/arch/x86_64/PageTable.cpp index 4a0b6f3512..dae2c1041a 100644 --- a/kernel/arch/x86_64/PageTable.cpp +++ b/kernel/arch/x86_64/PageTable.cpp @@ -382,11 +382,13 @@ namespace Kernel ASSERT_NOT_REACHED(); } - vaddr_t PageTable::get_free_contiguous_pages(size_t page_count) const + vaddr_t PageTable::get_free_contiguous_pages(size_t page_count, vaddr_t first_address) const { + ASSERT(first_address % PAGE_SIZE == 0); + LockGuard _(m_lock); - for (vaddr_t vaddr = PAGE_SIZE; !(vaddr >> 48); vaddr += PAGE_SIZE) + for (vaddr_t vaddr = first_address; is_canonical(vaddr); vaddr += PAGE_SIZE) { bool valid { true }; for (size_t page = 0; page < page_count; page++) diff --git a/kernel/include/kernel/Memory/PageTable.h b/kernel/include/kernel/Memory/PageTable.h index 33ef4559bb..ed19560372 100644 --- a/kernel/include/kernel/Memory/PageTable.h +++ b/kernel/include/kernel/Memory/PageTable.h @@ -43,7 +43,7 @@ namespace Kernel bool is_range_free(vaddr_t, size_t bytes) const; vaddr_t get_free_page() const; - vaddr_t get_free_contiguous_pages(size_t page_count) const; + vaddr_t get_free_contiguous_pages(size_t page_count, vaddr_t first_address = PAGE_SIZE) const; void invalidate(vaddr_t); void load();