use core::{ffi::c_void, ptr::NonNull};
use uefi::{
Status, guid,
proto::{
device_path::{DevicePath, FfiDevicePath},
unsafe_protocol,
},
};
type Bool = u8;
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct DevicetreeFixupProtocol {
revision: u64,
pub(crate) fixup: unsafe extern "efiapi" fn(
this: *mut Self,
fdt: *mut c_void,
buffer_size: *mut usize,
flags: u32,
) -> Status,
}
impl DevicetreeFixupProtocol {
const GUID: uefi::Guid = guid!("e617d64c-fe08-46da-f4dc-bbd5870c7300");
}
#[derive(Clone, Copy, Debug)]
#[repr(transparent)]
#[unsafe_protocol(DevicetreeFixupProtocol::GUID)]
pub struct DevicetreeFixup(DevicetreeFixupProtocol);
impl DevicetreeFixup {
pub fn fixup(&mut self, fdt: NonNull<u8>, buffer_size: &mut usize, flags: u32) -> Status {
let fdt = fdt.as_ptr().cast::<c_void>();
unsafe { (self.0.fixup)(&raw mut self.0, fdt, buffer_size, flags) }
}
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct SecurityArchProtocol {
pub(crate) auth_state: unsafe extern "efiapi" fn(
this: *const Self,
auth_status: u32,
file: *const FfiDevicePath,
) -> Status,
}
impl SecurityArchProtocol {
const GUID: uefi::Guid = guid!("a46423e3-4617-49f1-b9ff-d1bfa9115839");
}
#[derive(Clone, Copy, Debug)]
#[repr(transparent)]
#[unsafe_protocol(SecurityArchProtocol::GUID)]
pub struct SecurityArch(SecurityArchProtocol);
impl SecurityArch {
pub fn auth_state(&self, auth_status: u32, file: &DevicePath) -> Status {
let file = file.as_ffi_ptr();
unsafe { (self.0.auth_state)(&raw const self.0, auth_status, file) }
}
#[must_use = "Has no effect if the result is unused"]
pub(crate) const fn get_inner(&self) -> &SecurityArchProtocol {
&self.0
}
pub(crate) const fn get_inner_mut(&mut self) -> &mut SecurityArchProtocol {
&mut self.0
}
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct Security2ArchProtocol {
pub(crate) authentication: unsafe extern "efiapi" fn(
this: *const Self,
device_path: *const FfiDevicePath,
file_buffer: *mut c_void,
file_size: usize,
boot_policy: Bool,
) -> Status,
}
impl Security2ArchProtocol {
const GUID: uefi::Guid = guid!("94ab2f58-1438-4ef1-9152-18941a3a0e68");
}
#[derive(Clone, Copy, Debug)]
#[repr(transparent)]
#[unsafe_protocol(Security2ArchProtocol::GUID)]
pub struct Security2Arch(Security2ArchProtocol);
impl Security2Arch {
pub fn authentication(
&self,
device_path: Option<&DevicePath>,
file_buffer: &mut [u8],
boot_policy: bool,
) -> Status {
let device_path = device_path.map_or(core::ptr::null(), DevicePath::as_ffi_ptr);
let file_size = file_buffer.len();
let file_buffer = file_buffer.as_mut_ptr().cast::<c_void>();
unsafe {
(self.0.authentication)(
&raw const self.0,
device_path,
file_buffer,
file_size,
Bool::from(boot_policy),
)
}
}
#[must_use = "Has no effect if the result is unused"]
pub(crate) const fn get_inner(&self) -> &Security2ArchProtocol {
&self.0
}
pub(crate) const fn get_inner_mut(&mut self) -> &mut Security2ArchProtocol {
&mut self.0
}
}
#[derive(Clone, Debug)]
#[repr(C)]
pub struct ShimImageLoaderProtocol {
pub(crate) load_image: unsafe extern "efiapi" fn(
boot_policy: Bool,
parent: *mut c_void,
device_path: *mut FfiDevicePath,
src: *mut c_void,
src_size: usize,
image: *mut c_void,
),
pub(crate) start_image: unsafe extern "efiapi" fn(
image: *mut c_void,
exit_data_size: *mut usize,
exit_data: *mut u16,
),
pub(crate) exit: unsafe extern "efiapi" fn(
image: *mut c_void,
status: Status,
exit_data_size: usize,
exit_data: *mut u16,
),
pub(crate) unload_image: unsafe extern "efiapi" fn(image: *mut c_void),
}
impl ShimImageLoaderProtocol {
const GUID: uefi::Guid = guid!("1f492041-fadb-4e59-9e57-7cafe73a55ab");
}
#[derive(Clone, Debug)]
#[repr(transparent)]
#[unsafe_protocol(ShimImageLoaderProtocol::GUID)]
pub struct ShimImageLoader(ShimImageLoaderProtocol);