@@ -1260,7 +1260,7 @@ unsafe fn get_memory_map_and_exit_boot_services(buf: &mut [u8]) -> Result<Memory
1260
1260
1261
1261
/// Convenient wrapper to exit UEFI boot services along with corresponding
1262
1262
/// essential steps to get the memory map.
1263
- ///
1263
+ ///
1264
1264
/// This wrapper ensures a safe and spec-compliant transition from UEFI boot
1265
1265
/// services phase to the runtime services phase by retrieving the system
1266
1266
/// memory map and invoking `ExitBootServices()` with the correct memory map
@@ -1282,6 +1282,13 @@ unsafe fn get_memory_map_and_exit_boot_services(buf: &mut [u8]) -> Result<Memory
1282
1282
/// `global_allocator` feature is enabled, attempting to use the allocator
1283
1283
/// after exiting boot services will panic.
1284
1284
///
1285
+ /// # Arguments
1286
+ /// - `custom_memory_type`: The [`MemoryType`] for the UEFI allocation that will
1287
+ /// store the final memory map. If you pass `None`, this defaults to the
1288
+ /// recommended default value of [`MemoryType::LOADER_DATA`]. If you want a
1289
+ /// specific memory region for the memory map, you can pass the desired
1290
+ /// [`MemoryType`].
1291
+ ///
1285
1292
/// # Safety
1286
1293
///
1287
1294
/// The caller is responsible for ensuring that no references to
@@ -1312,7 +1319,10 @@ unsafe fn get_memory_map_and_exit_boot_services(buf: &mut [u8]) -> Result<Memory
1312
1319
/// [`Output`]: crate::proto::console::text::Output
1313
1320
/// [`PoolString`]: crate::proto::device_path::text::PoolString
1314
1321
#[ must_use]
1315
- pub unsafe fn exit_boot_services ( memory_type : MemoryType ) -> MemoryMapOwned {
1322
+ pub unsafe fn exit_boot_services ( custom_memory_type : Option < MemoryType > ) -> MemoryMapOwned {
1323
+ // LOADER_DATA is the default and also used by the Linux kernel:
1324
+ // https://elixir.bootlin.com/linux/v6.13.7/source/drivers/firmware/efi/libstub/mem.c#L24
1325
+ let memory_type = custom_memory_type. unwrap_or ( MemoryType :: LOADER_DATA ) ;
1316
1326
crate :: helpers:: exit ( ) ;
1317
1327
1318
1328
let mut buf = MemoryMapBackingMemory :: new ( memory_type) . expect ( "Failed to allocate memory" ) ;
0 commit comments