@@ -330,6 +330,22 @@ impl EFIMemoryMapTag {
330
330
phantom : PhantomData ,
331
331
}
332
332
}
333
+
334
+ /// Return an iterator over ALL marked memory areas, mutably.
335
+ ///
336
+ /// This differs from `MemoryMapTag` as for UEFI, the OS needs some non-
337
+ /// available memory areas for tables and such.
338
+ pub fn memory_areas_mut ( & mut self ) -> EFIMemoryAreaIterMut {
339
+ let self_ptr = self as * mut EFIMemoryMapTag ;
340
+ let start_area = ( & mut self . descs [ 0 ] ) as * mut EFIMemoryDesc ;
341
+ EFIMemoryAreaIterMut {
342
+ current_area : start_area as u64 ,
343
+ // NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
344
+ last_area : ( self_ptr as * mut ( ) as u64 + self . size as u64 ) ,
345
+ entry_size : self . desc_size ,
346
+ phantom : PhantomData ,
347
+ }
348
+ }
333
349
}
334
350
335
351
impl TagTrait for EFIMemoryMapTag {
@@ -364,3 +380,25 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
364
380
}
365
381
}
366
382
}
383
+
384
+ /// An iterator over ALL EFI memory areas, mutably.
385
+ #[ derive( Clone , Debug ) ]
386
+ pub struct EFIMemoryAreaIterMut < ' a > {
387
+ current_area : u64 ,
388
+ last_area : u64 ,
389
+ entry_size : u32 ,
390
+ phantom : PhantomData < & ' a mut EFIMemoryDesc > ,
391
+ }
392
+
393
+ impl < ' a > Iterator for EFIMemoryAreaIterMut < ' a > {
394
+ type Item = & ' a mut EFIMemoryDesc ;
395
+ fn next ( & mut self ) -> Option < & ' a mut EFIMemoryDesc > {
396
+ if self . current_area > self . last_area {
397
+ None
398
+ } else {
399
+ let area = unsafe { & mut * ( self . current_area as * mut EFIMemoryDesc ) } ;
400
+ self . current_area += self . entry_size as u64 ;
401
+ Some ( area)
402
+ }
403
+ }
404
+ }
0 commit comments