Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion uefi-test-runner/src/boot/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use uefi::table::boot::{
Tpl,
};
use uefi::table::{Boot, SystemTable};
use uefi::{boot, guid, Event, Guid, Identify, Status};
use uefi::{boot, guid, system, Event, Guid, Identify, Status};

pub fn test(st: &SystemTable<Boot>) {
let bt = st.boot_services();
Expand All @@ -30,6 +30,7 @@ pub fn test(st: &SystemTable<Boot>) {
test_reinstall_protocol_interface(bt);
test_uninstall_protocol_interface(bt);
test_install_configuration_table(st);
test_install_configuration_table_freestanding();
}

fn test_tpl() {
Expand Down Expand Up @@ -262,6 +263,35 @@ fn test_uninstall_protocol_interface(bt: &BootServices) {
}
}

fn test_install_configuration_table_freestanding() {
// Get the current number of entries.
let count = system::with_config_table(|t| t.len());

// Create the entry data.
let config = boot::allocate_pool(MemoryType::RUNTIME_SERVICES_DATA, 1)
.unwrap()
.as_ptr();
unsafe { config.write(42) };

// Install the table.
const ID: Guid = guid!("4bec53c4-5fc1-48a1-ab12-df214907d29f");
unsafe {
boot::install_configuration_table(&ID, config.cast()).unwrap();
}

// Verify the installation.
assert_eq!(count + 1, system::with_config_table(|t| t.len()));
system::with_config_table(|t| {
let config_entry = t.iter().find(|ct| ct.guid == ID).unwrap();
assert_eq!(unsafe { *(config_entry.address as *const u8) }, 42);
});

// Uninstall the table.
unsafe {
boot::install_configuration_table(&ID, ptr::null()).unwrap();
}
}

fn test_install_configuration_table(st: &SystemTable<Boot>) {
let config = st
.boot_services()
Expand Down
26 changes: 26 additions & 0 deletions uefi/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,32 @@ pub unsafe fn exit(
)
}

/// Adds, updates, or removes a configuration table entry
/// from the EFI System Table.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I thought we want to consistently use UEFI rather than EFI.

We can do that in a tree-wide follow-up soon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, agree. I copied from the method docstring and didn't proofread carefully :)

///
/// # Safety
///
/// When installing or updating a configuration table, the data pointed to by
/// `table_ptr` must be a pool allocation of type
/// [`RUNTIME_SERVICES_DATA`]. Once this table has been installed, the caller
/// should not modify or free the data.
///
/// [`RUNTIME_SERVICES_DATA`]: MemoryType::RUNTIME_SERVICES_DATA
///
/// # Errors
///
/// * [`Status::NOT_FOUND`]: tried to delete a nonexistent entry.
/// * [`Status::OUT_OF_RESOURCES`]: out of memory.
pub unsafe fn install_configuration_table(
guid_entry: &'static Guid,
table_ptr: *const c_void,
) -> Result {
let bt = boot_services_raw_panicking();
let bt = unsafe { bt.as_ref() };

(bt.install_configuration_table)(guid_entry, table_ptr).to_result()
}

/// Stalls execution for the given number of microseconds.
pub fn stall(microseconds: usize) {
let bt = boot_services_raw_panicking();
Expand Down