|
1 | 1 | //! UEFI services available at runtime, even after the OS boots.
|
2 | 2 |
|
3 | 3 | use super::{Header, Revision};
|
4 |
| -#[cfg(feature = "alloc")] |
5 |
| -use crate::data_types::FromSliceWithNulError; |
6 |
| -use crate::result::Error; |
7 | 4 | use crate::table::boot::MemoryDescriptor;
|
8 |
| -use crate::{guid, CStr16, Char16, Guid, Result, Status, StatusExt}; |
9 |
| -#[cfg(feature = "alloc")] |
10 |
| -use alloc::{vec, vec::Vec}; |
| 5 | +use crate::{guid, CStr16, Char16, Error, Guid, Result, Status, StatusExt}; |
11 | 6 | use bitflags::bitflags;
|
12 | 7 | use core::ffi::c_void;
|
13 | 8 | use core::fmt::{Debug, Formatter};
|
14 |
| -#[cfg(feature = "alloc")] |
15 |
| -use core::mem; |
16 | 9 | use core::mem::MaybeUninit;
|
17 | 10 | use core::{fmt, ptr};
|
| 11 | + |
| 12 | +#[cfg(feature = "alloc")] |
| 13 | +use { |
| 14 | + crate::data_types::FromSliceWithNulError, |
| 15 | + alloc::boxed::Box, |
| 16 | + alloc::{vec, vec::Vec}, |
| 17 | + core::mem, |
| 18 | +}; |
| 19 | + |
18 | 20 | /// Contains pointers to all of the runtime services.
|
19 | 21 | ///
|
20 | 22 | /// This table, and the function pointers it contains are valid
|
@@ -159,6 +161,38 @@ impl RuntimeServices {
|
159 | 161 | }
|
160 | 162 | }
|
161 | 163 |
|
| 164 | + /// Get the contents and attributes of a variable. |
| 165 | + #[cfg(feature = "alloc")] |
| 166 | + pub fn get_variable_boxed( |
| 167 | + &self, |
| 168 | + name: &CStr16, |
| 169 | + vendor: &VariableVendor, |
| 170 | + ) -> Result<(Box<[u8]>, VariableAttributes)> { |
| 171 | + let mut attributes = VariableAttributes::empty(); |
| 172 | + |
| 173 | + let mut data_size = self.get_variable_size(name, vendor)?; |
| 174 | + let mut data = Vec::with_capacity(data_size); |
| 175 | + |
| 176 | + let status = unsafe { |
| 177 | + (self.get_variable)( |
| 178 | + name.as_ptr(), |
| 179 | + &vendor.0, |
| 180 | + &mut attributes, |
| 181 | + &mut data_size, |
| 182 | + data.as_mut_ptr(), |
| 183 | + ) |
| 184 | + }; |
| 185 | + if !status.is_success() { |
| 186 | + return Err(Error::from(status)); |
| 187 | + } |
| 188 | + |
| 189 | + unsafe { |
| 190 | + data.set_len(data_size); |
| 191 | + } |
| 192 | + |
| 193 | + Ok((data.into_boxed_slice(), attributes)) |
| 194 | + } |
| 195 | + |
162 | 196 | /// Get the names and vendor GUIDs of all currently-set variables.
|
163 | 197 | #[cfg(feature = "alloc")]
|
164 | 198 | pub fn variable_keys(&self) -> Result<Vec<VariableKey>> {
|
|
0 commit comments