Skip to content

Commit c3ed645

Browse files
authored
Merge pull request #1283 from rust-osdev/bishop-boot-exit
boot: Add freestanding exit function
2 parents 30d33ec + df8d014 commit c3ed645

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

uefi/src/boot.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use core::ops::{Deref, DerefMut};
1010
use core::ptr::{self, NonNull};
1111
use core::slice;
1212
use core::sync::atomic::{AtomicPtr, Ordering};
13-
use uefi::{table, Handle, Result, Status, StatusExt};
13+
use uefi::{table, Char16, Handle, Result, Status, StatusExt};
1414

1515
#[cfg(doc)]
1616
use {
@@ -446,6 +446,35 @@ pub fn start_image(image_handle: Handle) -> Result {
446446
}
447447
}
448448

449+
/// Exits the UEFI application and returns control to the UEFI component
450+
/// that started the UEFI application.
451+
///
452+
/// # Safety
453+
///
454+
/// The caller must ensure that resources owned by the application are properly
455+
/// cleaned up.
456+
///
457+
/// Note that event callbacks installed by the application are not automatically
458+
/// uninstalled. If such a callback is invoked after exiting the application,
459+
/// the function's code may no longer be loaded in memory, leading to a crash or
460+
/// other unexpected behavior.
461+
pub unsafe fn exit(
462+
image_handle: Handle,
463+
exit_status: Status,
464+
exit_data_size: usize,
465+
exit_data: *mut Char16,
466+
) -> ! {
467+
let bt = boot_services_raw_panicking();
468+
let bt = unsafe { bt.as_ref() };
469+
470+
(bt.exit)(
471+
image_handle.as_ptr(),
472+
exit_status,
473+
exit_data_size,
474+
exit_data.cast(),
475+
)
476+
}
477+
449478
/// A buffer returned by [`locate_handle_buffer`] that contains an array of
450479
/// [`Handle`]s that support the requested protocol.
451480
#[derive(Debug, Eq, PartialEq)]

0 commit comments

Comments
 (0)