@@ -122,7 +122,7 @@ pub struct BootServices {
122
122
notify_tpl : Tpl ,
123
123
notify_func : Option < EventNotifyFn > ,
124
124
notify_ctx : Option < NonNull < c_void > > ,
125
- out_event : * mut Event ,
125
+ out_event : * mut Option < Event > ,
126
126
) -> Status ,
127
127
set_timer : unsafe extern "efiapi" fn ( event : Event , ty : u32 , trigger_time : u64 ) -> Status ,
128
128
wait_for_event : unsafe extern "efiapi" fn (
@@ -159,7 +159,7 @@ pub struct BootServices {
159
159
register_protocol_notify : extern "efiapi" fn (
160
160
protocol : & Guid ,
161
161
event : Event ,
162
- registration : * mut ProtocolSearchKey ,
162
+ registration : * mut Option < ProtocolSearchKey > ,
163
163
) -> Status ,
164
164
locate_handle : unsafe extern "efiapi" fn (
165
165
search_ty : i32 ,
@@ -171,7 +171,7 @@ pub struct BootServices {
171
171
locate_device_path : unsafe extern "efiapi" fn (
172
172
proto : & Guid ,
173
173
device_path : & mut * const FfiDevicePath ,
174
- out_handle : & mut MaybeUninit < Handle > ,
174
+ out_handle : & mut Option < Handle > ,
175
175
) -> Status ,
176
176
install_configuration_table :
177
177
extern "efiapi" fn ( guid_entry : & Guid , table_ptr : * const c_void ) -> Status ,
@@ -183,7 +183,7 @@ pub struct BootServices {
183
183
device_path : * const FfiDevicePath ,
184
184
source_buffer : * const u8 ,
185
185
source_size : usize ,
186
- image_handle : & mut MaybeUninit < Handle > ,
186
+ image_handle : & mut Option < Handle > ,
187
187
) -> Status ,
188
188
start_image : unsafe extern "efiapi" fn (
189
189
image_handle : Handle ,
@@ -276,7 +276,7 @@ pub struct BootServices {
276
276
notify_fn : Option < EventNotifyFn > ,
277
277
notify_ctx : Option < NonNull < c_void > > ,
278
278
event_group : Option < NonNull < Guid > > ,
279
- out_event : * mut Event ,
279
+ out_event : * mut Option < Event > ,
280
280
) -> Status ,
281
281
}
282
282
@@ -519,18 +519,14 @@ impl BootServices {
519
519
notify_fn : Option < EventNotifyFn > ,
520
520
notify_ctx : Option < NonNull < c_void > > ,
521
521
) -> Result < Event > {
522
- // Prepare storage for the output Event
523
- let mut event = MaybeUninit :: < Event > :: uninit ( ) ;
522
+ let mut event = None ;
524
523
525
524
// Now we're ready to call UEFI
526
- ( self . create_event ) (
527
- event_ty,
528
- notify_tpl,
529
- notify_fn,
530
- notify_ctx,
531
- event. as_mut_ptr ( ) ,
532
- )
533
- . to_result_with_val ( || event. assume_init ( ) )
525
+ ( self . create_event ) ( event_ty, notify_tpl, notify_fn, notify_ctx, & mut event)
526
+ . to_result_with_val (
527
+ // OK to unwrap: event is non-null for Status::SUCCESS.
528
+ || event. unwrap ( ) ,
529
+ )
534
530
}
535
531
536
532
/// Creates a new `Event` of type `event_type`. The event's notification function, context,
@@ -584,17 +580,20 @@ impl BootServices {
584
580
return Err ( Status :: UNSUPPORTED . into ( ) ) ;
585
581
}
586
582
587
- let mut event = MaybeUninit :: < Event > :: uninit ( ) ;
583
+ let mut event = None ;
588
584
589
585
( self . create_event_ex ) (
590
586
event_type,
591
587
notify_tpl,
592
588
notify_fn,
593
589
notify_ctx,
594
590
event_group,
595
- event. as_mut_ptr ( ) ,
591
+ & mut event,
592
+ )
593
+ . to_result_with_val (
594
+ // OK to unwrap: event is non-null for Status::SUCCESS.
595
+ || event. unwrap ( ) ,
596
596
)
597
- . to_result_with_val ( || event. assume_init ( ) )
598
597
}
599
598
600
599
/// Sets the trigger for `EventType::TIMER` event.
@@ -649,18 +648,17 @@ impl BootServices {
649
648
/// * [`uefi::Status::UNSUPPORTED`]
650
649
pub fn wait_for_event ( & self , events : & mut [ Event ] ) -> Result < usize , Option < usize > > {
651
650
let ( number_of_events, events) = ( events. len ( ) , events. as_mut_ptr ( ) ) ;
652
- let mut index = MaybeUninit :: < usize > :: uninit ( ) ;
653
- unsafe { ( self . wait_for_event ) ( number_of_events, events, index. as_mut_ptr ( ) ) }
654
- . to_result_with (
655
- || unsafe { index. assume_init ( ) } ,
656
- |s| {
657
- if s == Status :: INVALID_PARAMETER {
658
- unsafe { Some ( index. assume_init ( ) ) }
659
- } else {
660
- None
661
- }
662
- } ,
663
- )
651
+ let mut index = 0 ;
652
+ unsafe { ( self . wait_for_event ) ( number_of_events, events, & mut index) } . to_result_with (
653
+ || index,
654
+ |s| {
655
+ if s == Status :: INVALID_PARAMETER {
656
+ Some ( index)
657
+ } else {
658
+ None
659
+ }
660
+ } ,
661
+ )
664
662
}
665
663
666
664
/// Place 'event' in the signaled stated. If 'event' is already in the signaled state,
@@ -839,14 +837,15 @@ impl BootServices {
839
837
protocol : & Guid ,
840
838
event : Event ,
841
839
) -> Result < ( Event , SearchType ) > {
842
- let mut key: MaybeUninit < ProtocolSearchKey > = MaybeUninit :: uninit ( ) ;
840
+ let mut key = None ;
843
841
// Safety: we clone `event` a couple times, but there will be only one left once we return.
844
- unsafe { ( self . register_protocol_notify ) ( protocol, event. unsafe_clone ( ) , key. as_mut_ptr ( ) ) }
842
+ unsafe { ( self . register_protocol_notify ) ( protocol, event. unsafe_clone ( ) , & mut key) }
845
843
// Safety: as long as this call is successful, `key` will be valid.
846
844
. to_result_with_val ( || unsafe {
847
845
(
848
846
event. unsafe_clone ( ) ,
849
- SearchType :: ByRegisterNotify ( key. assume_init ( ) ) ,
847
+ // OK to unwrap: key is non-null for Status::SUCCESS.
848
+ SearchType :: ByRegisterNotify ( key. unwrap ( ) ) ,
850
849
)
851
850
} )
852
851
}
@@ -918,13 +917,14 @@ impl BootServices {
918
917
& self ,
919
918
device_path : & mut & DevicePath ,
920
919
) -> Result < Handle > {
921
- let mut handle = MaybeUninit :: uninit ( ) ;
920
+ let mut handle = None ;
922
921
let mut device_path_ptr = device_path. as_ffi_ptr ( ) ;
923
922
unsafe {
924
923
( self . locate_device_path ) ( & P :: GUID , & mut device_path_ptr, & mut handle)
925
924
. to_result_with_val ( || {
926
925
* device_path = DevicePath :: from_ffi_ptr ( device_path_ptr) ;
927
- handle. assume_init ( )
926
+ // OK to unwrap: handle is non-null for Status::SUCCESS.
927
+ handle. unwrap ( )
928
928
} )
929
929
}
930
930
}
@@ -1037,7 +1037,7 @@ impl BootServices {
1037
1037
}
1038
1038
} ;
1039
1039
1040
- let mut image_handle = MaybeUninit :: uninit ( ) ;
1040
+ let mut image_handle = None ;
1041
1041
unsafe {
1042
1042
( self . load_image ) (
1043
1043
boot_policy,
@@ -1047,7 +1047,10 @@ impl BootServices {
1047
1047
source_size,
1048
1048
& mut image_handle,
1049
1049
)
1050
- . to_result_with_val ( || image_handle. assume_init ( ) )
1050
+ . to_result_with_val (
1051
+ // OK to unwrap: image handle is non-null for Status::SUCCESS.
1052
+ || image_handle. unwrap ( ) ,
1053
+ )
1051
1054
}
1052
1055
}
1053
1056
0 commit comments