From 005ec047a080d932e75aaffd32ed37493c400a6f Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Tue, 7 Sep 2021 14:17:54 +0300 Subject: [PATCH 1/2] Handle panics by unwinding the stack --- .github/workflows/rust.yml | 4 ---- Cargo.toml | 6 ------ 2 files changed, 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 09c798a0f..6da109c4e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -79,10 +79,6 @@ jobs: - name: Run cargo test uses: actions-rs/cargo@v1 - env: - # This works around "duplicate item in crate core" errors: - # https://github.com/rust-lang/wg-cargo-std-aware/issues/56 - CARGO_PROFILE_DEV_PANIC: unwind with: command: test args: -Zbuild-std=std --target x86_64-unknown-linux-gnu --features=exts diff --git a/Cargo.toml b/Cargo.toml index 71d26acc1..39686528b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,12 +45,6 @@ members = [ "uefi-test-runner", ] -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" - [patch.crates-io] uefi-macros = { path = "uefi-macros" } uefi = { path = "." } From 8da602fc8f196f93f2420173362d82bcf80fcb99 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Tue, 7 Sep 2021 17:00:25 +0300 Subject: [PATCH 2/2] Implement the `check_event` boot services function --- src/table/boot.rs | 33 +++++++++++++++++++++---------- uefi-test-runner/src/boot/misc.rs | 26 +++++++++++++++++------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/table/boot.rs b/src/table/boot.rs index bd04d815d..9ac0a543d 100644 --- a/src/table/boot.rs +++ b/src/table/boot.rs @@ -59,7 +59,7 @@ pub struct BootServices { ) -> Status, signal_event: usize, close_event: usize, - check_event: usize, + check_event: unsafe extern "efiapi" fn(event: Event) -> Status, // Protocol handlers install_protocol_interface: usize, @@ -337,7 +337,17 @@ impl BootServices { .into_with_val(|| event.assume_init()) } - /// Stops execution until an event is signaled + /// Sets the trigger for `EventType::TIMER` event. + pub fn set_timer(&self, event: Event, trigger_time: TimerTrigger) -> Result { + let (ty, time) = match trigger_time { + TimerTrigger::Cancel => (0, 0), + TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns), + TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns), + }; + unsafe { (self.set_timer)(event, ty, time) }.into() + } + + /// Stops execution until an event is signaled. /// /// This function must be called at priority level `Tpl::APPLICATION`. If an /// attempt is made to call it at any other priority level, an `Unsupported` @@ -379,14 +389,17 @@ impl BootServices { ) } - /// Sets the trigger for `EventType::TIMER` event. - pub fn set_timer(&self, event: Event, trigger_time: TimerTrigger) -> Result { - let (ty, time) = match trigger_time { - TimerTrigger::Cancel => (0, 0), - TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns), - TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns), - }; - unsafe { (self.set_timer)(event, ty, time) }.into() + /// Checks to see if an event is signaled, without blocking execution to wait for it. + /// + /// The returned value will be `true` if the event is in the signaled state, + /// otherwise `false` is returned. + pub fn check_event(&self, event: Event) -> Result { + let status = unsafe { (self.check_event)(event) }; + match status { + Status::SUCCESS => Ok(true.into()), + Status::NOT_READY => Ok(false.into()), + _ => Err(status.into()), + } } /// Query a handle for a certain protocol. diff --git a/uefi-test-runner/src/boot/misc.rs b/uefi-test-runner/src/boot/misc.rs index 3b7d540b2..bc765be7f 100644 --- a/uefi-test-runner/src/boot/misc.rs +++ b/uefi-test-runner/src/boot/misc.rs @@ -1,19 +1,15 @@ -use uefi::prelude::*; use uefi::table::boot::{BootServices, EventType, TimerTrigger, Tpl}; +use uefi::{prelude::*, Event}; pub fn test(bt: &BootServices) { info!("Testing timer..."); test_timer(bt); + info!("Testing events..."); + test_event_callback(bt); info!("Testing watchdog..."); test_watchdog(bt); } -fn test_watchdog(bt: &BootServices) { - // Disable the UEFI watchdog timer - bt.set_watchdog_timer(0, 0x10000, None) - .expect_success("Could not set watchdog timer"); -} - fn test_timer(bt: &BootServices) { let timer_event = unsafe { bt.create_event(EventType::TIMER, Tpl::APPLICATION, None) } .expect_success("Failed to create TIMER event"); @@ -23,3 +19,19 @@ fn test_timer(bt: &BootServices) { bt.wait_for_event(&mut events) .expect_success("Wait for event failed"); } + +fn test_event_callback(bt: &BootServices) { + fn callback(_event: Event) { + info!("Inside the event callback"); + } + let event = unsafe { bt.create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback)) } + .expect_success("Failed to create custom event"); + bt.check_event(event) + .expect_success("Failed to check event"); +} + +fn test_watchdog(bt: &BootServices) { + // Disable the UEFI watchdog timer + bt.set_watchdog_timer(0, 0x10000, None) + .expect_success("Could not set watchdog timer"); +}