Skip to content

Commit 2277f17

Browse files
committed
uefi: add MemoryMap::raw() and MemoryMap::raw_mut()
There are scenarios where users need the raw memory map. For example, but not limited to, bootloaders that want to embed the EFI memory map in a Multiboot2 boot information structure.
1 parent da48cc2 commit 2277f17

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Added `table::{set_system_table, system_table_boot, system_table_runtime}`.
1212
This provides an initial API for global tables that do not require passing
1313
around a reference.
14+
- `MemoryMap::raw` and `MemoryMap::raw_mut`
1415

1516
## Changed
1617
- `SystemTable::exit_boot_services` is now `unsafe`. See that method's

uefi/src/table/boot.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,43 @@ impl<'buf> MemoryMap<'buf> {
18011801

18021802
Some(desc)
18031803
}
1804+
1805+
/// Returns a reference to the underlying buffer, which is the raw UEFI
1806+
/// memory map, and the corresponding properties.
1807+
#[must_use]
1808+
pub fn raw(
1809+
&'buf self,
1810+
) -> (
1811+
&'buf [u8],
1812+
usize, /* desc_size */
1813+
u32, /* version */
1814+
) {
1815+
(
1816+
&self.buf[0..self.map_size],
1817+
self.desc_size,
1818+
MemoryDescriptor::VERSION,
1819+
)
1820+
}
1821+
1822+
/// Mutable version of [`Self::raw`].
1823+
///
1824+
/// # Safety
1825+
/// Unsafe because changes to the memory map may break it, causing this
1826+
/// abstraction to produce erroneous behavior.
1827+
#[must_use]
1828+
pub unsafe fn raw_mut(
1829+
&'buf mut self,
1830+
) -> (
1831+
&'buf mut [u8],
1832+
usize, /* desc_size */
1833+
u32, /* version */
1834+
) {
1835+
(
1836+
&mut self.buf[0..self.map_size],
1837+
self.desc_size,
1838+
MemoryDescriptor::VERSION,
1839+
)
1840+
}
18041841
}
18051842

18061843
impl core::ops::Index<usize> for MemoryMap<'_> {

0 commit comments

Comments
 (0)