From 01b019dda3002075e48ebb0d5759afa9bbef975b Mon Sep 17 00:00:00 2001 From: Akira Moroo Date: Sun, 2 May 2021 13:52:12 +0900 Subject: [PATCH] efi: Opt-out EFI variable support On current design, RuntimeServices.set_virtual_address_map overwrites all function pointers in the RuntimeServices to not_available function to avoid calling original functions on runtime phase. However, the Windows Hardware Abstraction Layer (HAL) stores the original RuntimeServices function addresses before the phase and uses the functions afterwards. This behavior causes invalid memory access error because this firmware does not do self-relocation. On Windows, it to use EFI variables on runtime phase (See issue #115). Signed-off-by: Akira Moroo --- Cargo.toml | 1 + src/efi/mod.rs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f4edc1c2..edf25674 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ log-serial = [] log-panic = ["log-serial"] integration_tests = [] coreboot = [] +efi-var = [] [dependencies] bitflags = "1.2.1" diff --git a/src/efi/mod.rs b/src/efi/mod.rs index a25ededb..81182652 100644 --- a/src/efi/mod.rs +++ b/src/efi/mod.rs @@ -291,9 +291,13 @@ pub extern "win64" fn get_variable( data_size: *mut usize, data: *mut c_void, ) -> Status { - VARIABLES - .borrow_mut() - .get(variable_name, vendor_guid, attributes, data_size, data) + if cfg!(feature = "efi-var") { + VARIABLES + .borrow_mut() + .get(variable_name, vendor_guid, attributes, data_size, data) + } else { + Status::NOT_FOUND + } } pub extern "win64" fn get_next_variable_name( @@ -311,9 +315,13 @@ pub extern "win64" fn set_variable( data_size: usize, data: *mut c_void, ) -> Status { - VARIABLES - .borrow_mut() - .set(variable_name, vendor_guid, attributes, data_size, data) + if cfg!(feature = "efi-var") { + VARIABLES + .borrow_mut() + .set(variable_name, vendor_guid, attributes, data_size, data) + } else { + Status::UNSUPPORTED + } } pub extern "win64" fn get_next_high_mono_count(_: *mut u32) -> Status {