diff --git a/uefi-test-runner/src/main.rs b/uefi-test-runner/src/main.rs index bcbbb0f8e..2e45d8438 100644 --- a/uefi-test-runner/src/main.rs +++ b/uefi-test-runner/src/main.rs @@ -10,7 +10,7 @@ extern crate alloc; use alloc::string::ToString; use alloc::vec::Vec; -use uefi::mem::memory_map::{MemoryMap, MemoryType}; +use uefi::mem::memory_map::MemoryMap; use uefi::prelude::*; use uefi::proto::console::serial::Serial; use uefi::proto::device_path::build::{self, DevicePathBuilder}; @@ -209,7 +209,7 @@ fn shutdown() -> ! { info!("Testing complete, exiting boot services..."); // Exit boot services as a proof that it works :) - let mmap = unsafe { uefi::boot::exit_boot_services(MemoryType::LOADER_DATA) }; + let mmap = unsafe { uefi::boot::exit_boot_services(None) }; info!("Memory Map:"); for desc in mmap.entries() { diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index dfb07a075..0d059b9d9 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -16,6 +16,8 @@ `&self`. - **Breaking:** The `pxe::Mode` struct is now opaque. Use method calls to access mode data instead of direct field access. +- **Breaking:** `exit_boot_services` now consumes a `Option` which + defaults to the recommended value of `MemoryType::LOADER_DATA`. - `boot::memory_map()` will never return `Status::BUFFER_TOO_SMALL` from now on, as this is considered a hard internal error where users can't do anything about it anyway. It will panic instead. diff --git a/uefi/src/boot.rs b/uefi/src/boot.rs index 4c44bef55..d36e59dae 100644 --- a/uefi/src/boot.rs +++ b/uefi/src/boot.rs @@ -1258,17 +1258,23 @@ unsafe fn get_memory_map_and_exit_boot_services(buf: &mut [u8]) -> Result Result Result MemoryMapOwned { +pub unsafe fn exit_boot_services(custom_memory_type: Option) -> MemoryMapOwned { + // LOADER_DATA is the default and also used by the Linux kernel: + // https://elixir.bootlin.com/linux/v6.13.7/source/drivers/firmware/efi/libstub/mem.c#L24 + let memory_type = custom_memory_type.unwrap_or(MemoryType::LOADER_DATA); crate::helpers::exit(); let mut buf = MemoryMapBackingMemory::new(memory_type).expect("Failed to allocate memory");