Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 44bdca2

Browse files
uefi: Add get_variable_boxed
This alloc-only method is a more convenient form of `get_variable`.
1 parent e84e76f commit 44bdca2

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- `From<&CStr16>` for `CString16`
2020
- `From<&CStr16>` for `String`
2121
- `From<&CString16>` for `String`
22+
- Added `RuntimeServices::get_variable_boxed` (requires the `alloc` feature).
2223

2324
### Changed
2425

‎uefi-test-runner/src/runtime/vars.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ fn test_variables(rt: &RuntimeServices) {
2929
assert_eq!(data, test_value);
3030
assert_eq!(attrs, test_attrs);
3131

32+
info!("Testing get_variable_boxed");
33+
let (data, attrs) = rt
34+
.get_variable_boxed(name, &vendor)
35+
.expect("failed to get variable");
36+
assert_eq!(&*data, test_value);
37+
assert_eq!(attrs, test_attrs);
38+
3239
info!("Testing variable_keys");
3340
let variable_keys = rt.variable_keys().expect("failed to get variable keys");
3441
info!("Found {} variables", variable_keys.len());

‎uefi/src/table/runtime.rs‎

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
//! UEFI services available at runtime, even after the OS boots.
22
33
use super::{Header, Revision};
4-
#[cfg(feature = "alloc")]
5-
use crate::data_types::FromSliceWithNulError;
6-
use crate::result::Error;
74
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};
116
use bitflags::bitflags;
127
use core::ffi::c_void;
138
use core::fmt::{Debug, Formatter};
14-
#[cfg(feature = "alloc")]
15-
use core::mem;
169
use core::mem::MaybeUninit;
1710
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+
1820
/// Contains pointers to all of the runtime services.
1921
///
2022
/// This table, and the function pointers it contains are valid
@@ -159,6 +161,38 @@ impl RuntimeServices {
159161
}
160162
}
161163

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+
162196
/// Get the names and vendor GUIDs of all currently-set variables.
163197
#[cfg(feature = "alloc")]
164198
pub fn variable_keys(&self) -> Result<Vec<VariableKey>> {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /