Skip to content

Commit 9626dfb

Browse files
committed
uefi/doc: improve documentation of exit_boot_services
TL;DR: Document why exit_boot_services needs to do more than just call the UEFI function. Exiting UEFI boot services requires a non-trivial sequence of steps, including safe retrieval and finalization of the memory map. To clarify why our exit_boot_services function is more than a thin wrapper, the documentation has been updated accordingly. This complexity is also reflected in the Linux source code [0]. In fact, the sequence of steps uefi-rs uses is inspired by the Linux source code. [0] https://github.com/torvalds/linux/blob/e544a0743/drivers/firmware/efi/libstub/efi-stub-helper.c#L375
1 parent a0a76eb commit 9626dfb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

uefi/src/boot.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1258,17 +1258,23 @@ unsafe fn get_memory_map_and_exit_boot_services(buf: &mut [u8]) -> Result<Memory
12581258
.to_result_with_val(|| memory_map)
12591259
}
12601260

1261-
/// Exit UEFI boot services.
1261+
/// Convenient wrapper to exit UEFI boot services along with corresponding
1262+
/// essential steps to get the memory map.
1263+
///
1264+
/// Exiting UEFI boot services requires a **non-trivial sequence of steps**,
1265+
/// including safe retrieval and finalization of the memory map. This wrapper
1266+
/// ensures a safe and spec-compliant transition from UEFI boot services to
1267+
/// runtime services by retrieving the system memory map and invoking
1268+
/// `ExitBootServices()` with the correct memory map key, retrying if necessary.
12621269
///
12631270
/// After this function completes, UEFI hands over control of the hardware
12641271
/// to the executing OS loader, which implies that the UEFI boot services
12651272
/// are shut down and cannot be used anymore. Only UEFI configuration tables
1266-
/// and run-time services can be used.
1273+
/// and runtime services can be used.
12671274
///
1268-
/// The memory map at the time of exiting boot services returned. The map is
1269-
/// backed by a pool allocation of the given `memory_type`. Since the boot
1270-
/// services function to free that memory is no longer available after calling
1271-
/// `exit_boot_services`, the allocation will not be freed on drop.
1275+
/// Since the boot services function to free memory is no longer available after
1276+
/// this function returns, the allocation will not be freed on drop. It will
1277+
/// however be reflected by the memory map itself (self-contained).
12721278
///
12731279
/// Note that once the boot services are exited, associated loggers and
12741280
/// allocators can't use the boot services anymore. For the corresponding

0 commit comments

Comments
 (0)