From 64bf7fcf58ced023be1701ed4508e38f746d40b8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 16 Mar 2026 08:34:13 +0100 Subject: kernel/memory: implement basic free-list heap --- arch/x86_64/src/memory/recursive_page_mapper.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'arch/x86_64/src/memory') diff --git a/arch/x86_64/src/memory/recursive_page_mapper.cpp b/arch/x86_64/src/memory/recursive_page_mapper.cpp index d8273e1..c7c5341 100644 --- a/arch/x86_64/src/memory/recursive_page_mapper.cpp +++ b/arch/x86_64/src/memory/recursive_page_mapper.cpp @@ -56,18 +56,17 @@ namespace arch::memory } // namespace - recursive_page_mapper::recursive_page_mapper(kapi::memory::frame_allocator & allocator) - : m_allocator{&allocator} - {} + recursive_page_mapper::recursive_page_mapper() {} auto recursive_page_mapper::map(kapi::memory::page page, kapi::memory::frame frame, flags flags) -> std::byte * { auto pml4 = static_cast *>((paging_root::get())); + auto & allocator = kapi::memory::get_frame_allocator(); return std::optional{pml4} - .and_then([&](auto pml) -> auto { return do_map(pml, page, *m_allocator, flags); }) - .and_then([&](auto pml) -> auto { return do_map(pml, page, *m_allocator, flags); }) - .and_then([&](auto pml) -> auto { return do_map(pml, page, *m_allocator, flags); }) + .and_then([&](auto pml) -> auto { return do_map(pml, page, allocator, flags); }) + .and_then([&](auto pml) -> auto { return do_map(pml, page, allocator, flags); }) + .and_then([&](auto pml) -> auto { return do_map(pml, page, allocator, flags); }) .and_then([&](auto pml) -> auto { return do_map(pml, page, frame, flags); }) .value_or(nullptr); } @@ -91,27 +90,28 @@ namespace arch::memory auto pml3 = pml4->next(pml_index<4>(page)).value(); auto pml2 = pml3->next(pml_index<3>(page)).value(); auto pml1 = pml2->next(pml_index<2>(page)).value(); + auto & allocator = kapi::memory::get_frame_allocator(); (*pml1)[pml_index<1>(page)].clear(); if (pml1->empty()) { auto pml1_frame = (*pml2)[pml_index<2>(page)].frame().value(); - m_allocator->release(pml1_frame); + allocator.release(pml1_frame); (*pml2)[pml_index<2>(page)].clear(); } if (pml2->empty()) { auto pml2_frame = (*pml3)[pml_index<3>(page)].frame().value(); - m_allocator->release(pml2_frame); + allocator.release(pml2_frame); (*pml3)[pml_index<3>(page)].clear(); } if (pml3->empty()) { auto pml3_frame = (*pml4)[pml_index<4>(page)].frame().value(); - m_allocator->release(pml3_frame); + allocator.release(pml3_frame); (*pml4)[pml_index<4>(page)].clear(); } -- cgit v1.2.3