@@ -328,6 +328,22 @@ impl EFIMemoryMapTag {
328
328
phantom : PhantomData ,
329
329
}
330
330
}
331
+
332
+ /// Return an iterator over ALL marked memory areas, mutably.
333
+ ///
334
+ /// This differs from `MemoryMapTag` as for UEFI, the OS needs some non-
335
+ /// available memory areas for tables and such.
336
+ pub fn memory_areas_mut ( & mut self ) -> EFIMemoryAreaIterMut {
337
+ let self_ptr = self as * mut EFIMemoryMapTag ;
338
+ let start_area = ( & mut self . descs [ 0 ] ) as * mut EFIMemoryDesc ;
339
+ EFIMemoryAreaIterMut {
340
+ current_area : start_area as u64 ,
341
+ // NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
342
+ last_area : ( self_ptr as * mut ( ) as u64 + self . size as u64 ) ,
343
+ entry_size : self . desc_size ,
344
+ phantom : PhantomData ,
345
+ }
346
+ }
331
347
}
332
348
333
349
impl TagTrait for EFIMemoryMapTag {
@@ -393,3 +409,25 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
393
409
}
394
410
}
395
411
}
412
+
413
+ /// An iterator over ALL EFI memory areas, mutably.
414
+ #[ derive( Clone , Debug ) ]
415
+ pub struct EFIMemoryAreaIterMut < ' a > {
416
+ current_area : u64 ,
417
+ last_area : u64 ,
418
+ entry_size : u32 ,
419
+ phantom : PhantomData < & ' a mut EFIMemoryDesc > ,
420
+ }
421
+
422
+ impl < ' a > Iterator for EFIMemoryAreaIterMut < ' a > {
423
+ type Item = & ' a mut EFIMemoryDesc ;
424
+ fn next ( & mut self ) -> Option < & ' a mut EFIMemoryDesc > {
425
+ if self . current_area > self . last_area {
426
+ None
427
+ } else {
428
+ let area = unsafe { & mut * ( self . current_area as * mut EFIMemoryDesc ) } ;
429
+ self . current_area += self . entry_size as u64 ;
430
+ Some ( area)
431
+ }
432
+ }
433
+ }
0 commit comments