mirror of
https://github.com/rust-osdev/uefi-rs
synced 2026-08-26 18:26:05 -04:00
uefi: initialize memory map buffer
This is much easier than handling of `MaybeUninit` with casting things around, and the performance overhead is negligible.
This commit is contained in:
parent
68b5782ad5
commit
73acd67ade
1 changed files with 8 additions and 0 deletions
|
|
@ -281,6 +281,12 @@ impl MemoryMapBackingMemory {
|
|||
let memory_map_meta = boot::memory_map_size();
|
||||
let len = Self::safe_allocation_size_hint(memory_map_meta);
|
||||
let ptr = boot::allocate_pool(memory_type, len)?.as_ptr();
|
||||
// Initialize all bytes.
|
||||
//
|
||||
// SAFETY: Pointer is valid.
|
||||
unsafe {
|
||||
ptr.write_bytes(0, len);
|
||||
};
|
||||
|
||||
// Should be fine as UEFI always has allocations with a guaranteed
|
||||
// alignment of 8 bytes.
|
||||
|
|
@ -329,12 +335,14 @@ impl MemoryMapBackingMemory {
|
|||
/// Returns a slice to the underlying memory.
|
||||
#[must_use]
|
||||
pub const fn as_slice(&self) -> &[u8] {
|
||||
// SAFETY: Memory is valid and initialized.
|
||||
unsafe { self.0.as_ref() }
|
||||
}
|
||||
|
||||
/// Returns a mutable slice to the underlying memory.
|
||||
#[must_use]
|
||||
pub const fn as_mut_slice(&mut self) -> &mut [u8] {
|
||||
// SAFETY: Memory is valid and initialized.
|
||||
unsafe { self.0.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue