aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi / src / proto / hii / database.rs
| 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | |
| 3 | //! HII Database protocol. |
| 4 | |
| 5 | use alloc::boxed::Box; |
| 6 | use core::ptr; |
| 7 | use uefi_macros::unsafe_protocol; |
| 8 | use uefi_raw::protocol::hii::database::HiiDatabaseProtocol; |
| 9 | |
| 10 | use crate::mem::make_boxed; |
| 11 | use crate::{Error, StatusExt}; |
| 12 | |
| 13 | /// The HII Configuration Access Protocol. |
| 14 | /// |
| 15 | /// This protocol grants access to the HII database definition available in every UEFI firmware. |
| 16 | /// This database contains internationalized strings, as well as a description of all |
| 17 | /// supported BIOS settings, together with their logic (e.g.: option A blocks option B if value is `true`). |
| 18 | /// |
| 19 | /// # UEFI Specification |
| 20 | /// |
| 21 | /// Database manager for HII-related data structures. |
| 22 | #[derive(Debug)] |
| 23 | #[repr(transparent)] |
| 24 | #[unsafe_protocol(HiiDatabaseProtocol::GUID)] |
| 25 | pub struct HiiDatabase(HiiDatabaseProtocol); |
| 26 | |
| 27 | impl HiiDatabase { |
| 28 | /// Export all package lists as raw byte buffer. |
| 29 | pub fn export_all_raw(&self) -> crate::Result<Box<[u8]>> { |
| 30 | fn fetch_data_fn<'a>( |
| 31 | proto: &HiiDatabase, |
| 32 | buf: &'a mut [u8], |
| 33 | ) -> Result<&'a mut [u8], Error<Option<usize>>> { |
| 34 | // SAFETY: The memory is valid. |
| 35 | unsafe { |
| 36 | let mut size = buf.len(); |
| 37 | let status = { |
| 38 | (proto.0.export_package_lists)( |
| 39 | &proto.0, |
| 40 | ptr::null_mut(), |
| 41 | &mut size, |
| 42 | buf.as_mut_ptr().cast(), |
| 43 | ) |
| 44 | }; |
| 45 | // The firmware may write less than it announced, so only |
| 46 | // return the part it actually filled. |
| 47 | status |
| 48 | .to_result_with_err(|_| Some(size)) |
| 49 | .map(|_| &mut buf[..size]) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | let buf = make_boxed::<[u8], _>(|buf| fetch_data_fn(self, buf))?; |
| 54 | |
| 55 | Ok(buf) |
| 56 | } |
| 57 | } |