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