Skip to content

Commit b36417f

Browse files
committed
fix max memory region calculation
1 parent b0cae12 commit b36417f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

common/src/legacy_memory_region.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ where
152152
.unwrap()
153153
}
154154

155+
/// Calculate the maximum number of regions produced by [Self::construct_memory_map]
156+
pub fn memory_map_max_region_count(&self) -> usize {
157+
// every used slice can split an original region into 3 new regions,
158+
// this means we need to reserve 2 extra spaces for each slice.
159+
// There are 3 additional slices (kernel, ramdisk and the bootloader heap)
160+
self.len() + (3 + self.used_slices.clone().count()) * 2
161+
}
162+
155163
/// Converts this type to a boot info memory map.
156164
///
157165
/// The memory map is placed in the given `regions` slice. The length of the given slice

common/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ where
487487
// allocate and map space for the boot info
488488
let (boot_info, memory_regions) = {
489489
let boot_info_layout = Layout::new::<BootInfo>();
490-
// TODO the assumption here about the regions is wrong
491-
// figure out what the correct region count should be
492-
let regions = frame_allocator.len() + 4 + 30; // up to 4 regions might be split into used/unused
490+
let regions = frame_allocator.memory_map_max_region_count();
493491
let memory_regions_layout = Layout::array::<MemoryRegion>(regions).unwrap();
494492
let (combined, memory_regions_offset) =
495493
boot_info_layout.extend(memory_regions_layout).unwrap();

0 commit comments

Comments
 (0)