File tree 2 files changed +9
-3
lines changed
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,14 @@ where
152
152
. unwrap ( )
153
153
}
154
154
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
+
155
163
/// Converts this type to a boot info memory map.
156
164
///
157
165
/// The memory map is placed in the given `regions` slice. The length of the given slice
Original file line number Diff line number Diff line change @@ -487,9 +487,7 @@ where
487
487
// allocate and map space for the boot info
488
488
let ( boot_info, memory_regions) = {
489
489
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 ( ) ;
493
491
let memory_regions_layout = Layout :: array :: < MemoryRegion > ( regions) . unwrap ( ) ;
494
492
let ( combined, memory_regions_offset) =
495
493
boot_info_layout. extend ( memory_regions_layout) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments