@@ -77,8 +77,8 @@ struct BootServicesInternal {
77
77
create_event : unsafe extern "efiapi" fn (
78
78
ty : EventType ,
79
79
notify_tpl : Tpl ,
80
- notify_func : Option < EventNotifyFn > ,
81
- notify_ctx : Option < NonNull < c_void > > ,
80
+ notify_func : Option < uefi_raw :: table :: boot :: EventNotifyFn > ,
81
+ notify_ctx : * mut c_void ,
82
82
out_event : * mut uefi_raw:: Event ,
83
83
) -> Status ,
84
84
set_timer :
@@ -234,13 +234,18 @@ struct BootServicesInternal {
234
234
create_event_ex : unsafe extern "efiapi" fn (
235
235
ty : EventType ,
236
236
notify_tpl : Tpl ,
237
- notify_fn : Option < EventNotifyFn > ,
238
- notify_ctx : Option < NonNull < c_void > > ,
239
- event_group : Option < NonNull < Guid > > ,
237
+ notify_fn : Option < uefi_raw :: table :: boot :: EventNotifyFn > ,
238
+ notify_ctx : * mut c_void ,
239
+ event_group : * mut Guid ,
240
240
out_event : * mut uefi_raw:: Event ,
241
241
) -> Status ,
242
242
}
243
243
244
+ /// Get the raw pointer from `opt`, defaulting to `null_mut`.
245
+ fn opt_nonnull_to_ptr < T > ( opt : Option < NonNull < T > > ) -> * mut T {
246
+ opt. map ( NonNull :: as_ptr) . unwrap_or ( ptr:: null_mut ( ) )
247
+ }
248
+
244
249
/// Contains pointers to all of the boot services.
245
250
///
246
251
/// # Accessing `BootServices`
@@ -532,6 +537,12 @@ impl BootServices {
532
537
) -> Result < Event > {
533
538
let mut event = ptr:: null_mut ( ) ;
534
539
540
+ // Safety: the argument types of the function pointers are defined
541
+ // differently, but are compatible and can be safely transmuted.
542
+ let notify_fn: Option < uefi_raw:: table:: boot:: EventNotifyFn > = mem:: transmute ( notify_fn) ;
543
+
544
+ let notify_ctx = opt_nonnull_to_ptr ( notify_ctx) ;
545
+
535
546
// Now we're ready to call UEFI
536
547
( self . 0 . create_event ) ( event_ty, notify_tpl, notify_fn, notify_ctx, & mut event)
537
548
. to_result_with_val (
@@ -593,12 +604,16 @@ impl BootServices {
593
604
594
605
let mut event = ptr:: null_mut ( ) ;
595
606
607
+ // Safety: the argument types of the function pointers are defined
608
+ // differently, but are compatible and can be safely transmuted.
609
+ let notify_fn: Option < uefi_raw:: table:: boot:: EventNotifyFn > = mem:: transmute ( notify_fn) ;
610
+
596
611
( self . 0 . create_event_ex ) (
597
612
event_type,
598
613
notify_tpl,
599
614
notify_fn,
600
- notify_ctx,
601
- event_group,
615
+ opt_nonnull_to_ptr ( notify_ctx) ,
616
+ opt_nonnull_to_ptr ( event_group) ,
602
617
& mut event,
603
618
)
604
619
. to_result_with_val (
0 commit comments