10
10
11
11
use crate :: proto:: device_path:: { DevicePath , DevicePathNode } ;
12
12
use crate :: proto:: unsafe_protocol;
13
- use crate :: { boot, CStr16 , Char16 , Result , Status } ;
13
+ use crate :: table:: boot:: BootServices ;
14
+ use crate :: { CStr16 , Char16 , Result , Status } ;
14
15
use core:: ops:: Deref ;
15
- use core:: ptr:: NonNull ;
16
16
use uefi_raw:: protocol:: device_path:: { DevicePathFromTextProtocol , DevicePathToTextProtocol } ;
17
17
18
18
/// This struct is a wrapper of `display_only` parameter
@@ -42,27 +42,36 @@ pub struct AllowShortcuts(pub bool);
42
42
/// Wrapper for a string internally allocated from
43
43
/// UEFI boot services memory.
44
44
#[ derive( Debug ) ]
45
- pub struct PoolString ( NonNull < Char16 > ) ;
45
+ pub struct PoolString < ' a > {
46
+ boot_services : & ' a BootServices ,
47
+ text : * const Char16 ,
48
+ }
46
49
47
- impl PoolString {
48
- fn new ( text : * const Char16 ) -> Result < Self > {
49
- NonNull :: new ( text. cast_mut ( ) )
50
- . map ( Self )
51
- . ok_or ( Status :: OUT_OF_RESOURCES . into ( ) )
50
+ impl < ' a > PoolString < ' a > {
51
+ fn new ( boot_services : & ' a BootServices , text : * const Char16 ) -> Result < Self > {
52
+ if text. is_null ( ) {
53
+ Err ( Status :: OUT_OF_RESOURCES . into ( ) )
54
+ } else {
55
+ Ok ( Self {
56
+ boot_services,
57
+ text,
58
+ } )
59
+ }
52
60
}
53
61
}
54
62
55
- impl Deref for PoolString {
63
+ impl < ' a > Deref for PoolString < ' a > {
56
64
type Target = CStr16 ;
57
65
58
66
fn deref ( & self ) -> & Self :: Target {
59
- unsafe { CStr16 :: from_ptr ( self . 0 . as_ptr ( ) ) }
67
+ unsafe { CStr16 :: from_ptr ( self . text ) }
60
68
}
61
69
}
62
70
63
- impl Drop for PoolString {
71
+ impl Drop for PoolString < ' _ > {
64
72
fn drop ( & mut self ) {
65
- unsafe { boot:: free_pool ( self . 0 . cast ( ) ) } . expect ( "Failed to free pool [{addr:#?}]" ) ;
73
+ let addr = self . text as * mut u8 ;
74
+ unsafe { self . boot_services . free_pool ( addr) } . expect ( "Failed to free pool [{addr:#?}]" ) ;
66
75
}
67
76
}
68
77
@@ -82,20 +91,21 @@ impl DevicePathToText {
82
91
/// memory for the conversion.
83
92
///
84
93
/// [`OUT_OF_RESOURCES`]: Status::OUT_OF_RESOURCES
85
- pub fn convert_device_node_to_text (
94
+ pub fn convert_device_node_to_text < ' boot > (
86
95
& self ,
96
+ boot_services : & ' boot BootServices ,
87
97
device_node : & DevicePathNode ,
88
98
display_only : DisplayOnly ,
89
99
allow_shortcuts : AllowShortcuts ,
90
- ) -> Result < PoolString > {
100
+ ) -> Result < PoolString < ' boot > > {
91
101
let text_device_node = unsafe {
92
102
( self . 0 . convert_device_node_to_text ) (
93
103
device_node. as_ffi_ptr ( ) . cast ( ) ,
94
104
display_only. 0 ,
95
105
allow_shortcuts. 0 ,
96
106
)
97
107
} ;
98
- PoolString :: new ( text_device_node. cast ( ) )
108
+ PoolString :: new ( boot_services , text_device_node. cast ( ) )
99
109
}
100
110
101
111
/// Convert a device path to its text representation.
@@ -104,20 +114,21 @@ impl DevicePathToText {
104
114
/// memory for the conversion.
105
115
///
106
116
/// [`OUT_OF_RESOURCES`]: Status::OUT_OF_RESOURCES
107
- pub fn convert_device_path_to_text (
117
+ pub fn convert_device_path_to_text < ' boot > (
108
118
& self ,
119
+ boot_services : & ' boot BootServices ,
109
120
device_path : & DevicePath ,
110
121
display_only : DisplayOnly ,
111
122
allow_shortcuts : AllowShortcuts ,
112
- ) -> Result < PoolString > {
123
+ ) -> Result < PoolString < ' boot > > {
113
124
let text_device_path = unsafe {
114
125
( self . 0 . convert_device_path_to_text ) (
115
126
device_path. as_ffi_ptr ( ) . cast ( ) ,
116
127
display_only. 0 ,
117
128
allow_shortcuts. 0 ,
118
129
)
119
130
} ;
120
- PoolString :: new ( text_device_path. cast ( ) )
131
+ PoolString :: new ( boot_services , text_device_path. cast ( ) )
121
132
}
122
133
}
123
134
0 commit comments