Skip to content

Commit 6981536

Browse files
committed
bootservices: Add load_image and start_image
Implement Rust interfaces for LoadImage and StartImage, including variants for each based on optional inputs/outputs.
1 parent 5d4be56 commit 6981536

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

src/bootservices.rs

Lines changed: 43 additions & 3 deletions
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::Protocol;
8+
use protocol::{DevicePathProtocol, Protocol};
99
use guid;
1010
use table;
1111

@@ -43,8 +43,8 @@ pub struct BootServices {
4343
locate_handle: *const NotYetDef,
4444
locate_device_path: *const NotYetDef,
4545
install_configuration_table: *const NotYetDef,
46-
load_image: *const NotYetDef,
47-
start_image: *const NotYetDef,
46+
load_image: unsafe extern "win64" fn(boot_policy: u8, parent_image_handle: Handle, device_path: *const DevicePathProtocol, source_buffer: *const CVoid, source_size: usize, image_handle: *mut Handle) -> Status,
47+
start_image: unsafe extern "win64" fn(image_handle: Handle, exit_data_size: *mut usize, exit_data: *mut *const u16) -> Status,
4848
exit: *const NotYetDef,
4949
unload_image: *const NotYetDef,
5050
exit_boot_services: *const NotYetDef,
@@ -148,6 +148,46 @@ impl BootServices {
148148
return Ok(Handles::new(handles as *mut Handle, nhandles));
149149
}
150150

151+
/// Load an image by device path and return its handle.
152+
pub fn load_image(&self, boot_policy: bool, parent_image_handle: Handle, device_path: *const DevicePathProtocol) -> Result<Handle, Status> {
153+
self.load_image_buffer(boot_policy, parent_image_handle, device_path, 0 as *const CVoid, 0)
154+
}
155+
156+
/// Load an image already loaded into memory at source_buffer and return its handle.
157+
pub fn load_image_buffer(&self, boot_policy: bool, parent_image_handle: Handle, device_path: *const DevicePathProtocol, source_buffer: *const CVoid, source_size: usize) -> Result<Handle, Status> {
158+
let mut handle: Handle = Default::default();
159+
160+
let result = unsafe { (self.load_image)(boot_policy as u8, parent_image_handle, device_path, source_buffer, source_size, &mut handle) };
161+
if result != Status::Success {
162+
return Err(result);
163+
}
164+
165+
Ok(handle)
166+
}
167+
168+
/// Start a loaded image, and return its ExitData.
169+
pub fn start_image_with_exitdata(&self, image_handle: Handle) -> Result<(*const u16, usize), Status> {
170+
let mut exit_data_ptr: *const u16 = 0 as *const u16;
171+
let mut exit_data_size: usize = 0;
172+
173+
let result = unsafe { (self.start_image)(image_handle, &mut exit_data_size, &mut exit_data_ptr) };
174+
if result != Status::Success {
175+
return Err(result);
176+
}
177+
178+
Ok((exit_data_ptr, exit_data_size))
179+
}
180+
181+
/// Start a loaded image, but ignore its ExitData.
182+
pub fn start_image(&self, image_handle: Handle) -> Result<(), Status> {
183+
let result = unsafe { (self.start_image)(image_handle, 0 as *mut usize, 0 as *mut *const u16) };
184+
if result != Status::Success {
185+
return Err(result);
186+
}
187+
188+
Ok(())
189+
}
190+
151191
/// Sleep for a number of microseconds.
152192
pub fn stall(&self, microseconds: usize) {
153193
unsafe {

0 commit comments

Comments
 (0)