Skip to content

Commit 7a3a10c

Browse files
uefi: BootServices: Make create_event/create_event_ex compatible with uefi_raw
1 parent 3ccdf54 commit 7a3a10c

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

uefi/src/table/boot.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ struct BootServicesInternal {
7777
create_event: unsafe extern "efiapi" fn(
7878
ty: EventType,
7979
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,
8282
out_event: *mut uefi_raw::Event,
8383
) -> Status,
8484
set_timer:
@@ -234,13 +234,18 @@ struct BootServicesInternal {
234234
create_event_ex: unsafe extern "efiapi" fn(
235235
ty: EventType,
236236
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,
240240
out_event: *mut uefi_raw::Event,
241241
) -> Status,
242242
}
243243

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+
244249
/// Contains pointers to all of the boot services.
245250
///
246251
/// # Accessing `BootServices`
@@ -532,6 +537,12 @@ impl BootServices {
532537
) -> Result<Event> {
533538
let mut event = ptr::null_mut();
534539

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+
535546
// Now we're ready to call UEFI
536547
(self.0.create_event)(event_ty, notify_tpl, notify_fn, notify_ctx, &mut event)
537548
.to_result_with_val(
@@ -593,12 +604,16 @@ impl BootServices {
593604

594605
let mut event = ptr::null_mut();
595606

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+
596611
(self.0.create_event_ex)(
597612
event_type,
598613
notify_tpl,
599614
notify_fn,
600-
notify_ctx,
601-
event_group,
615+
opt_nonnull_to_ptr(notify_ctx),
616+
opt_nonnull_to_ptr(event_group),
602617
&mut event,
603618
)
604619
.to_result_with_val(

0 commit comments

Comments
 (0)