From 1518177efac38961a36db0bc40152d00c38e6281 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 27 Oct 2024 13:27:33 +0000 Subject: add correct optional handling --- .../src/memory/allocator/area_frame_allocator.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'arch/x86_64/src/memory/allocator') diff --git a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp index c2cafce..05b828c 100644 --- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp +++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp @@ -29,14 +29,14 @@ namespace teachos::arch::memory::allocator if (physical_frame::containing_address(address) >= next_free_frame) { // The `next_free_frame` address is smaller than the last address of the current area - if (!current_area || area.base_address < current_area->base_address) + if (!current_area.has_value() || area.base_address < current_area.value().base_address) { - current_area = area; + current_area.emplace(area); } } } - if (current_area) + if (current_area.has_value()) { // Update the `next_free_frame` according to the new memory area physical_frame start_frame = physical_frame::containing_address(current_area->base_address); @@ -53,7 +53,7 @@ namespace teachos::arch::memory::allocator * Only try to allocate memory if current_area is not null, because * the current_area is null if there is no more available memory. */ - if (current_area) + if (current_area.has_value()) { physical_frame physical_frame{next_free_frame.frame_number}; @@ -65,11 +65,16 @@ namespace teachos::arch::memory::allocator // All frames of current area are used, switch to next area choose_next_area(); } - else if (physical_frame >= multiboot_start && physical_frame <= kernel_end) + else if (physical_frame >= kernel_start && physical_frame <= kernel_end) { - // `physical_frame` is used by the kernel or multiboot information structure + // `physical_frame` is used by the kernel next_free_frame = allocator::physical_frame{kernel_end.frame_number + 1}; } + else if (physical_frame >= multiboot_start && physical_frame <= multiboot_end) + { + // `physical_frame` is used by the multiboot information structure + next_free_frame = allocator::physical_frame{multiboot_end.frame_number + 1}; + } else { // Frame is unused, increment `next_free_frame` and return it -- cgit v1.2.3