Skip to content

Commit 1b55908

Browse files
authoredSep 7, 2021
Merge pull request #282 from rust-osdev/panic-unwind
Handle panics by unwinding the stack and implement `check_event` method
2 parents 400c905 + 8da602f commit 1b55908

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed
 

‎.github/workflows/rust.yml

-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ jobs:
7979

8080
- name: Run cargo test
8181
uses: actions-rs/cargo@v1
82-
env:
83-
# This works around "duplicate item in crate core" errors:
84-
# https://github.com/rust-lang/wg-cargo-std-aware/issues/56
85-
CARGO_PROFILE_DEV_PANIC: unwind
8682
with:
8783
command: test
8884
args: -Zbuild-std=std --target x86_64-unknown-linux-gnu --features=exts

‎Cargo.toml

-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ members = [
4545
"uefi-test-runner",
4646
]
4747

48-
[profile.dev]
49-
panic = "abort"
50-
51-
[profile.release]
52-
panic = "abort"
53-
5448
[patch.crates-io]
5549
uefi-macros = { path = "uefi-macros" }
5650
uefi = { path = "." }

‎src/table/boot.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct BootServices {
5959
) -> Status,
6060
signal_event: usize,
6161
close_event: usize,
62-
check_event: usize,
62+
check_event: unsafe extern "efiapi" fn(event: Event) -> Status,
6363

6464
// Protocol handlers
6565
install_protocol_interface: usize,
@@ -337,7 +337,17 @@ impl BootServices {
337337
.into_with_val(|| event.assume_init())
338338
}
339339

340-
/// Stops execution until an event is signaled
340+
/// Sets the trigger for `EventType::TIMER` event.
341+
pub fn set_timer(&self, event: Event, trigger_time: TimerTrigger) -> Result {
342+
let (ty, time) = match trigger_time {
343+
TimerTrigger::Cancel => (0, 0),
344+
TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns),
345+
TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns),
346+
};
347+
unsafe { (self.set_timer)(event, ty, time) }.into()
348+
}
349+
350+
/// Stops execution until an event is signaled.
341351
///
342352
/// This function must be called at priority level `Tpl::APPLICATION`. If an
343353
/// attempt is made to call it at any other priority level, an `Unsupported`
@@ -379,14 +389,17 @@ impl BootServices {
379389
)
380390
}
381391

382-
/// Sets the trigger for `EventType::TIMER` event.
383-
pub fn set_timer(&self, event: Event, trigger_time: TimerTrigger) -> Result {
384-
let (ty, time) = match trigger_time {
385-
TimerTrigger::Cancel => (0, 0),
386-
TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns),
387-
TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns),
388-
};
389-
unsafe { (self.set_timer)(event, ty, time) }.into()
392+
/// Checks to see if an event is signaled, without blocking execution to wait for it.
393+
///
394+
/// The returned value will be `true` if the event is in the signaled state,
395+
/// otherwise `false` is returned.
396+
pub fn check_event(&self, event: Event) -> Result<bool> {
397+
let status = unsafe { (self.check_event)(event) };
398+
match status {
399+
Status::SUCCESS => Ok(true.into()),
400+
Status::NOT_READY => Ok(false.into()),
401+
_ => Err(status.into()),
402+
}
390403
}
391404

392405
/// Query a handle for a certain protocol.

‎uefi-test-runner/src/boot/misc.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
use uefi::prelude::*;
21
use uefi::table::boot::{BootServices, EventType, TimerTrigger, Tpl};
2+
use uefi::{prelude::*, Event};
33

44
pub fn test(bt: &BootServices) {
55
info!("Testing timer...");
66
test_timer(bt);
7+
info!("Testing events...");
8+
test_event_callback(bt);
79
info!("Testing watchdog...");
810
test_watchdog(bt);
911
}
1012

11-
fn test_watchdog(bt: &BootServices) {
12-
// Disable the UEFI watchdog timer
13-
bt.set_watchdog_timer(0, 0x10000, None)
14-
.expect_success("Could not set watchdog timer");
15-
}
16-
1713
fn test_timer(bt: &BootServices) {
1814
let timer_event = unsafe { bt.create_event(EventType::TIMER, Tpl::APPLICATION, None) }
1915
.expect_success("Failed to create TIMER event");
@@ -23,3 +19,19 @@ fn test_timer(bt: &BootServices) {
2319
bt.wait_for_event(&mut events)
2420
.expect_success("Wait for event failed");
2521
}
22+
23+
fn test_event_callback(bt: &BootServices) {
24+
fn callback(_event: Event) {
25+
info!("Inside the event callback");
26+
}
27+
let event = unsafe { bt.create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback)) }
28+
.expect_success("Failed to create custom event");
29+
bt.check_event(event)
30+
.expect_success("Failed to check event");
31+
}
32+
33+
fn test_watchdog(bt: &BootServices) {
34+
// Disable the UEFI watchdog timer
35+
bt.set_watchdog_timer(0, 0x10000, None)
36+
.expect_success("Could not set watchdog timer");
37+
}

0 commit comments

Comments
 (0)