Skip to content
This repository was archived by the owner on Sep 22, 2019. It is now read-only.

Commit 8c8dc60

Browse files
committed
lib: add library method for get_memory_map
1 parent 540109c commit 8c8dc60

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod runtimeservices;
1111
mod protocols;
1212
mod console;
1313

14-
pub use base::{Handle, Handles, Event, MemoryType, Status, Time};
14+
pub use base::{Handle, Handles, Event, MemoryType, MemoryDescriptor, Status, Time};
1515
pub use guid::*;
1616

1717
pub use systemtable::*;
@@ -24,6 +24,8 @@ pub use runtimeservices::{ResetType, RuntimeServices};
2424

2525
pub use console::{Attribute, ForegroundColor, BackgroundColor, InputKey, SimpleTextOutput, SimpleTextInput, Console};
2626

27+
use core::mem;
28+
2729
static mut POOL_ALLOCATION_TYPE: base::MemoryType = base::MemoryType::BootServicesData;
2830

2931
pub fn initialize_lib(hdl: &base::Handle, sys: &systemtable::SystemTable) {
@@ -41,3 +43,16 @@ pub fn initialize_lib(hdl: &base::Handle, sys: &systemtable::SystemTable) {
4143
pub fn get_pool_allocation_type() -> base::MemoryType {
4244
unsafe{ POOL_ALLOCATION_TYPE.clone() }
4345
}
46+
47+
// return (memory_map, memory_map_size, map_key, descriptor_size, descriptor_version)
48+
pub fn lib_memory_map() -> (&'static MemoryDescriptor, usize, usize, usize, u32) {
49+
let bs = systemtable::get_system_table().boot_services();
50+
let mut buffer_size: usize = mem::size_of::<MemoryDescriptor>();
51+
52+
loop {
53+
match unsafe { bs.get_memory_map(&mut buffer_size) } {
54+
Ok(val) => return val,
55+
Err(_) => { continue; },
56+
};
57+
}
58+
}

0 commit comments

Comments
 (0)