@@ -18,7 +18,7 @@ pub struct MemoryMapTag {
1818 size : u32 ,
1919 entry_size : u32 ,
2020 entry_version : u32 ,
21- first_area : MemoryArea ,
21+ first_area : [ MemoryArea ; 0 ] ,
2222}
2323
2424impl MemoryMapTag {
@@ -31,10 +31,13 @@ impl MemoryMapTag {
3131 /// Return an iterator over all marked memory areas.
3232 pub fn all_memory_areas ( & self ) -> impl Iterator < Item = & MemoryArea > {
3333 let self_ptr = self as * const MemoryMapTag ;
34- let start_area = ( & self . first_area ) as * const MemoryArea ;
34+ let start_area = self . first_area . as_ptr ( ) ;
35+
3536 MemoryAreaIter {
3637 current_area : start_area as u64 ,
37- last_area : ( self_ptr as u64 + ( self . size - self . entry_size ) as u64 ) ,
38+ // NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
39+ last_area : ( self_ptr as u64
40+ + ( self . size as u64 - core:: mem:: size_of :: < MemoryMapTag > ( ) as u64 ) ) ,
3841 entry_size : self . entry_size ,
3942 phantom : PhantomData ,
4043 }
@@ -127,7 +130,7 @@ pub struct EFIMemoryMapTag {
127130 size : u32 ,
128131 desc_size : u32 ,
129132 desc_version : u32 ,
130- first_desc : EFIMemoryDesc ,
133+ first_desc : [ EFIMemoryDesc ; 0 ] ,
131134}
132135
133136impl EFIMemoryMapTag {
@@ -137,10 +140,12 @@ impl EFIMemoryMapTag {
137140 /// available memory areas for tables and such.
138141 pub fn memory_areas ( & self ) -> EFIMemoryAreaIter {
139142 let self_ptr = self as * const EFIMemoryMapTag ;
140- let start_area = ( & self . first_desc ) as * const EFIMemoryDesc ;
143+ let start_area = self . first_desc . as_ptr ( ) ;
141144 EFIMemoryAreaIter {
142145 current_area : start_area as u64 ,
143- last_area : ( self_ptr as u64 + self . size as u64 ) ,
146+ // NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
147+ last_area : ( self_ptr as u64
148+ + ( self . size as u64 - core:: mem:: size_of :: < EFIMemoryMapTag > ( ) as u64 ) ) ,
144149 entry_size : self . desc_size ,
145150 phantom : PhantomData ,
146151 }
0 commit comments