1
- use base:: { Handle , MemoryType } ;
1
+ use base:: { Handle , MemoryType , Status } ;
2
2
use guid:: Guid ;
3
3
use void:: NotYetDef ;
4
4
@@ -13,6 +13,8 @@ pub trait Protocol {
13
13
/// GUID for UEFI protocol for loaded images
14
14
pub static EFI_LOADED_IMAGE_PROTOCOL_GUID : Guid = Guid ( 0x5B1B31A1 , 0x9562 , 0x11d2 , [ 0x8E , 0x3F , 0x00 , 0xA0 , 0xC9 , 0x69 , 0x72 , 0x3B ] ) ;
15
15
16
+ static mut THIS_LOADED_IMAGE : * const LoadedImageProtocol = 0 as * const LoadedImageProtocol ;
17
+
16
18
#[ derive( Debug ) ]
17
19
#[ repr( C ) ]
18
20
pub struct LoadedImageProtocol {
@@ -27,7 +29,7 @@ pub struct LoadedImageProtocol {
27
29
pub image_base : usize ,
28
30
pub image_size : u64 ,
29
31
image_code_type : MemoryType ,
30
- image_data_type : MemoryType ,
32
+ pub image_data_type : MemoryType ,
31
33
32
34
//unload: unsafe extern "win64" fn(handle: ::base::Handle),
33
35
unload : * const NotYetDef ,
@@ -39,3 +41,22 @@ impl Protocol for LoadedImageProtocol {
39
41
}
40
42
}
41
43
44
+ pub fn set_current_image ( handle : Handle ) -> Result < & ' static LoadedImageProtocol , Status > {
45
+ let st = :: get_system_table ( ) ;
46
+
47
+ let loaded_image_proto: Result < & ' static LoadedImageProtocol , Status > = st. boot_services ( ) . handle_protocol ( handle) ;
48
+ if let Ok ( image) = loaded_image_proto {
49
+ unsafe {
50
+ THIS_LOADED_IMAGE = image;
51
+ }
52
+ }
53
+
54
+ loaded_image_proto
55
+ }
56
+
57
+ pub fn get_current_image ( ) -> & ' static LoadedImageProtocol {
58
+ unsafe {
59
+ & * THIS_LOADED_IMAGE
60
+ }
61
+ }
62
+
0 commit comments