Skip to content

Commit 7f456f4

Browse files
Add LoadedImageDevicePath protocol
This protocol is the same as `DevicePath`, but only available on image handles.
1 parent 98670a3 commit 7f456f4

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

uefi-test-runner/src/proto/device_path.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use uefi::prelude::*;
22
use uefi::proto::device_path::text::*;
3-
use uefi::proto::device_path::DevicePath;
3+
use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath};
44
use uefi::proto::loaded_image::LoadedImage;
55
use uefi::table::boot::BootServices;
66

@@ -48,4 +48,16 @@ pub fn test(image: Handle, bt: &BootServices) {
4848
.expect("Failed to convert text to device path");
4949
assert_eq!(path, convert);
5050
}
51+
52+
// Get the `LoadedImageDevicePath`. Verify it start with the same nodes as
53+
// `device_path`.
54+
let loaded_image_device_path = bt
55+
.open_protocol_exclusive::<LoadedImageDevicePath>(image)
56+
.expect("Failed to open LoadedImageDevicePath protocol");
57+
for (n1, n2) in device_path
58+
.node_iter()
59+
.zip(loaded_image_device_path.node_iter())
60+
{
61+
assert_eq!(n1, n2);
62+
}
5163
}

uefi/src/proto/device_path/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ use crate::proto::{unsafe_protocol, ProtocolPointer};
8585
use core::ffi::c_void;
8686
use core::fmt::{self, Debug, Formatter};
8787
use core::mem;
88+
use core::ops::Deref;
8889
use ptr_meta::Pointee;
8990

9091
opaque_type! {
@@ -610,6 +611,35 @@ pub enum NodeConversionError {
610611
UnsupportedType,
611612
}
612613

614+
/// Protocol for accessing the device path that was passed in to [`load_image`]
615+
/// when loading a PE/COFF image.
616+
///
617+
/// The layout of this type is the same as a [`DevicePath`].
618+
///
619+
/// [`load_image`]: crate::table::boot::BootServices::load_image
620+
#[repr(transparent)]
621+
#[unsafe_protocol("bc62157e-3e33-4fec-9920-2d3b36d750df")]
622+
#[derive(Pointee)]
623+
pub struct LoadedImageDevicePath(DevicePath);
624+
625+
impl ProtocolPointer for LoadedImageDevicePath {
626+
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
627+
ptr_meta::from_raw_parts(ptr.cast(), DevicePath::size_in_bytes_from_ptr(ptr))
628+
}
629+
630+
unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
631+
ptr_meta::from_raw_parts_mut(ptr.cast(), DevicePath::size_in_bytes_from_ptr(ptr))
632+
}
633+
}
634+
635+
impl Deref for LoadedImageDevicePath {
636+
type Target = DevicePath;
637+
638+
fn deref(&self) -> &DevicePath {
639+
&self.0
640+
}
641+
}
642+
613643
#[cfg(test)]
614644
mod tests {
615645
use super::*;

uefi/src/table/boot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,10 +986,11 @@ impl BootServices {
986986
/// image.
987987
///
988988
/// If the image is successfully loaded, a [`Handle`] supporting the
989-
/// [`LoadedImage`] and `LoadedImageDevicePath` protocols is
989+
/// [`LoadedImage`] and [`LoadedImageDevicePath`] protocols is
990990
/// returned. The image can be started with [`start_image`] or
991991
/// unloaded with [`unload_image`].
992992
///
993+
/// [`LoadedImageDevicePath`]: crate::proto::device_path::LoadedImageDevicePath
993994
/// [`start_image`]: BootServices::start_image
994995
/// [`unload_image`]: BootServices::unload_image
995996
///

0 commit comments

Comments
 (0)