Skip to content

Commit 58709dc

Browse files
committed
doc: internally handle BUFFER_TOO_SMALL in uefi::boot::memory_map()
We don't want to confuse users and let them think they should handle this, as they can't do anything about it anyway. This path won't be taken in OOM situations, but only if for unknown reasons, we failed to properly allocate the memory map.
1 parent c92777d commit 58709dc

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

uefi/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
- **Breaking:** Removed `BootPolicyError` as `BootPolicy` construction is no
55
longer fallible. `BootPolicy` now tightly integrates the new `Boolean` type
66
of `uefi-raw`.
7+
- `boot::memory_map()` will never return `Status::BUFFER_TOO_SMALL` from now on,
8+
as this is considered a hard internal error where users can't do anything
9+
about it anyway. It will panic instead.
10+
711

812
# uefi - 0.34.1 (2025-02-07)
913

uefi/src/boot.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ pub(crate) fn memory_map_size() -> MemoryMapMeta {
249249
///
250250
/// The implementation tries to mitigate some UEFI pitfalls, such as getting
251251
/// the right allocation size for the memory map to prevent
252-
/// [`Status::BUFFER_TOO_SMALL`]. If [`Status::BUFFER_TOO_SMALL`] is returned,
253-
/// further calls are likely to fail as well. If so, the situation may be
254-
/// considered as unrecoverable error.
252+
/// [`Status::BUFFER_TOO_SMALL`].
255253
///
256254
/// # Parameters
257255
///
@@ -261,12 +259,28 @@ pub(crate) fn memory_map_size() -> MemoryMapMeta {
261259
///
262260
/// # Errors
263261
///
264-
/// * [`Status::BUFFER_TOO_SMALL`]
265-
/// * [`Status::INVALID_PARAMETER`]
262+
/// * [`Status::INVALID_PARAMETER`]: Invalid [`MemoryType`]
263+
/// * [`Status::OUT_OF_RESOURCES`]: allocation failed.
264+
///
265+
/// # Panics
266+
///
267+
/// Panics if the memory map can't be retrieved.
266268
pub fn memory_map(mt: MemoryType) -> Result<MemoryMapOwned> {
267269
let mut buffer = MemoryMapBackingMemory::new(mt)?;
268270

269-
let meta = get_memory_map(buffer.as_mut_slice())?;
271+
let meta = get_memory_map(buffer.as_mut_slice());
272+
273+
if let Err(e) = &meta {
274+
// We don't want to confuse users and let them think they should handle
275+
// this, as they can't do anything about it anyway.
276+
//
277+
// This path won't be taken in OOM situations, but only if for unknown
278+
// reasons, we failed to properly allocate the memory map.
279+
if e.status() == Status::BUFFER_TOO_SMALL {
280+
panic!("Failed to get a proper allocation for the memory map");
281+
}
282+
}
283+
let meta = meta?;
270284

271285
Ok(MemoryMapOwned::from_initialized_mem(buffer, meta))
272286
}

0 commit comments

Comments
 (0)