Skip to content

Commit 733855d

Browse files
committed
Change the type of file_path to *const DevicePath
1 parent 4d69a23 commit 733855d

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/proto/loaded_image.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! `LoadedImage` protocol.
22
33
use crate::{
4-
data_types::FromSliceWithNulError, proto::device_path::DevicePath, proto::Protocol,
5-
table::boot::MemoryType, unsafe_guid, CStr16, Char16, Handle, Status,
4+
data_types::FromSliceWithNulError,
5+
proto::{device_path::DevicePath, Protocol},
6+
table::boot::MemoryType,
7+
unsafe_guid, CStr16, Char16, Handle, Status,
68
};
79
use core::{ffi::c_void, mem, slice};
810

@@ -17,7 +19,7 @@ pub struct LoadedImage {
1719

1820
// Source location of the image
1921
device_handle: Handle,
20-
file_path: *const c_void,
22+
file_path: *const DevicePath,
2123
_reserved: *const c_void,
2224

2325
// Image load options
@@ -54,16 +56,20 @@ impl LoadedImage {
5456
}
5557

5658
/// Return a NULL-terminated Path string including directory and file names.
57-
pub fn file_path(&self) -> &CStr16 {
58-
// file_path is a pointer to the file path portion specific to
59-
// DeviceHandle that the EFI Image was loaded from.
60-
let file_path = self.file_path as *const DevicePath;
61-
62-
unsafe {
63-
// path name follows the DevicePathHeader.
64-
let path_name = file_path.offset(1);
65-
CStr16::from_ptr(path_name.cast::<Char16>())
66-
}
59+
///
60+
/// `file_path` is a pointer to the file path portion specific to DeviceHandle
61+
/// that the EFI Image was loaded from. It will be empty if the image is loaded
62+
/// from a buffer and the `file_path` is `None`.
63+
///
64+
/// # Safety
65+
///
66+
/// The callers should guarantee the image is loaded from file. If the image
67+
/// is loaded from a buffer, make sure not passing an incorrect `DevicePath`,
68+
/// which may case an undefined behavior.
69+
pub unsafe fn file_path(&self) -> &CStr16 {
70+
// path name follows the DevicePathHeader.
71+
let path_name = self.file_path.offset(1);
72+
CStr16::from_ptr(path_name.cast::<Char16>())
6773
}
6874

6975
/// Get the load options of the image as a [`&CStr16`].

0 commit comments

Comments
 (0)