Skip to content

Commit 877e6b7

Browse files
committed
bootservices: add allocate_pool function
1 parent 8904d88 commit 877e6b7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/bootservices.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use void::{NotYetDef, CVoid};
55
use base::{Event, Handle, Handles, MemoryType, Status};
66
use event::{EventType, EventNotify, TimerDelay};
77
use task::TPL;
8-
use protocol::{DevicePathProtocol, Protocol};
8+
use protocol::{DevicePathProtocol, Protocol, get_current_image};
99
use guid;
1010
use table;
1111

@@ -68,6 +68,17 @@ pub struct BootServices {
6868
}
6969

7070
impl BootServices {
71+
/// Allocate `size` bytes of memory using type `T`.
72+
pub fn allocate_pool<T>(&self, size: usize) -> Result<*mut T, Status> {
73+
let mut ptr: *mut u8 = 0 as *mut u8;
74+
75+
let result = unsafe { (self.allocate_pool)(get_current_image().image_data_type, size, &mut ptr) };
76+
if result != Status::Success {
77+
return Err(result);
78+
}
79+
Ok(ptr as *mut T)
80+
}
81+
7182
pub fn free_pool<T>(&self, p: *const T) {
7283
unsafe {
7384
(self.free_pool)(p as *mut CVoid);

0 commit comments

Comments
 (0)