Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boot: Add freestanding check_event #1295

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions uefi-test-runner/src/boot/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn test(st: &SystemTable<Boot>) {
info!("Testing timer...");
test_timer(bt);
info!("Testing events...");
test_check_event_freestanding();
test_event_callback(bt);
test_callback_with_ctx(bt);
info!("Testing watchdog...");
Expand All @@ -35,6 +36,18 @@ fn test_tpl() {
let _guard = unsafe { boot::raise_tpl(Tpl::NOTIFY) };
}

fn test_check_event_freestanding() {
extern "efiapi" fn callback(_event: Event, _ctx: Option<NonNull<c_void>>) {
info!("Callback triggered by check_event");
}

let event =
unsafe { boot::create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback), None) }
.unwrap();
let is_signaled = boot::check_event(event).unwrap();
assert!(!is_signaled);
}

fn test_timer(bt: &BootServices) {
let timer_event = unsafe { bt.create_event(EventType::TIMER, Tpl::APPLICATION, None, None) }
.expect("Failed to create TIMER event");
Expand Down
25 changes: 25 additions & 0 deletions uefi/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,31 @@ pub unsafe fn create_event(
)
}

/// Checks to see if an event is signaled, without blocking execution to wait for it.
///
/// Returns `Ok(true)` if the event is in the signaled state or `Ok(false)`
/// if the event is not in the signaled state.
///
/// # Errors
///
/// Note: Instead of returning [`Status::NOT_READY`] as listed in the UEFI
/// Specification, this function will return `Ok(false)`.
///
/// * [`Status::INVALID_PARAMETER`]: `event` is of type [`NOTIFY_SIGNAL`].
///
/// [`NOTIFY_SIGNAL`]: EventType::NOTIFY_SIGNAL
pub fn check_event(event: Event) -> Result<bool> {
let bt = boot_services_raw_panicking();
let bt = unsafe { bt.as_ref() };

let status = unsafe { (bt.check_event)(event.as_ptr()) };
match status {
Status::SUCCESS => Ok(true),
Status::NOT_READY => Ok(false),
_ => Err(status.into()),
}
}

/// Connect one or more drivers to a controller.
///
/// Usually one disconnects and then reconnects certain drivers
Expand Down