From b9c49446c7a2744484fb014e9160d1a971f02bd0 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sat, 28 Sep 2024 12:04:57 -0400 Subject: [PATCH] uefi: Delete the uefi::table::system module --- uefi/CHANGELOG.md | 8 +- uefi/src/prelude.rs | 4 - uefi/src/table/mod.rs | 23 +----- uefi/src/table/system.rs | 157 --------------------------------------- 4 files changed, 5 insertions(+), 187 deletions(-) delete mode 100644 uefi/src/table/system.rs diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index 68342ea91..9f9fbaea3 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -4,11 +4,11 @@ See [Deprecating SystemTable/BootServices/RuntimeServices][funcmigrate] for details of the deprecated items that were removed in this release. ## Changed -- **Breaking:** Deleted the deprecated `BootServices` and `RuntimeServices` - structs. +- **Breaking:** Deleted the deprecated `BootServices`, `RuntimeServices`, and + `SystemTable` structs. - **Breaking:** Deleted deprecated functions `allocator::init`, - `allocator::exit_boot_services`, `helpers::system_table`, and - `table::system_table_runtime`. + `allocator::exit_boot_services`, `helpers::system_table`, + `table::system_table_boot`, and `table::system_table_runtime`. - **Breaking:** `FileSystem` no longer has a lifetime parameter, and the deprecated conversion from `uefi::table::boot::ScopedProtocol` has been removed. diff --git a/uefi/src/prelude.rs b/uefi/src/prelude.rs index a2ae5eb75..655b6fa39 100644 --- a/uefi/src/prelude.rs +++ b/uefi/src/prelude.rs @@ -5,7 +5,3 @@ pub use crate::{ boot, cstr16, cstr8, entry, runtime, system, Handle, ResultExt, Status, StatusExt, }; - -// Import the basic table types. -#[allow(deprecated)] -pub use crate::table::{Boot, SystemTable}; diff --git a/uefi/src/table/mod.rs b/uefi/src/table/mod.rs index 35b6f80b4..57f4d7c6a 100644 --- a/uefi/src/table/mod.rs +++ b/uefi/src/table/mod.rs @@ -3,11 +3,8 @@ pub mod cfg; mod header; -mod system; pub use header::Header; -#[allow(deprecated)] -pub use system::{Boot, SystemTable}; pub use uefi_raw::table::Revision; use core::ptr::{self, NonNull}; @@ -53,30 +50,12 @@ pub(crate) fn system_table_raw_panicking() -> NonNull Option> { - let st = SYSTEM_TABLE.load(Ordering::Acquire); - if st.is_null() { - return None; - } - - // SAFETY: the system table is valid per the requirements of `set_system_table`. - unsafe { - if (*st).boot_services.is_null() { - None - } else { - Some(SystemTable::::from_ptr(st.cast()).unwrap()) - } - } -} - /// Common trait implemented by all standard UEFI tables. pub trait Table { /// A unique number assigned by the UEFI specification diff --git a/uefi/src/table/system.rs b/uefi/src/table/system.rs deleted file mode 100644 index 8cdcd2adb..000000000 --- a/uefi/src/table/system.rs +++ /dev/null @@ -1,157 +0,0 @@ -#![allow(deprecated)] - -use super::{cfg, Revision}; -use crate::proto::console::text; -use crate::CStr16; -use core::ffi::c_void; -use core::marker::PhantomData; -use core::ptr::NonNull; -use core::slice; - -/// Marker trait used to provide different views of the UEFI System Table. -#[deprecated = "Use the uefi::system, uefi::boot, and uefi::runtime modules instead. See https://github.com/rust-osdev/uefi-rs/blob/HEAD/docs/funcs_migration.md"] -pub trait SystemTableView {} - -/// Marker struct associated with the boot view of the UEFI System Table. -#[deprecated = "Use the uefi::boot module instead. See https://github.com/rust-osdev/uefi-rs/blob/HEAD/docs/funcs_migration.md"] -#[derive(Debug)] -pub struct Boot; -impl SystemTableView for Boot {} - -/// UEFI System Table interface -/// -/// The UEFI System Table is the gateway to all UEFI services which an UEFI -/// application is provided access to on startup. However, not all UEFI services -/// will remain accessible forever. -/// -/// Some services, called "boot services", may only be called during a bootstrap -/// stage where the UEFI firmware still has control of the hardware, and will -/// become unavailable once the firmware hands over control of the hardware to -/// an operating system loader. Others, called "runtime services", may still be -/// used after that point, but require a rather specific CPU configuration which -/// an operating system loader is unlikely to preserve. -/// -/// We handle this state transition by providing two different views of the UEFI -/// system table, the "Boot" view and the "Runtime" view. An UEFI application -/// is initially provided with access to the "Boot" view, and may transition -/// to the "Runtime" view through the ExitBootServices mechanism that is -/// documented in the UEFI spec. At that point, the boot view of the system -/// table will be destroyed (which conveniently invalidates all references to -/// UEFI boot services in the eye of the Rust borrow checker) and a runtime view -/// will be provided to replace it -#[deprecated = "Use the uefi::system, uefi::boot, and uefi::runtime modules instead. See https://github.com/rust-osdev/uefi-rs/blob/HEAD/docs/funcs_migration.md"] -#[derive(Debug)] -#[repr(transparent)] -pub struct SystemTable { - table: *const uefi_raw::table::system::SystemTable, - _marker: PhantomData, -} - -// These parts of the UEFI System Table interface will always be available -impl SystemTable { - /// Return the firmware vendor string - #[must_use] - pub fn firmware_vendor(&self) -> &CStr16 { - unsafe { CStr16::from_ptr((*self.table).firmware_vendor.cast()) } - } - - /// Return the firmware revision - #[must_use] - pub const fn firmware_revision(&self) -> u32 { - unsafe { (*self.table).firmware_revision } - } - - /// Returns the revision of this table, which is defined to be - /// the revision of the UEFI specification implemented by the firmware. - #[must_use] - pub const fn uefi_revision(&self) -> Revision { - unsafe { (*self.table).header.revision } - } - - /// Returns the config table entries, a linear array of structures - /// pointing to other system-specific tables. - #[allow(clippy::missing_const_for_fn)] // Required until we bump the MSRV. - #[must_use] - pub fn config_table(&self) -> &[cfg::ConfigTableEntry] { - unsafe { - let table = &*self.table; - table - .configuration_table - .cast::() - .as_ref() - .map(|ptr| slice::from_raw_parts(ptr, table.number_of_configuration_table_entries)) - .unwrap_or(&[]) - } - } - - /// Creates a new `SystemTable` from a raw address. The address might - /// come from the Multiboot2 information structure or something similar. - /// - /// # Example - /// ```no_run - /// use core::ffi::c_void; - /// use uefi::prelude::{Boot, SystemTable}; - /// - /// let system_table_addr = 0xdeadbeef as *mut c_void; - /// - /// let mut uefi_system_table = unsafe { - /// SystemTable::::from_ptr(system_table_addr).expect("Pointer must not be null!") - /// }; - /// ``` - /// - /// # Safety - /// This function is unsafe because the caller must be sure that the pointer - /// is valid. Otherwise, further operations on the object might result in - /// undefined behaviour, even if the methods aren't marked as unsafe. - pub unsafe fn from_ptr(ptr: *mut c_void) -> Option { - NonNull::new(ptr.cast()).map(|ptr| Self { - table: ptr.as_ref(), - _marker: PhantomData, - }) - } - - /// Get the underlying raw pointer. - #[must_use] - pub const fn as_ptr(&self) -> *const c_void { - self.table.cast() - } -} - -// These parts of the UEFI System Table interface may only be used until boot -// services are exited and hardware control is handed over to the OS loader -impl SystemTable { - /// Returns the standard input protocol. - pub fn stdin(&mut self) -> &mut text::Input { - unsafe { &mut *(*self.table).stdin.cast() } - } - - /// Returns the standard output protocol. - pub fn stdout(&mut self) -> &mut text::Output { - unsafe { &mut *(*self.table).stdout.cast() } - } - - /// Returns the standard error protocol. - pub fn stderr(&mut self) -> &mut text::Output { - unsafe { &mut *(*self.table).stderr.cast() } - } - - /// Clone this boot-time UEFI system table interface - /// - /// # Safety - /// - /// This is unsafe because you must guarantee that the clone will not be - /// used after boot services are exited. However, the singleton-based - /// designs that Rust uses for memory allocation, logging, and panic - /// handling require taking this risk. - #[must_use] - pub const unsafe fn unsafe_clone(&self) -> Self { - Self { - table: self.table, - _marker: PhantomData, - } - } -} - -impl super::Table for SystemTable { - const SIGNATURE: u64 = 0x5453_5953_2049_4249; -}