Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

uefi: Fix wrong install_configuration_table() signature #843

Merged
merged 1 commit into from
Jun 4, 2023
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
34 changes: 31 additions & 3 deletions uefi-test-runner/src/boot/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use core::ffi::c_void;
use core::ptr::{self, NonNull};

use uefi::proto::unsafe_protocol;
use uefi::table::boot::{BootServices, EventType, SearchType, TimerTrigger, Tpl};
use uefi::{Event, Identify};
use uefi::table::boot::{BootServices, EventType, MemoryType, SearchType, TimerTrigger, Tpl};
use uefi::table::{Boot, SystemTable};
use uefi::{guid, Event, Guid, Identify};

pub fn test(bt: &BootServices) {
pub fn test(st: &SystemTable<Boot>) {
let bt = st.boot_services();
info!("Testing timer...");
test_timer(bt);
info!("Testing events...");
Expand All @@ -18,6 +20,7 @@ pub fn test(bt: &BootServices) {
test_install_protocol_interface(bt);
test_reinstall_protocol_interface(bt);
test_uninstall_protocol_interface(bt);
test_install_configuration_table(st);
}

fn test_timer(bt: &BootServices) {
Expand Down Expand Up @@ -143,3 +146,28 @@ fn test_uninstall_protocol_interface(bt: &BootServices) {
.expect("Failed to uninstall protocol interface");
}
}

fn test_install_configuration_table(st: &SystemTable<Boot>) {
let config = st
.boot_services()
.allocate_pool(MemoryType::ACPI_RECLAIM, 1)
.expect("Failed to allocate config table");
unsafe { config.write(42) };

let count = st.config_table().len();
const ID: Guid = guid!("3bdb3089-5662-42df-840e-3922ed6467c9");

unsafe {
st.boot_services()
.install_configuration_table(&ID, config.cast())
.expect("Failed to install configuration table");
}

assert_eq!(count + 1, st.config_table().len());
let config_entry = st
.config_table()
.iter()
.find(|ct| ct.guid == ID)
.expect("Failed to find test config table");
assert_eq!(unsafe { *(config_entry.address as *const u8) }, 42);
}
6 changes: 4 additions & 2 deletions uefi-test-runner/src/boot/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use uefi::proto::console::text::Output;
use uefi::table::boot::{BootServices, SearchType};
use uefi::table::{Boot, SystemTable};
use uefi::Identify;

pub fn test(bt: &BootServices) {
pub fn test(st: &SystemTable<Boot>) {
let bt = st.boot_services();
info!("Testing boot services");
memory::test(bt);
misc::test(bt);
misc::test(st);
test_locate_handle_buffer(bt);
}

Expand Down
2 changes: 1 addition & 1 deletion uefi-test-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
bt.get_image_file_system(image)
.expect("Failed to retrieve boot file system");

boot::test(bt);
boot::test(&st);

// Test all the supported protocols.
proto::test(image, &mut st);
Expand Down
4 changes: 2 additions & 2 deletions uefi/src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub struct BootServices {
out_handle: &mut MaybeUninit<Handle>,
) -> Status,
install_configuration_table:
extern "efiapi" fn(guid_entry: Guid, table_ptr: *const c_void) -> Status,
extern "efiapi" fn(guid_entry: &Guid, table_ptr: *const c_void) -> Status,

// Image services
load_image: unsafe extern "efiapi" fn(
Expand Down Expand Up @@ -1161,7 +1161,7 @@ impl BootServices {
/// * [`uefi::Status::OUT_OF_RESOURCES`]
pub unsafe fn install_configuration_table(
&self,
guid_entry: Guid,
guid_entry: &Guid,
table_ptr: *const c_void,
) -> Result {
(self.install_configuration_table)(guid_entry, table_ptr).to_result()
Expand Down