limine_protocol/responses/
memory_map.rs

1use crate::structures::memory_map_entry::MemoryMapEntry;
2
3#[repr(C)]
4#[derive(Debug)]
5/// Response to [`MemoryMapRequest`]
6pub struct MemoryMapResponse {
7    /// The response revision number
8    pub revision: u64,
9    /// The amount of entries in the memory map
10    pub entry_count: u64,
11    /// An array of [MemoryMapEntry] pointers
12    pub entries: *const *const MemoryMapEntry,
13}
14
15impl MemoryMapResponse {
16    /// Get the memory map entry slice
17    ///
18    /// # Safety
19    /// The pointer must point to a valid array of [`MemoryMapEntry`]
20    #[must_use]
21    pub unsafe fn get_memory_map(&self) -> Option<&[&MemoryMapEntry]> {
22        if self.entries.is_null() {
23            return None;
24        }
25        Some(core::slice::from_raw_parts(
26            self.entries.cast::<&MemoryMapEntry>(),
27            self.entry_count.try_into().ok()?,
28        ))
29    }
30}