Skip to content

Commit 3b93042

Browse files
committed
fix(mm): use stack buffer for memory map (heap not ready yet)
- CRITICAL BUG: mm::init used alloc::vec! to get UEFI Memory Map - But heap initialization happens AFTER memory map scanning! - This caused a circular dependency: alloc needs heap, heap needs memory map - Fix: Use static [u8; 8192] stack buffer instead of Vec - This breaks the circular dependency and allows boot to proceed
1 parent e7b56af commit 3b93042

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/mm/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ pub fn init(st: &SystemTable<Boot>) -> (u64, ()) {
1313
{
1414
use uefi::table::boot::MemoryType;
1515

16-
log::info!("[MM] Getting UEFI Memory Map...");
17-
18-
// 1. Get Memory Map Size
19-
let map_size = st.boot_services().memory_map_size().map_size;
20-
// Allocate with padding for fragmentation/alignment
21-
let buffer_size = map_size + 8 * core::mem::size_of::<uefi::table::boot::MemoryDescriptor>();
22-
23-
let mut buffer = alloc::vec![0u8; buffer_size];
16+
// CRITICAL: We CANNOT use alloc::vec! here because heap is not initialized yet!
17+
// Use a static stack buffer instead.
18+
// Max size: ~8KB should cover most UEFI memory maps (hundreds of descriptors).
19+
// Use a static stack buffer instead.
20+
// Max size: ~8KB should cover most UEFI memory maps (hundreds of descriptors).
21+
const MAP_BUF_SIZE: usize = 8192;
22+
let mut buffer = [0u8; MAP_BUF_SIZE];
2423

2524
// 2. Get Memory Map
2625
// We need to collect the best region, then drop the iterator/map to satisfy borrow checker if needed,

0 commit comments

Comments
 (0)