diff --git a/uefi-test-runner/src/boot/misc.rs b/uefi-test-runner/src/boot/misc.rs index e1c4f9cbe..87a4d206b 100644 --- a/uefi-test-runner/src/boot/misc.rs +++ b/uefi-test-runner/src/boot/misc.rs @@ -46,8 +46,12 @@ fn test_check_event_freestanding() { let event = unsafe { boot::create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback), None) } .unwrap(); - let is_signaled = boot::check_event(event).unwrap(); + + let event_clone = unsafe { event.unsafe_clone() }; + let is_signaled = boot::check_event(event_clone).unwrap(); assert!(!is_signaled); + + boot::close_event(event).unwrap(); } fn test_timer_freestanding() { @@ -56,6 +60,8 @@ fn test_timer_freestanding() { let mut events = unsafe { [timer_event.unsafe_clone()] }; boot::set_timer(&timer_event, TimerTrigger::Relative(5_0 /*00 ns */)).unwrap(); assert_eq!(boot::wait_for_event(&mut events).unwrap(), 0); + + boot::close_event(timer_event).unwrap(); } fn test_timer(bt: &BootServices) { diff --git a/uefi/src/boot.rs b/uefi/src/boot.rs index 9b0d38c56..d86d635a3 100644 --- a/uefi/src/boot.rs +++ b/uefi/src/boot.rs @@ -234,6 +234,23 @@ pub fn check_event(event: Event) -> Result { } } +/// Removes `event` from any event group to which it belongs and closes it. +/// +/// If `event` was registered with `register_protocol_notify`, then the +/// corresponding registration will be removed. Calling this function within the +/// corresponding notify function is allowed. +/// +/// # Errors +/// +/// The specification does not list any errors, however implementations are +/// allowed to return an error if needed. +pub fn close_event(event: Event) -> Result { + let bt = boot_services_raw_panicking(); + let bt = unsafe { bt.as_ref() }; + + unsafe { (bt.close_event)(event.as_ptr()) }.to_result() +} + /// Sets the trigger for an event of type [`TIMER`]. /// /// # Errors