Skip to content

Commit

Permalink
Merge pull request #1404 from rust-osdev/bishop-remove-rt
Browse files Browse the repository at this point in the history
Delete deprecated RuntimeServices struct
  • Loading branch information
phip1611 authored Sep 20, 2024
2 parents 5ad1504 + bdb925c commit d6eb99e
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 746 deletions.
16 changes: 4 additions & 12 deletions uefi-test-runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]
#![no_main]
// TODO: temporarily allow deprecated code so that we can continue to test
// SystemTable/BootServices/RuntimeServices.
// SystemTable/BootServices.
#![allow(deprecated)]

#[macro_use]
Expand Down Expand Up @@ -63,7 +63,7 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
// probably want to test them after exit_boot_services. However,
// exit_boot_services is currently called during shutdown.

runtime::test(st.runtime_services());
runtime::test();

shutdown(st);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ fn shutdown(mut st: SystemTable<Boot>) -> ! {
info!("Testing complete, exiting boot services...");

// Exit boot services as a proof that it works :)
let (st, mmap) = unsafe { st.exit_boot_services(MemoryType::LOADER_DATA) };
let mmap = unsafe { uefi::boot::exit_boot_services(MemoryType::LOADER_DATA) };

info!("Memory Map:");
for desc in mmap.entries() {
Expand All @@ -235,9 +235,6 @@ fn shutdown(mut st: SystemTable<Boot>) -> ! {

#[cfg(target_arch = "x86_64")]
{
// Prevent unused variable warning.
let _ = st;

use qemu_exit::QEMUExit;
let custom_exit_success = 3;
let qemu_exit_handle = qemu_exit::X86::new(0xF4, custom_exit_success);
Expand All @@ -247,11 +244,6 @@ fn shutdown(mut st: SystemTable<Boot>) -> ! {
#[cfg(not(target_arch = "x86_64"))]
{
// Shut down the system
let rt = unsafe { st.runtime_services() };
rt.reset(
uefi::table::runtime::ResetType::SHUTDOWN,
Status::SUCCESS,
None,
);
uefi::runtime::reset(uefi::runtime::ResetType::SHUTDOWN, Status::SUCCESS, None);
}
}
2 changes: 1 addition & 1 deletion uefi-test-runner/src/proto/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use uefi::proto::media::file::{
};
use uefi::proto::media::fs::SimpleFileSystem;
use uefi::proto::media::partition::{MbrOsType, PartitionInfo};
use uefi::table::runtime::{Daylight, Time, TimeParams};
use uefi::runtime::{Daylight, Time, TimeParams};

/// Test directory entry iteration.
fn test_existing_dir(directory: &mut Directory) {
Expand Down
4 changes: 2 additions & 2 deletions uefi-test-runner/src/proto/misc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use uefi::prelude::*;
use uefi::proto::misc::ResetNotification;
use uefi::table::runtime;
use uefi::runtime::ResetType;

pub fn test(bt: &BootServices) {
test_reset_notification(bt);
Expand All @@ -19,7 +19,7 @@ pub fn test_reset_notification(bt: &BootServices) {

// value efi_reset_fn is the type of ResetSystemFn, a function pointer
unsafe extern "efiapi" fn efi_reset_fn(
rt: runtime::ResetType,
rt: ResetType,
status: Status,
data_size: usize,
data: *const u8,
Expand Down
5 changes: 2 additions & 3 deletions uefi-test-runner/src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod vars;

use uefi::runtime::{self, Daylight, Time, TimeParams};
use uefi::table::runtime::RuntimeServices;

pub fn test(rt: &RuntimeServices) {
pub fn test() {
info!("Testing runtime services");
vars::test(rt);
vars::test();
test_time();
}

Expand Down
74 changes: 8 additions & 66 deletions uefi-test-runner/src/runtime/vars.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use log::info;
use uefi::prelude::*;
use uefi::table::runtime::{VariableAttributes, VariableVendor};
use uefi::runtime::{VariableAttributes, VariableVendor};
use uefi::{guid, runtime, CStr16, Error};

/// Test variable name.
Expand All @@ -16,63 +16,8 @@ const VALUE: &[u8] = b"TestValue";
const ATTRS: VariableAttributes =
VariableAttributes::BOOTSERVICE_ACCESS.union(VariableAttributes::RUNTIME_ACCESS);

fn test_variables(rt: &RuntimeServices) {
info!("Testing set_variable");
rt.set_variable(NAME, VENDOR, ATTRS, VALUE)
.expect("failed to set variable");

info!("Testing get_variable_size");
let size = rt
.get_variable_size(NAME, VENDOR)
.expect("failed to get variable size");
assert_eq!(size, VALUE.len());

info!("Testing get_variable");
let mut buf = [0u8; 9];
let (data, attrs) = rt
.get_variable(NAME, VENDOR, &mut buf)
.expect("failed to get variable");
assert_eq!(data, VALUE);
assert_eq!(attrs, ATTRS);

info!("Testing get_variable_boxed");
let (data, attrs) = rt
.get_variable_boxed(NAME, VENDOR)
.expect("failed to get variable");
assert_eq!(&*data, VALUE);
assert_eq!(attrs, ATTRS);

info!("Testing variable_keys");
let variable_keys = rt.variable_keys().expect("failed to get variable keys");
info!("Found {} variables", variable_keys.len());
// There are likely a bunch of variables, only print out the first one
// during the test to avoid spamming the log.
if let Some(key) = variable_keys.first() {
info!("First variable: {}", key);
}

// Test that the `runtime::variable_keys` iterator gives exactly the same
// list as the `RuntimeServices::variable_keys` function.
assert_eq!(
runtime::variable_keys()
.map(|k| k.unwrap())
.collect::<alloc::vec::Vec<_>>(),
variable_keys
);

info!("Testing delete_variable()");
rt.delete_variable(NAME, VENDOR)
.expect("failed to delete variable");
assert_eq!(
rt.get_variable(NAME, VENDOR, &mut buf)
.unwrap_err()
.status(),
Status::NOT_FOUND
);
}

/// Test the variable functions in `uefi::runtime`.
fn test_variables_freestanding() {
fn test_variables() {
assert!(!runtime::variable_exists(NAME, VENDOR).unwrap());

// Create the test variable.
Expand Down Expand Up @@ -121,20 +66,17 @@ fn test_variables_freestanding() {
assert!(!find_by_key());
}

fn test_variable_info(rt: &RuntimeServices) {
fn test_variable_info() {
let attr = VariableAttributes::BOOTSERVICE_ACCESS | VariableAttributes::NON_VOLATILE;
let info = rt.query_variable_info(attr).unwrap();
let info = runtime::query_variable_info(attr).unwrap();
info!("Storage for non-volatile boot-services variables: {info:?}");
assert_eq!(info, runtime::query_variable_info(attr).unwrap());

let attr = VariableAttributes::BOOTSERVICE_ACCESS | VariableAttributes::RUNTIME_ACCESS;
let info = rt.query_variable_info(attr).unwrap();
let info = runtime::query_variable_info(attr).unwrap();
info!("Storage for volatile runtime variables: {info:?}");
assert_eq!(info, runtime::query_variable_info(attr).unwrap());
}

pub fn test(rt: &RuntimeServices) {
test_variables(rt);
test_variable_info(rt);
test_variables_freestanding();
pub fn test() {
test_variable_info();
test_variables();
}
7 changes: 6 additions & 1 deletion uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# uefi - [Unreleased]

See [Deprecating SystemTable/BootServices/RuntimeServices][funcmigrate] for
details of the deprecated items that were removed in this release.

## Changed
- **Breaking:** Deleted deprecated function `helpers::system_table`.
- **Breaking:** Deleted the deprecated `RuntimeServices` struct.
- **Breaking:** Deleted deprecated functions `helpers::system_table` 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.
Expand Down
2 changes: 0 additions & 2 deletions uefi/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ pub use crate::{
#[allow(deprecated)]
pub use crate::table::boot::BootServices;
#[allow(deprecated)]
pub use crate::table::runtime::RuntimeServices;
#[allow(deprecated)]
pub use crate::table::{Boot, SystemTable};
24 changes: 0 additions & 24 deletions uefi/src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,30 +882,6 @@ impl BootServices {
)
}

/// Exits the UEFI boot services
///
/// This unsafe method is meant to be an implementation detail of the safe
/// `SystemTable<Boot>::exit_boot_services()` method, which is why it is not
/// public.
///
/// Everything that is explained in the documentation of the high-level
/// `SystemTable<Boot>` method is also true here, except that this function
/// is one-shot (no automatic retry) and does not prevent you from shooting
/// yourself in the foot by calling invalid boot services after a failure.
///
/// # Errors
///
/// See section `EFI_BOOT_SERVICES.ExitBootServices()` in the UEFI Specification for more details.
///
/// * [`uefi::Status::INVALID_PARAMETER`]
pub(super) unsafe fn exit_boot_services(
&self,
image: Handle,
mmap_key: MemoryMapKey,
) -> Result {
(self.0.exit_boot_services)(image.as_ptr(), mmap_key.0).to_result()
}

/// Stalls the processor for an amount of time.
///
/// The time is in microseconds.
Expand Down
22 changes: 1 addition & 21 deletions uefi/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
pub mod boot;
pub mod cfg;
pub mod runtime;

mod header;
mod system;

pub use header::Header;
#[allow(deprecated)]
pub use system::{Boot, Runtime, SystemTable};
pub use system::{Boot, SystemTable};
pub use uefi_raw::table::Revision;

use core::ptr::{self, NonNull};
Expand Down Expand Up @@ -79,25 +78,6 @@ pub fn system_table_boot() -> Option<SystemTable<Boot>> {
}
}

/// Get the system table while runtime services are active.
#[deprecated = "Use the uefi::runtime module instead. See https://github.com/rust-osdev/uefi-rs/blob/HEAD/docs/funcs_migration.md"]
#[allow(deprecated)]
pub fn system_table_runtime() -> Option<SystemTable<Runtime>> {
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).runtime_services.is_null() {
None
} else {
Some(SystemTable::<Runtime>::from_ptr(st.cast()).unwrap())
}
}
}

/// Common trait implemented by all standard UEFI tables.
pub trait Table {
/// A unique number assigned by the UEFI specification
Expand Down
Loading

0 comments on commit d6eb99e

Please sign in to comment.