Skip to content

Commit 4ae0cd6

Browse files
uefi: Make exit_boot_services unsafe
This method was already unsafe in practice, since it's very hard to statically ensure that no references to boot-services data exist. Change the signature to acknowledge that reality, and update the docstring with details.
1 parent b325e72 commit 4ae0cd6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

uefi-test-runner/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn shutdown(mut st: SystemTable<Boot>) -> ! {
199199
info!("Testing complete, shutting down...");
200200

201201
// Exit boot services as a proof that it works :)
202-
let (st, _iter) = st.exit_boot_services(MemoryType::LOADER_DATA);
202+
let (st, _iter) = unsafe { st.exit_boot_services(MemoryType::LOADER_DATA) };
203203

204204
#[cfg(target_arch = "x86_64")]
205205
{

uefi/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
This provides an initial API for global tables that do not require passing
66
around a reference.
77

8+
## Changed
9+
- `SystemTable::exit_boot_services` is now `unsafe`. See that method's
10+
documentation for details of obligations for callers.
11+
812
## Removed
913
- Removed the `panic-on-logger-errors` feature of the `uefi` crate. Logger
1014
errors are now silently ignored.

uefi/src/table/system.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,23 @@ impl SystemTable<Boot> {
211211
/// abstractions provided by this crate, invoking this function will
212212
/// automatically disable them.
213213
///
214+
/// # Safety
215+
///
216+
/// The caller is responsible for ensuring that no references to
217+
/// boot-services data remain. A non-exhaustive list of resources to check:
218+
///
219+
/// * All protocols will be invalid after exiting boot services. This
220+
/// includes the [`Output`] protocols attached to stdout/stderr. The
221+
/// caller must ensure that no protocol references remain.
222+
/// * The pool allocator is not usable after exiting boot services. Types
223+
/// such as [`PoolString`] which call [`BootServices::free_pool`] on drop
224+
/// must be cleaned up before calling `exit_boot_services`, or leaked to
225+
/// avoid drop ever being called.
226+
/// * All data in the memory map marked as
227+
/// [`MemoryType::BOOT_SERVICES_CODE`] and
228+
/// [`MemoryType::BOOT_SERVICES_DATA`] will become free memory, the caller
229+
/// must ensure that no references to such memory exist.
230+
///
214231
/// # Errors
215232
///
216233
/// This function will fail if it is unable to allocate memory for
@@ -221,7 +238,7 @@ impl SystemTable<Boot> {
221238
/// now in an undefined state. Rather than returning control to the
222239
/// caller, the system will be reset.
223240
#[must_use]
224-
pub fn exit_boot_services(
241+
pub unsafe fn exit_boot_services(
225242
self,
226243
memory_type: MemoryType,
227244
) -> (SystemTable<Runtime>, MemoryMap<'static>) {

0 commit comments

Comments
 (0)