Skip to content

Commit

Permalink
bootservices: add allocate_pool function
Browse files Browse the repository at this point in the history
  • Loading branch information
csssuf committed Jun 15, 2017
1 parent 8904d88 commit 877e6b7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/bootservices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use void::{NotYetDef, CVoid};
use base::{Event, Handle, Handles, MemoryType, Status};
use event::{EventType, EventNotify, TimerDelay};
use task::TPL;
use protocol::{DevicePathProtocol, Protocol};
use protocol::{DevicePathProtocol, Protocol, get_current_image};
use guid;
use table;

Expand Down Expand Up @@ -68,6 +68,17 @@ pub struct BootServices {
}

impl BootServices {
/// Allocate `size` bytes of memory using type `T`.
pub fn allocate_pool<T>(&self, size: usize) -> Result<*mut T, Status> {
let mut ptr: *mut u8 = 0 as *mut u8;

let result = unsafe { (self.allocate_pool)(get_current_image().image_data_type, size, &mut ptr) };
if result != Status::Success {
return Err(result);
}
Ok(ptr as *mut T)
}

pub fn free_pool<T>(&self, p: *const T) {
unsafe {
(self.free_pool)(p as *mut CVoid);
Expand Down

0 comments on commit 877e6b7

Please sign in to comment.