Skip to content

Commit c70bce2

Browse files
uefi: BootServices: Make event args compatible with uefi_raw
1 parent cacef00 commit c70bce2

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

uefi/src/table/boot.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,18 @@ struct BootServicesInternal {
7979
notify_tpl: Tpl,
8080
notify_func: Option<EventNotifyFn>,
8181
notify_ctx: Option<NonNull<c_void>>,
82-
out_event: *mut Option<Event>,
82+
out_event: *mut uefi_raw::Event,
8383
) -> Status,
84-
set_timer: unsafe extern "efiapi" fn(event: Event, ty: u32, trigger_time: u64) -> Status,
84+
set_timer:
85+
unsafe extern "efiapi" fn(event: uefi_raw::Event, ty: u32, trigger_time: u64) -> Status,
8586
wait_for_event: unsafe extern "efiapi" fn(
8687
number_of_events: usize,
87-
events: *mut Event,
88+
events: *mut uefi_raw::Event,
8889
out_index: *mut usize,
8990
) -> Status,
90-
signal_event: unsafe extern "efiapi" fn(event: Event) -> Status,
91-
close_event: unsafe extern "efiapi" fn(event: Event) -> Status,
92-
check_event: unsafe extern "efiapi" fn(event: Event) -> Status,
91+
signal_event: unsafe extern "efiapi" fn(event: uefi_raw::Event) -> Status,
92+
close_event: unsafe extern "efiapi" fn(event: uefi_raw::Event) -> Status,
93+
check_event: unsafe extern "efiapi" fn(event: uefi_raw::Event) -> Status,
9394

9495
// Protocol handlers
9596
install_protocol_interface: unsafe extern "efiapi" fn(
@@ -118,7 +119,7 @@ struct BootServicesInternal {
118119
_reserved: usize,
119120
register_protocol_notify: unsafe extern "efiapi" fn(
120121
protocol: &Guid,
121-
event: Event,
122+
event: uefi_raw::Event,
122123
registration: *mut Option<ProtocolSearchKey>,
123124
) -> Status,
124125
locate_handle: unsafe extern "efiapi" fn(
@@ -235,7 +236,7 @@ struct BootServicesInternal {
235236
notify_fn: Option<EventNotifyFn>,
236237
notify_ctx: Option<NonNull<c_void>>,
237238
event_group: Option<NonNull<Guid>>,
238-
out_event: *mut Option<Event>,
239+
out_event: *mut uefi_raw::Event,
239240
) -> Status,
240241
}
241242

@@ -528,13 +529,13 @@ impl BootServices {
528529
notify_fn: Option<EventNotifyFn>,
529530
notify_ctx: Option<NonNull<c_void>>,
530531
) -> Result<Event> {
531-
let mut event = None;
532+
let mut event = ptr::null_mut();
532533

533534
// Now we're ready to call UEFI
534535
(self.0.create_event)(event_ty, notify_tpl, notify_fn, notify_ctx, &mut event)
535536
.to_result_with_val(
536537
// OK to unwrap: event is non-null for Status::SUCCESS.
537-
|| event.unwrap(),
538+
|| Event::from_ptr(event).unwrap(),
538539
)
539540
}
540541

@@ -589,7 +590,7 @@ impl BootServices {
589590
return Err(Status::UNSUPPORTED.into());
590591
}
591592

592-
let mut event = None;
593+
let mut event = ptr::null_mut();
593594

594595
(self.0.create_event_ex)(
595596
event_type,
@@ -601,7 +602,7 @@ impl BootServices {
601602
)
602603
.to_result_with_val(
603604
// OK to unwrap: event is non-null for Status::SUCCESS.
604-
|| event.unwrap(),
605+
|| Event::from_ptr(event).unwrap(),
605606
)
606607
}
607608

@@ -618,7 +619,7 @@ impl BootServices {
618619
TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns),
619620
TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns),
620621
};
621-
unsafe { (self.0.set_timer)(event.unsafe_clone(), ty, time) }.to_result()
622+
unsafe { (self.0.set_timer)(event.as_ptr(), ty, time) }.to_result()
622623
}
623624

624625
/// Stops execution until an event is signaled.
@@ -656,7 +657,9 @@ impl BootServices {
656657
/// * [`uefi::Status::INVALID_PARAMETER`]
657658
/// * [`uefi::Status::UNSUPPORTED`]
658659
pub fn wait_for_event(&self, events: &mut [Event]) -> Result<usize, Option<usize>> {
659-
let (number_of_events, events) = (events.len(), events.as_mut_ptr());
660+
let number_of_events = events.len();
661+
let events: *mut uefi_raw::Event = events.as_mut_ptr().cast();
662+
660663
let mut index = 0;
661664
unsafe { (self.0.wait_for_event)(number_of_events, events, &mut index) }.to_result_with(
662665
|| index,
@@ -691,7 +694,7 @@ impl BootServices {
691694
pub fn signal_event(&self, event: &Event) -> Result {
692695
// Safety: cloning this event should be safe, as we're directly passing it to firmware
693696
// and not keeping the clone around.
694-
unsafe { (self.0.signal_event)(event.unsafe_clone()).to_result() }
697+
unsafe { (self.0.signal_event)(event.as_ptr()).to_result() }
695698
}
696699

697700
/// Removes `event` from any event group to which it belongs and closes it. If `event` was
@@ -708,7 +711,7 @@ impl BootServices {
708711
///
709712
/// * [`uefi::Status::INVALID_PARAMETER`]
710713
pub fn close_event(&self, event: Event) -> Result {
711-
unsafe { (self.0.close_event)(event).to_result() }
714+
unsafe { (self.0.close_event)(event.as_ptr()).to_result() }
712715
}
713716

714717
/// Checks to see if an event is signaled, without blocking execution to wait for it.
@@ -725,7 +728,7 @@ impl BootServices {
725728
///
726729
/// * [`uefi::Status::INVALID_PARAMETER`]
727730
pub fn check_event(&self, event: Event) -> Result<bool> {
728-
let status = unsafe { (self.0.check_event)(event) };
731+
let status = unsafe { (self.0.check_event)(event.as_ptr()) };
729732
match status {
730733
Status::SUCCESS => Ok(true),
731734
Status::NOT_READY => Ok(false),
@@ -848,7 +851,7 @@ impl BootServices {
848851
) -> Result<(Event, SearchType)> {
849852
let mut key = None;
850853
// Safety: we clone `event` a couple times, but there will be only one left once we return.
851-
unsafe { (self.0.register_protocol_notify)(protocol, event.unsafe_clone(), &mut key) }
854+
unsafe { (self.0.register_protocol_notify)(protocol, event.as_ptr(), &mut key) }
852855
// Safety: as long as this call is successful, `key` will be valid.
853856
.to_result_with_val(|| unsafe {
854857
(

0 commit comments

Comments
 (0)