1010
1111use crate :: proto:: device_path:: { DevicePath , DevicePathNode } ;
1212use 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 } ;
1514use core:: ops:: Deref ;
15+ use core:: ptr:: NonNull ;
1616use uefi_raw:: protocol:: device_path:: { DevicePathFromTextProtocol , DevicePathToTextProtocol } ;
1717
1818/// This struct is a wrapper of `display_only` parameter
@@ -42,36 +42,27 @@ pub struct AllowShortcuts(pub bool);
4242/// Wrapper for a string internally allocated from
4343/// UEFI boot services memory.
4444#[ derive( Debug ) ]
45- pub struct PoolString < ' a > {
46- boot_services : & ' a BootServices ,
47- text : * const Char16 ,
48- }
45+ pub struct PoolString ( NonNull < Char16 > ) ;
4946
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 ( ) )
6052 }
6153}
6254
63- impl < ' a > Deref for PoolString < ' a > {
55+ impl Deref for PoolString {
6456 type Target = CStr16 ;
6557
6658 fn deref ( & self ) -> & Self :: Target {
67- unsafe { CStr16 :: from_ptr ( self . text ) }
59+ unsafe { CStr16 :: from_ptr ( self . 0 . as_ptr ( ) ) }
6860 }
6961}
7062
71- impl Drop for PoolString < ' _ > {
63+ impl Drop for PoolString {
7264 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:#?}]" ) ;
7566 }
7667}
7768
@@ -91,21 +82,20 @@ impl DevicePathToText {
9182 /// memory for the conversion.
9283 ///
9384 /// [`OUT_OF_RESOURCES`]: Status::OUT_OF_RESOURCES
94- pub fn convert_device_node_to_text < ' boot > (
85+ pub fn convert_device_node_to_text (
9586 & self ,
96- boot_services : & ' boot BootServices ,
9787 device_node : & DevicePathNode ,
9888 display_only : DisplayOnly ,
9989 allow_shortcuts : AllowShortcuts ,
100- ) -> Result < PoolString < ' boot > > {
90+ ) -> Result < PoolString > {
10191 let text_device_node = unsafe {
10292 ( self . 0 . convert_device_node_to_text ) (
10393 device_node. as_ffi_ptr ( ) . cast ( ) ,
10494 display_only. 0 ,
10595 allow_shortcuts. 0 ,
10696 )
10797 } ;
108- PoolString :: new ( boot_services , text_device_node. cast ( ) )
98+ PoolString :: new ( text_device_node. cast ( ) )
10999 }
110100
111101 /// Convert a device path to its text representation.
@@ -114,21 +104,20 @@ impl DevicePathToText {
114104 /// memory for the conversion.
115105 ///
116106 /// [`OUT_OF_RESOURCES`]: Status::OUT_OF_RESOURCES
117- pub fn convert_device_path_to_text < ' boot > (
107+ pub fn convert_device_path_to_text (
118108 & self ,
119- boot_services : & ' boot BootServices ,
120109 device_path : & DevicePath ,
121110 display_only : DisplayOnly ,
122111 allow_shortcuts : AllowShortcuts ,
123- ) -> Result < PoolString < ' boot > > {
112+ ) -> Result < PoolString > {
124113 let text_device_path = unsafe {
125114 ( self . 0 . convert_device_path_to_text ) (
126115 device_path. as_ffi_ptr ( ) . cast ( ) ,
127116 display_only. 0 ,
128117 allow_shortcuts. 0 ,
129118 )
130119 } ;
131- PoolString :: new ( boot_services , text_device_path. cast ( ) )
120+ PoolString :: new ( text_device_path. cast ( ) )
132121 }
133122}
134123
0 commit comments