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