Skip to content

Commit

Permalink
Frame Allocator: avoid creating duplicate free regions during init (#โ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆ1105)

The duplicate region was created due to a bug
in the `check_and_add_free_region` function:
After returning from a recursive call, the original area's
end frame should be updated to *not include* th
 region that was just added to the free list.
  • Loading branch information
Ramla-I authored Sep 3, 2024
1 parent 8a1d149 commit 68cc3ae
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kernel/frame_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ fn check_and_add_free_region<P, R>(
where P: Borrow<PhysicalMemoryRegion>,
R: IntoIterator<Item = P> + Clone,
{
let mut area = area.clone();
// This will be set to the frame that is the start of the current free region.
let mut current_start = *area.start();
// This will be set to the frame that is the end of the current free region.
Expand Down Expand Up @@ -229,11 +230,14 @@ fn check_and_add_free_region<P, R>(
free_list_idx,
reserved_physical_memory_areas.clone(),
);
area = FrameRange::new(*area.start(), current_end);
// info!("Updating original region after exiting recursive function: {:X?}", area);
}
}
}

let new_area = FrameRange::new(current_start, current_end);
// info!("Adding new area: {:X?}", new_area);
if new_area.size_in_frames() > 0 {
free_list[*free_list_idx] = Some(PhysicalMemoryRegion {
typ: MemoryRegionType::Free,
Expand Down

0 comments on commit 68cc3ae

Please sign in to comment.