Skip to content

Commit d7697c3

Browse files
medhefgonicholasbishop
authored andcommitted
uefi: Fix wrong install_configuration_table() signature
Interestingly, this crashes on aarch64 but works on x86_64. Likely, the x86_64 calling convention used still passes the Guid struct by pointer, while the aarch64 passes it by value (or in an unexpected registers) causing a crash. This also adds a test case to verify this works correctly now. Fixes: #842
1 parent bb08157 commit d7697c3

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

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

+31-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ use core::ffi::c_void;
22
use core::ptr::{self, NonNull};
33

44
use uefi::proto::unsafe_protocol;
5-
use uefi::table::boot::{BootServices, EventType, SearchType, TimerTrigger, Tpl};
6-
use uefi::{Event, Identify};
5+
use uefi::table::boot::{BootServices, EventType, MemoryType, SearchType, TimerTrigger, Tpl};
6+
use uefi::table::{Boot, SystemTable};
7+
use uefi::{guid, Event, Guid, Identify};
78

8-
pub fn test(bt: &BootServices) {
9+
pub fn test(st: &SystemTable<Boot>) {
10+
let bt = st.boot_services();
911
info!("Testing timer...");
1012
test_timer(bt);
1113
info!("Testing events...");
@@ -18,6 +20,7 @@ pub fn test(bt: &BootServices) {
1820
test_install_protocol_interface(bt);
1921
test_reinstall_protocol_interface(bt);
2022
test_uninstall_protocol_interface(bt);
23+
test_install_configuration_table(st);
2124
}
2225

2326
fn test_timer(bt: &BootServices) {
@@ -143,3 +146,28 @@ fn test_uninstall_protocol_interface(bt: &BootServices) {
143146
.expect("Failed to uninstall protocol interface");
144147
}
145148
}
149+
150+
fn test_install_configuration_table(st: &SystemTable<Boot>) {
151+
let config = st
152+
.boot_services()
153+
.allocate_pool(MemoryType::ACPI_RECLAIM, 1)
154+
.expect("Failed to allocate config table");
155+
unsafe { config.write(42) };
156+
157+
let count = st.config_table().len();
158+
const ID: Guid = guid!("3bdb3089-5662-42df-840e-3922ed6467c9");
159+
160+
unsafe {
161+
st.boot_services()
162+
.install_configuration_table(&ID, config.cast())
163+
.expect("Failed to install configuration table");
164+
}
165+
166+
assert_eq!(count + 1, st.config_table().len());
167+
let config_entry = st
168+
.config_table()
169+
.iter()
170+
.find(|ct| ct.guid == ID)
171+
.expect("Failed to find test config table");
172+
assert_eq!(unsafe { *(config_entry.address as *const u8) }, 42);
173+
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use uefi::proto::console::text::Output;
22
use uefi::table::boot::{BootServices, SearchType};
3+
use uefi::table::{Boot, SystemTable};
34
use uefi::Identify;
45

5-
pub fn test(bt: &BootServices) {
6+
pub fn test(st: &SystemTable<Boot>) {
7+
let bt = st.boot_services();
68
info!("Testing boot services");
79
memory::test(bt);
8-
misc::test(bt);
10+
misc::test(st);
911
test_locate_handle_buffer(bt);
1012
}
1113

uefi-test-runner/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
4949
bt.get_image_file_system(image)
5050
.expect("Failed to retrieve boot file system");
5151

52-
boot::test(bt);
52+
boot::test(&st);
5353

5454
// Test all the supported protocols.
5555
proto::test(image, &mut st);

uefi/src/table/boot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub struct BootServices {
174174
out_handle: &mut MaybeUninit<Handle>,
175175
) -> Status,
176176
install_configuration_table:
177-
extern "efiapi" fn(guid_entry: Guid, table_ptr: *const c_void) -> Status,
177+
extern "efiapi" fn(guid_entry: &Guid, table_ptr: *const c_void) -> Status,
178178

179179
// Image services
180180
load_image: unsafe extern "efiapi" fn(
@@ -1161,7 +1161,7 @@ impl BootServices {
11611161
/// * [`uefi::Status::OUT_OF_RESOURCES`]
11621162
pub unsafe fn install_configuration_table(
11631163
&self,
1164-
guid_entry: Guid,
1164+
guid_entry: &Guid,
11651165
table_ptr: *const c_void,
11661166
) -> Result {
11671167
(self.install_configuration_table)(guid_entry, table_ptr).to_result()

0 commit comments

Comments
 (0)