@@ -254,6 +254,22 @@ impl EFIMemoryMapTag {
254
254
phantom : PhantomData ,
255
255
}
256
256
}
257
+
258
+ /// Return an iterator over ALL marked memory areas, mutably.
259
+ ///
260
+ /// This differs from `MemoryMapTag` as for UEFI, the OS needs some non-
261
+ /// available memory areas for tables and such.
262
+ pub fn memory_areas_mut ( & mut self ) -> EFIMemoryAreaIterMut {
263
+ let self_ptr = self as * const EFIMemoryMapTag ;
264
+ let start_area = ( & self . descs [ 0 ] ) as * const EFIMemoryDesc ;
265
+ EFIMemoryAreaIterMut {
266
+ current_area : start_area as u64 ,
267
+ // NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
268
+ last_area : ( self_ptr as * const ( ) as u64 + self . size as u64 ) ,
269
+ entry_size : self . desc_size ,
270
+ phantom : PhantomData ,
271
+ }
272
+ }
257
273
}
258
274
259
275
impl TagTrait for EFIMemoryMapTag {
@@ -332,3 +348,25 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
332
348
}
333
349
}
334
350
}
351
+
352
+ /// An iterator over ALL EFI memory areas, mutably.
353
+ #[ derive( Clone , Debug ) ]
354
+ pub struct EFIMemoryAreaIterMut < ' a > {
355
+ current_area : u64 ,
356
+ last_area : u64 ,
357
+ entry_size : u32 ,
358
+ phantom : PhantomData < & ' a mut EFIMemoryDesc > ,
359
+ }
360
+
361
+ impl < ' a > Iterator for EFIMemoryAreaIterMut < ' a > {
362
+ type Item = & ' a mut EFIMemoryDesc ;
363
+ fn next ( & mut self ) -> Option < & ' a mut EFIMemoryDesc > {
364
+ if self . current_area > self . last_area {
365
+ None
366
+ } else {
367
+ let area = unsafe { & mut * ( self . current_area as * mut EFIMemoryDesc ) } ;
368
+ self . current_area += self . entry_size as u64 ;
369
+ Some ( area)
370
+ }
371
+ }
372
+ }
0 commit comments