Skip to content

Commit 144b770

Browse files
committed
uefi: MemoryMap: simplify API
1 parent ea48eec commit 144b770

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

uefi/src/table/boot.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ impl BootServices {
262262
&mut entry_version,
263263
)
264264
}
265-
.to_result_with_val(move || MemoryMap::from_raw(map_size, buffer, desc_size, map_key))
265+
.to_result_with_val(move || {
266+
MemoryMap::from_raw(&mut buffer[0..map_size], desc_size, map_key)
267+
})
266268
}
267269

268270
/// Allocates from a memory pool. The pointer will be 8-byte aligned.
@@ -1640,35 +1642,27 @@ pub struct MemoryMap<'buf> {
16401642
/// Usually bound to the size of a [`MemoryDescriptor`] but can indicate if
16411643
/// this field is ever extended by a new UEFI standard.
16421644
desc_size: usize,
1643-
map_size: usize,
16441645
num_entries: usize,
16451646
}
16461647

16471648
impl<'buf> MemoryMap<'buf> {
16481649
/// Creates a [`MemoryMap`] from the given buffer, and the reported
1649-
/// memory map size, descriptor size, and [`MemoryMapKey`] from UEFI.
1650-
///
1651-
/// This map technically owns the buffer (although not modeled yet by type
1652-
/// system).
1653-
pub fn from_raw(
1654-
map_size: usize,
1655-
buf: &'buf mut [u8],
1656-
desc_size: usize,
1657-
key: MemoryMapKey,
1658-
) -> Self {
1650+
/// descriptor size, and [`MemoryMapKey`] from UEFI.
1651+
///
1652+
/// The buffer length is expected to match `memory_map_size` reported by
1653+
/// UEFI.
1654+
pub fn from_raw(buf: &'buf mut [u8], desc_size: usize, key: MemoryMapKey) -> Self {
16591655
assert!(!buf.is_empty());
1660-
assert!(map_size <= buf.len());
16611656
assert_eq!(
16621657
buf.len() % desc_size,
16631658
0,
16641659
"The buffer length must be a multiple of the desc_size"
16651660
);
16661661
assert!(desc_size >= mem::size_of::<MemoryDescriptor>());
1667-
let num_entries = map_size / desc_size;
1662+
let num_entries = buf.len() / desc_size;
16681663
MemoryMap {
16691664
key,
16701665
buf,
1671-
map_size,
16721666
desc_size,
16731667
num_entries,
16741668
}
@@ -1812,11 +1806,7 @@ impl<'buf> MemoryMap<'buf> {
18121806
usize, /* desc_size */
18131807
u32, /* version */
18141808
) {
1815-
(
1816-
&self.buf[0..self.map_size],
1817-
self.desc_size,
1818-
MemoryDescriptor::VERSION,
1819-
)
1809+
(self.buf, self.desc_size, MemoryDescriptor::VERSION)
18201810
}
18211811

18221812
/// Mutable version of [`Self::raw`].
@@ -1832,11 +1822,7 @@ impl<'buf> MemoryMap<'buf> {
18321822
usize, /* desc_size */
18331823
u32, /* version */
18341824
) {
1835-
(
1836-
&mut self.buf[0..self.map_size],
1837-
self.desc_size,
1838-
MemoryDescriptor::VERSION,
1839-
)
1825+
(self.buf, self.desc_size, MemoryDescriptor::VERSION)
18401826
}
18411827
}
18421828

0 commit comments

Comments
 (0)