@@ -1617,21 +1617,35 @@ pub struct MemoryMapSize {
16171617/// An accessory to the memory map that can be either iterated or
16181618/// indexed like an array.
16191619///
1620- /// A [`MemoryMap`] is always associated with the
1621- /// unique [`MemoryMapKey`] contained in the struct.
1620+ /// A [`MemoryMap`] is always associated with the unique [`MemoryMapKey`]
1621+ /// contained in the struct.
16221622///
16231623/// To iterate over the entries, call [`MemoryMap::entries`]. To get a sorted
16241624/// map, you manually have to call [`MemoryMap::sort`] first.
1625+ ///
1626+ /// ## UEFI pitfalls
1627+ /// **Please note that when working with memory maps, the `entry_size` is
1628+ /// usually larger than `size_of::<MemoryDescriptor` [[0]]. So to be safe,
1629+ /// always use `entry_size` as step-size when interfacing with the memory map on
1630+ /// a low level.
1631+ ///
1632+ ///
1633+ ///
1634+ /// [0]:. https://github.com/tianocore/edk2/blob/7142e648416ff5d3eac6c6d607874805f5de0ca8/MdeModulePkg/Core/PiSmmCore/Page.c#L1059
16251635#[ derive( Debug ) ]
16261636pub struct MemoryMap < ' buf > {
16271637 key : MemoryMapKey ,
16281638 buf : & ' buf mut [ u8 ] ,
1639+ /// Usually bound to the size of a [`MemoryDescriptor`] but can indicate if
1640+ /// this field is ever extended by a new UEFI standard.
16291641 entry_size : usize ,
16301642 len : usize ,
16311643}
16321644
16331645impl < ' buf > MemoryMap < ' buf > {
16341646 /// Creates a [`MemoryMap`] from the given buffer and entry size.
1647+ /// The entry size is usually bound to the size of a [`MemoryDescriptor`]
1648+ /// but can indicate if this field is ever extended by a new UEFI standard.
16351649 ///
16361650 /// This allows parsing a memory map provided by a kernel after boot
16371651 /// services have already exited.
@@ -1722,8 +1736,14 @@ impl<'buf> MemoryMap<'buf> {
17221736 elem. phys_start
17231737 }
17241738
1725- /// Returns an iterator over the contained memory map. To get a sorted map,
1726- /// call [`MemoryMap::sort`] first.
1739+ /// Returns an [`MemoryMapIter`] emitting [`MemoryDescriptor`]s.
1740+ ///
1741+ /// To get a sorted map, call [`MemoryMap::sort`] first.
1742+ ///
1743+ /// # UEFI pitfalls
1744+ /// Currently, only the descriptor version specified in
1745+ /// [`MemoryDescriptor`] is supported. This is going to change if the UEFI
1746+ /// spec ever introduces a new memory descriptor version.
17271747 #[ must_use]
17281748 pub fn entries ( & self ) -> MemoryMapIter {
17291749 MemoryMapIter {
0 commit comments