mod device_path;
pub use self::device_path::DevicePath;
use crate::{
data_types::{CStr16, Char16},
proto::Protocol,
table::boot::MemoryType,
unsafe_guid, Handle, Status,
};
use core::{ffi::c_void, str};
#[repr(C)]
#[unsafe_guid("5b1b31a1-9562-11d2-8e3f-00a0c969723b")]
#[derive(Protocol)]
pub struct LoadedImage {
revision: u32,
parent_handle: Handle,
system_table: *const c_void,
device_handle: Handle,
_file_path: *const c_void, _reserved: *const c_void,
load_options_size: u32,
load_options: *const Char16,
image_base: usize,
image_size: u64,
image_code_type: MemoryType,
image_data_type: MemoryType,
unload: extern "efiapi" fn(image_handle: Handle) -> Status,
}
#[derive(Debug)]
pub enum LoadOptionsError {
BufferTooSmall,
NotValidUtf8,
}
impl LoadedImage {
pub fn device(&self) -> Handle {
self.device_handle
}
pub fn load_options<'a>(&self, buffer: &'a mut [u8]) -> Result<&'a str, LoadOptionsError> {
if self.load_options.is_null() {
Ok("")
} else {
let ucs2_slice = unsafe { CStr16::from_ptr(self.load_options).to_u16_slice() };
let length =
ucs2::decode(ucs2_slice, buffer).map_err(|_| LoadOptionsError::BufferTooSmall)?;
str::from_utf8(&buffer[0..length]).map_err(|_| LoadOptionsError::NotValidUtf8)
}
}
pub fn info(&self) -> (usize, u64) {
(self.image_base, self.image_size)
}
}