1
1
//! `LoadedImage` protocol.
2
2
3
3
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 ,
6
8
} ;
7
9
use core:: { ffi:: c_void, mem, slice} ;
8
10
@@ -17,7 +19,7 @@ pub struct LoadedImage {
17
19
18
20
// Source location of the image
19
21
device_handle : Handle ,
20
- file_path : * const c_void ,
22
+ file_path : * const DevicePath ,
21
23
_reserved : * const c_void ,
22
24
23
25
// Image load options
@@ -54,16 +56,20 @@ impl LoadedImage {
54
56
}
55
57
56
58
/// 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 > ( ) )
67
73
}
68
74
69
75
/// Get the load options of the image as a [`&CStr16`].
0 commit comments