@@ -314,6 +314,22 @@ impl EFIMemoryMapTag {
314
314
phantom : PhantomData ,
315
315
}
316
316
}
317
+
318
+ /// Return an iterator over ALL marked memory areas, mutably.
319
+ ///
320
+ /// This differs from `MemoryMapTag` as for UEFI, the OS needs some non-
321
+ /// available memory areas for tables and such.
322
+ pub fn memory_areas_mut ( & mut self ) -> EFIMemoryAreaIterMut {
323
+ let self_ptr = self as * const EFIMemoryMapTag ;
324
+ let start_area = ( & self . descs [ 0 ] ) as * const EFIMemoryDesc ;
325
+ EFIMemoryAreaIterMut {
326
+ current_area : start_area as u64 ,
327
+ // NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
328
+ last_area : ( self_ptr as * const ( ) as u64 + self . size as u64 ) ,
329
+ entry_size : self . desc_size ,
330
+ phantom : PhantomData ,
331
+ }
332
+ }
317
333
}
318
334
319
335
impl TagTrait for EFIMemoryMapTag {
@@ -532,3 +548,25 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
532
548
}
533
549
}
534
550
}
551
+
552
+ /// An iterator over ALL EFI memory areas, mutably.
553
+ #[ derive( Clone , Debug ) ]
554
+ pub struct EFIMemoryAreaIterMut < ' a > {
555
+ current_area : u64 ,
556
+ last_area : u64 ,
557
+ entry_size : u32 ,
558
+ phantom : PhantomData < & ' a mut EFIMemoryDesc > ,
559
+ }
560
+
561
+ impl < ' a > Iterator for EFIMemoryAreaIterMut < ' a > {
562
+ type Item = & ' a mut EFIMemoryDesc ;
563
+ fn next ( & mut self ) -> Option < & ' a mut EFIMemoryDesc > {
564
+ if self . current_area > self . last_area {
565
+ None
566
+ } else {
567
+ let area = unsafe { & mut * ( self . current_area as * mut EFIMemoryDesc ) } ;
568
+ self . current_area += self . entry_size as u64 ;
569
+ Some ( area)
570
+ }
571
+ }
572
+ }
0 commit comments