From fc3764c2f0d8fafc5b7e9af18e8f57c2e7552563 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 12 Aug 2024 11:57:57 -0400 Subject: [PATCH] uefi: Add table::system_table_raw This provides an alternative to `SystemTable::as_ptr`. --- uefi/CHANGELOG.md | 2 ++ uefi/src/table/mod.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index 4beaefb0e..00f0cac26 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -10,6 +10,8 @@ details of a significant change to the API in this release. boot services using the global system table. - `uefi::runtime` is a new module that provides freestanding functions for runtime services using the global system table. +- `uefi::table::system_table_raw` is a new function to retrieve a raw pointer to + the global system table. - Add standard derives for `ConfigTableEntry`. - `PcrEvent`/`PcrEventInputs` impl `Align`, `Eq`, and `PartialEq`. - Added `PcrEvent::new_in_box` and `PcrEventInputs::new_in_box`. diff --git a/uefi/src/table/mod.rs b/uefi/src/table/mod.rs index e8f54b396..fcf4fa7ad 100644 --- a/uefi/src/table/mod.rs +++ b/uefi/src/table/mod.rs @@ -18,6 +18,14 @@ use core::sync::atomic::{AtomicPtr, Ordering}; static SYSTEM_TABLE: AtomicPtr = AtomicPtr::new(ptr::null_mut()); +/// Get the raw system table pointer. +/// +/// If called before `set_system_table` has been called, this will return `None`. +pub fn system_table_raw() -> Option> { + let ptr = SYSTEM_TABLE.load(Ordering::Acquire); + NonNull::new(ptr) +} + /// Get the raw system table pointer. This may only be called after /// `set_system_table` has been used to set the global pointer. /// @@ -26,8 +34,7 @@ static SYSTEM_TABLE: AtomicPtr = /// Panics if the global system table pointer is null. #[track_caller] pub(crate) fn system_table_raw_panicking() -> NonNull { - let ptr = SYSTEM_TABLE.load(Ordering::Acquire); - NonNull::new(ptr).expect("global system table pointer is not set") + system_table_raw().expect("global system table pointer is not set") } /// Update the global system table pointer.