@@ -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.
266268pub 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