Skip to content

Commit 0d44132

Browse files
uefi: Drop duplicate global system table pointer
Now that `uefi::table` has a pointer to the system table, drop the pointer from `uefi::helpers`.
1 parent 2c83acc commit 0d44132

File tree

3 files changed

+9
-47
lines changed

3 files changed

+9
-47
lines changed

uefi/src/helpers/mod.rs

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@
1919
//! [println_macro]: uefi::println!
2020
2121
use crate::prelude::{Boot, SystemTable};
22-
use crate::Result;
23-
use crate::StatusExt;
24-
use core::ffi::c_void;
25-
use core::ptr;
26-
use core::sync::atomic::{AtomicPtr, Ordering};
22+
use crate::{table, Result};
2723
#[doc(hidden)]
2824
pub use println::_print;
29-
use uefi_raw::Status;
3025

3126
#[cfg(feature = "global_allocator")]
3227
mod global_allocator;
@@ -36,25 +31,6 @@ mod logger;
3631
mod panic_handler;
3732
mod println;
3833

39-
/// Reference to the system table.
40-
///
41-
/// This table is only fully safe to use until UEFI boot services have been exited.
42-
/// After that, some fields and methods are unsafe to use, see the documentation of
43-
/// UEFI's ExitBootServices entry point for more details.
44-
static SYSTEM_TABLE: AtomicPtr<c_void> = AtomicPtr::new(core::ptr::null_mut());
45-
46-
#[must_use]
47-
fn system_table_opt() -> Option<SystemTable<Boot>> {
48-
let ptr = SYSTEM_TABLE.load(Ordering::Acquire);
49-
// Safety: the `SYSTEM_TABLE` pointer either be null or a valid system
50-
// table.
51-
//
52-
// Null is the initial value, as well as the value set when exiting boot
53-
// services. Otherwise, the value is set by the call to `init`, which
54-
// requires a valid system table reference as input.
55-
unsafe { SystemTable::from_ptr(ptr) }
56-
}
57-
5834
/// Obtains a pointer to the system table.
5935
///
6036
/// This is meant to be used by higher-level libraries,
@@ -66,7 +42,7 @@ fn system_table_opt() -> Option<SystemTable<Boot>> {
6642
#[must_use]
6743
// TODO do we want to keep this public?
6844
pub fn system_table() -> SystemTable<Boot> {
69-
system_table_opt().expect("The system table handle is not available")
45+
table::system_table_boot().expect("boot services are not active")
7046
}
7147

7248
/// Initialize all helpers defined in [`uefi::helpers`] whose Cargo features
@@ -78,15 +54,8 @@ pub fn system_table() -> SystemTable<Boot> {
7854
/// **PLEASE NOTE** that these helpers are meant for the pre exit boot service
7955
/// epoch. Limited functionality might work after exiting them, such as logging
8056
/// to the debugcon device.
57+
#[allow(unused_variables)] // `st` is unused if logger and allocator are disabled
8158
pub fn init(st: &mut SystemTable<Boot>) -> Result<()> {
82-
if system_table_opt().is_some() {
83-
// Avoid double initialization.
84-
return Status::SUCCESS.to_result_with_val(|| ());
85-
}
86-
87-
// Setup the system table singleton
88-
SYSTEM_TABLE.store(st.as_ptr().cast_mut(), Ordering::Release);
89-
9059
// Setup logging and memory allocation
9160

9261
#[cfg(feature = "logger")]
@@ -103,14 +72,6 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result<()> {
10372
}
10473

10574
pub(crate) fn exit() {
106-
// DEBUG: The UEFI spec does not guarantee that this printout will work, as
107-
// the services used by logging might already have been shut down.
108-
// But it works on current OVMF, and can be used as a handy way to
109-
// check that the callback does get called.
110-
//
111-
// info!("Shutting down the UEFI utility library");
112-
SYSTEM_TABLE.store(ptr::null_mut(), Ordering::Release);
113-
11475
#[cfg(feature = "logger")]
11576
logger::disable();
11677

uefi/src/helpers/panic_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use crate::helpers::system_table_opt;
21
use crate::println;
2+
use crate::table::system_table_boot;
33
use cfg_if::cfg_if;
44

55
#[panic_handler]
66
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
77
println!("[PANIC]: {}", info);
88

99
// Give the user some time to read the message
10-
if let Some(st) = system_table_opt() {
10+
if let Some(st) = system_table_boot() {
1111
st.boot_services().stall(10_000_000);
1212
} else {
1313
let mut dummy = 0u64;
@@ -28,7 +28,7 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
2828
qemu_exit_handle.exit_failure();
2929
} else {
3030
// If the system table is available, use UEFI's standard shutdown mechanism
31-
if let Some(st) = system_table_opt() {
31+
if let Some(st) = system_table_boot() {
3232
use crate::table::runtime::ResetType;
3333
st.runtime_services()
3434
.reset(ResetType::SHUTDOWN, crate::Status::ABORTED, None);

uefi/src/helpers/println.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::helpers::system_table;
1+
use crate::table::system_table_boot;
22
use core::fmt::Write;
33

44
/// INTERNAL API! Helper for print macros.
55
#[doc(hidden)]
66
pub fn _print(args: core::fmt::Arguments) {
7-
system_table()
7+
system_table_boot()
8+
.expect("boot services are not active")
89
.stdout()
910
.write_fmt(args)
1011
.expect("Failed to write to stdout");

0 commit comments

Comments
 (0)