@@ -1617,21 +1617,35 @@ pub struct MemoryMapSize {
1617
1617
/// An accessory to the memory map that can be either iterated or
1618
1618
/// indexed like an array.
1619
1619
///
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.
1622
1622
///
1623
1623
/// To iterate over the entries, call [`MemoryMap::entries`]. To get a sorted
1624
1624
/// 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
1625
1635
#[ derive( Debug ) ]
1626
1636
pub struct MemoryMap < ' buf > {
1627
1637
key : MemoryMapKey ,
1628
1638
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.
1629
1641
entry_size : usize ,
1630
1642
len : usize ,
1631
1643
}
1632
1644
1633
1645
impl < ' buf > MemoryMap < ' buf > {
1634
1646
/// 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.
1635
1649
///
1636
1650
/// This allows parsing a memory map provided by a kernel after boot
1637
1651
/// services have already exited.
@@ -1722,8 +1736,14 @@ impl<'buf> MemoryMap<'buf> {
1722
1736
elem. phys_start
1723
1737
}
1724
1738
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.
1727
1747
#[ must_use]
1728
1748
pub fn entries ( & self ) -> MemoryMapIter {
1729
1749
MemoryMapIter {
0 commit comments