1
1
//! UEFI services available during boot.
2
2
3
3
use super :: { Header , Revision } ;
4
- use crate :: data_types:: { Align , PhysicalAddress , SearchKey , VirtualAddress } ;
4
+ use crate :: data_types:: { Align , PhysicalAddress , VirtualAddress } ;
5
5
use crate :: proto:: device_path:: { DevicePath , FfiDevicePath } ;
6
6
#[ cfg( feature = "exts" ) ]
7
7
use crate :: proto:: { loaded_image:: LoadedImage , media:: fs:: SimpleFileSystem } ;
@@ -129,31 +129,34 @@ pub struct BootServices {
129
129
130
130
// Protocol handlers
131
131
install_protocol_interface : unsafe extern "efiapi" fn (
132
- handle : NonNull < Option < Handle > > ,
132
+ handle : & mut Option < Handle > ,
133
133
guid : & Guid ,
134
134
interface_type : InterfaceType ,
135
- interface : Option < NonNull < c_void > > ,
135
+ interface : * mut c_void ,
136
136
) -> Status ,
137
137
reinstall_protocol_interface : unsafe extern "efiapi" fn (
138
138
handle : Handle ,
139
139
protocol : & Guid ,
140
- old_interface : Option < NonNull < c_void > > ,
141
- new_interface : Option < NonNull < c_void > > ,
140
+ old_interface : * mut c_void ,
141
+ new_interface : * mut c_void ,
142
142
) -> Status ,
143
143
uninstall_protocol_interface : unsafe extern "efiapi" fn (
144
144
handle : Handle ,
145
145
protocol : & Guid ,
146
- interface : Option < NonNull < c_void > > ,
146
+ interface : * mut c_void ,
147
147
) -> Status ,
148
148
handle_protocol :
149
149
extern "efiapi" fn ( handle : Handle , proto : & Guid , out_proto : & mut * mut c_void ) -> Status ,
150
150
_reserved : usize ,
151
- register_protocol_notify :
152
- extern "efiapi" fn ( protocol : & Guid , event : Event , registration : * mut SearchKey ) -> Status ,
151
+ register_protocol_notify : extern "efiapi" fn (
152
+ protocol : & Guid ,
153
+ event : Event ,
154
+ registration : * mut ProtocolSearchKey ,
155
+ ) -> Status ,
153
156
locate_handle : unsafe extern "efiapi" fn (
154
157
search_ty : i32 ,
155
158
proto : Option < & Guid > ,
156
- key : Option < SearchKey > ,
159
+ key : Option < ProtocolSearchKey > ,
157
160
buf_sz : & mut usize ,
158
161
buf : * mut MaybeUninit < Handle > ,
159
162
) -> Status ,
@@ -237,7 +240,7 @@ pub struct BootServices {
237
240
locate_handle_buffer : unsafe extern "efiapi" fn (
238
241
search_ty : i32 ,
239
242
proto : Option < & Guid > ,
240
- key : Option < SearchKey > ,
243
+ key : Option < ProtocolSearchKey > ,
241
244
no_handles : & mut usize ,
242
245
buf : & mut * mut Handle ,
243
246
) -> Status ,
@@ -634,7 +637,7 @@ impl BootServices {
634
637
}
635
638
636
639
/// Installs a protocol interface on a device handle. If the inner `Option` in `handle` is `None`,
637
- /// one will be created and added to the list of handles in the system and then returned."
640
+ /// one will be created and added to the list of handles in the system and then returned.
638
641
///
639
642
/// When a protocol interface is installed, firmware will call all functions that have registered
640
643
/// to wait for that interface to be installed.
@@ -646,14 +649,10 @@ impl BootServices {
646
649
& self ,
647
650
mut handle : Option < Handle > ,
648
651
protocol : & Guid ,
649
- interface : Option < NonNull < c_void > > ,
652
+ interface : * mut c_void ,
650
653
) -> Result < Handle > {
651
- // Safety: The given pointer is guaranteed to be non-null, even though what it's indirectly pointing to
652
- // may be null, thus this is safe
653
- let handle_ptr = NonNull :: new ( & mut handle as * mut _ ) . unwrap_unchecked ( ) ;
654
-
655
654
( ( self . install_protocol_interface ) (
656
- handle_ptr ,
655
+ & mut handle ,
657
656
protocol,
658
657
InterfaceType :: NATIVE_INTERFACE ,
659
658
interface,
@@ -678,8 +677,8 @@ impl BootServices {
678
677
& self ,
679
678
handle : Handle ,
680
679
protocol : & Guid ,
681
- old_interface : Option < NonNull < c_void > > ,
682
- new_interface : Option < NonNull < c_void > > ,
680
+ old_interface : * mut c_void ,
681
+ new_interface : * mut c_void ,
683
682
) -> Result < ( ) > {
684
683
( self . reinstall_protocol_interface ) ( handle, protocol, old_interface, new_interface) . into ( )
685
684
}
@@ -698,7 +697,7 @@ impl BootServices {
698
697
& self ,
699
698
handle : Handle ,
700
699
protocol : & Guid ,
701
- interface : Option < NonNull < c_void > > ,
700
+ interface : * mut c_void ,
702
701
) -> Result < ( ) > {
703
702
( self . uninstall_protocol_interface ) ( handle, protocol, interface) . into ( )
704
703
}
@@ -752,12 +751,17 @@ impl BootServices {
752
751
& self ,
753
752
protocol : & Guid ,
754
753
event : Event ,
755
- ) -> Result < ( Event , SearchKey ) > {
756
- let mut key: MaybeUninit < SearchKey > = MaybeUninit :: uninit ( ) ;
754
+ ) -> Result < ( Event , SearchType ) > {
755
+ let mut key: MaybeUninit < ProtocolSearchKey > = MaybeUninit :: uninit ( ) ;
757
756
// Safety: we clone `event` a couple times, but there will be only one left once we return.
758
757
unsafe { ( self . register_protocol_notify ) ( protocol, event. unsafe_clone ( ) , key. as_mut_ptr ( ) ) }
759
758
// Safety: as long as this call is successful, `key` will be valid.
760
- . into_with_val ( || unsafe { ( event. unsafe_clone ( ) , key. assume_init ( ) ) } )
759
+ . into_with_val ( || unsafe {
760
+ (
761
+ event. unsafe_clone ( ) ,
762
+ SearchType :: ByRegisterNotify ( key. assume_init ( ) ) ,
763
+ )
764
+ } )
761
765
}
762
766
763
767
/// Enumerates all handles installed on the system which match a certain query.
@@ -1840,7 +1844,7 @@ pub enum SearchType<'guid> {
1840
1844
ByProtocol ( & ' guid Guid ) ,
1841
1845
/// Return all handles that implement a protocol when an interface for that protocol
1842
1846
/// is (re)installed.
1843
- ByRegisterNotify ( SearchKey ) ,
1847
+ ByRegisterNotify ( ProtocolSearchKey ) ,
1844
1848
}
1845
1849
1846
1850
impl < ' guid > SearchType < ' guid > {
@@ -1850,13 +1854,6 @@ impl<'guid> SearchType<'guid> {
1850
1854
}
1851
1855
}
1852
1856
1853
- impl SearchType < ' _ > {
1854
- /// Constructs a new search type from a SearchKey.
1855
- pub fn from_search_key ( key : SearchKey ) -> Self {
1856
- SearchType :: ByRegisterNotify ( key)
1857
- }
1858
- }
1859
-
1860
1857
bitflags ! {
1861
1858
/// Flags describing the type of an UEFI event and its attributes.
1862
1859
pub struct EventType : u32 {
@@ -1970,3 +1967,9 @@ pub enum InterfaceType: i32 => {
1970
1967
NATIVE_INTERFACE = 0 ,
1971
1968
}
1972
1969
}
1970
+
1971
+ /// Opaque pointer returned by [`BootServices::register_protocol_notify`] to be used
1972
+ /// with [`BootServices::locate_handle`] via [`SearchType::ByRegisterNotify`].
1973
+ #[ derive( Debug , Clone , Copy ) ]
1974
+ #[ repr( transparent) ]
1975
+ pub struct ProtocolSearchKey ( NonNull < c_void > ) ;
0 commit comments