Skip to content

Commit 905baa6

Browse files
committed
uefi-helpers: remove exit hook
No need for the complicated and error-prone approach using an event.
1 parent bbf26f7 commit 905baa6

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

uefi-services/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ pub use uefi::{print, println};
99

1010
#[deprecated = "WARNING: `uefi-services` is deprecated. Functionality was moved to `uefi::helpers::init`."]
1111
pub fn init(st: &mut SystemTable<Boot>) -> Result<Option<Event>> {
12-
uefi::helpers::init(st)
12+
uefi::helpers::init(st).map(|_| None)
1313
}

uefi/src/helpers/mod.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313
//! epoch.
1414
1515
use crate::prelude::{Boot, SystemTable};
16-
use crate::Event;
1716
use crate::Result;
1817
use crate::StatusExt;
1918
use core::ffi::c_void;
2019
use core::ptr;
21-
use core::ptr::NonNull;
2220
use core::sync::atomic::{AtomicPtr, Ordering};
2321
#[doc(hidden)]
2422
pub use println::_print;
25-
use uefi_raw::table::boot::{EventType, Tpl};
2623
use uefi_raw::Status;
2724

2825
#[cfg(feature = "global_allocator")]
@@ -73,10 +70,10 @@ fn system_table() -> SystemTable<Boot> {
7370
///
7471
/// **PLEASE NOTE** that these helpers are meant for the pre exit boot service
7572
/// epoch.
76-
pub fn init(st: &mut SystemTable<Boot>) -> Result<Option<Event>> {
73+
pub fn init(st: &mut SystemTable<Boot>) -> Result<()> {
7774
if system_table_opt().is_some() {
7875
// Avoid double initialization.
79-
return Status::SUCCESS.to_result_with_val(|| None);
76+
return Status::SUCCESS.to_result_with_val(|| ());
8077
}
8178

8279
// Setup the system table singleton
@@ -89,23 +86,12 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result<Option<Event>> {
8986
logger::init(st);
9087

9188
uefi::allocator::init(st);
92-
93-
// Schedule these tools to be disabled on exit from UEFI boot services
94-
let boot_services = st.boot_services();
95-
boot_services
96-
.create_event(
97-
EventType::SIGNAL_EXIT_BOOT_SERVICES,
98-
Tpl::NOTIFY,
99-
Some(exit_boot_services),
100-
None,
101-
)
102-
.map(Some)
10389
}
90+
91+
Ok(())
10492
}
10593

106-
/// Notify the utility library that boot services are not safe to call anymore
107-
/// As this is a callback, it must be `extern "efiapi"`.
108-
unsafe extern "efiapi" fn exit_boot_services(_e: Event, _ctx: Option<NonNull<c_void>>) {
94+
pub(crate) fn exit() {
10995
// DEBUG: The UEFI spec does not guarantee that this printout will work, as
11096
// the services used by logging might already have been shut down.
11197
// But it works on current OVMF, and can be used as a handy way to

uefi/src/table/system.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,10 @@ impl SystemTable<Boot> {
206206
/// live until the program ends. The lifetime of the memory map is therefore
207207
/// `'static`.
208208
///
209-
/// Once boot services are exited, the logger and allocator provided by
210-
/// this crate can no longer be used. The logger should be disabled using
211-
/// the [`Logger::disable`] method, and the allocator should be disabled by
212-
/// calling [`allocator::exit_boot_services`]. Note that if the logger and
213-
/// allocator were initialized with [`uefi_services::init`], they will be
214-
/// disabled automatically when `exit_boot_services` is called.
209+
/// Note that once the boot services are exited, associated loggers and
210+
/// allocators can't use the boot services anymore. For the corresponding
211+
/// abstractions provided by this crate, invoking this function will
212+
/// automatically disable them.
215213
///
216214
/// # Errors
217215
///
@@ -222,14 +220,13 @@ impl SystemTable<Boot> {
222220
/// All errors are treated as unrecoverable because the system is
223221
/// now in an undefined state. Rather than returning control to the
224222
/// caller, the system will be reset.
225-
///
226-
/// [`allocator::exit_boot_services`]: crate::allocator::exit_boot_services
227-
/// [`Logger::disable`]: crate::logger::Logger::disable
228223
#[must_use]
229224
pub fn exit_boot_services(
230225
self,
231226
memory_type: MemoryType,
232227
) -> (SystemTable<Runtime>, MemoryMap<'static>) {
228+
crate::helpers::exit();
229+
233230
let boot_services = self.boot_services();
234231

235232
// Reboot the device.

0 commit comments

Comments
 (0)