Skip to content

Commit 804115d

Browse files
authored
Merge pull request #1306 from nicholasbishop/bishop-install-config-table
boot: Add freestanding install_configuration_table
2 parents c684367 + 929ab80 commit 804115d

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

uefi-test-runner/src/boot/misc.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use uefi::table::boot::{
99
Tpl,
1010
};
1111
use uefi::table::{Boot, SystemTable};
12-
use uefi::{boot, guid, Event, Guid, Identify, Status};
12+
use uefi::{boot, guid, system, Event, Guid, Identify, Status};
1313

1414
pub fn test(st: &SystemTable<Boot>) {
1515
let bt = st.boot_services();
@@ -30,6 +30,7 @@ pub fn test(st: &SystemTable<Boot>) {
3030
test_reinstall_protocol_interface(bt);
3131
test_uninstall_protocol_interface(bt);
3232
test_install_configuration_table(st);
33+
test_install_configuration_table_freestanding();
3334
}
3435

3536
fn test_tpl() {
@@ -262,6 +263,35 @@ fn test_uninstall_protocol_interface(bt: &BootServices) {
262263
}
263264
}
264265

266+
fn test_install_configuration_table_freestanding() {
267+
// Get the current number of entries.
268+
let count = system::with_config_table(|t| t.len());
269+
270+
// Create the entry data.
271+
let config = boot::allocate_pool(MemoryType::RUNTIME_SERVICES_DATA, 1)
272+
.unwrap()
273+
.as_ptr();
274+
unsafe { config.write(42) };
275+
276+
// Install the table.
277+
const ID: Guid = guid!("4bec53c4-5fc1-48a1-ab12-df214907d29f");
278+
unsafe {
279+
boot::install_configuration_table(&ID, config.cast()).unwrap();
280+
}
281+
282+
// Verify the installation.
283+
assert_eq!(count + 1, system::with_config_table(|t| t.len()));
284+
system::with_config_table(|t| {
285+
let config_entry = t.iter().find(|ct| ct.guid == ID).unwrap();
286+
assert_eq!(unsafe { *(config_entry.address as *const u8) }, 42);
287+
});
288+
289+
// Uninstall the table.
290+
unsafe {
291+
boot::install_configuration_table(&ID, ptr::null()).unwrap();
292+
}
293+
}
294+
265295
fn test_install_configuration_table(st: &SystemTable<Boot>) {
266296
let config = st
267297
.boot_services()

uefi/src/boot.rs

+26
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,32 @@ pub unsafe fn exit(
724724
)
725725
}
726726

727+
/// Adds, updates, or removes a configuration table entry
728+
/// from the EFI System Table.
729+
///
730+
/// # Safety
731+
///
732+
/// When installing or updating a configuration table, the data pointed to by
733+
/// `table_ptr` must be a pool allocation of type
734+
/// [`RUNTIME_SERVICES_DATA`]. Once this table has been installed, the caller
735+
/// should not modify or free the data.
736+
///
737+
/// [`RUNTIME_SERVICES_DATA`]: MemoryType::RUNTIME_SERVICES_DATA
738+
///
739+
/// # Errors
740+
///
741+
/// * [`Status::NOT_FOUND`]: tried to delete a nonexistent entry.
742+
/// * [`Status::OUT_OF_RESOURCES`]: out of memory.
743+
pub unsafe fn install_configuration_table(
744+
guid_entry: &'static Guid,
745+
table_ptr: *const c_void,
746+
) -> Result {
747+
let bt = boot_services_raw_panicking();
748+
let bt = unsafe { bt.as_ref() };
749+
750+
(bt.install_configuration_table)(guid_entry, table_ptr).to_result()
751+
}
752+
727753
/// Stalls execution for the given number of microseconds.
728754
pub fn stall(microseconds: usize) {
729755
let bt = boot_services_raw_panicking();

0 commit comments

Comments
 (0)