Skip to content

Commit 5a45784

Browse files
committed
uefi: Fix crash when pressing 'q' during -b pagination
The uefi crate's println! macro calls .expect() on write results. When the user presses 'q' during -b page break mode, the UEFI shell's ConsoleLogger disables output and returns EFI_DEVICE_ERROR for all subsequent writes. This causes the .expect() to panic, resulting in a page fault crash. Replace the uefi crate's print!/println! macros with non-panicking versions that silently ignore write errors, allowing the application to exit cleanly after the user breaks out of pagination. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent cf3e60a commit 5a45784

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

framework_lib/src/fw_uefi/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ use uefi_raw::protocol::shell::ShellProtocol;
1111

1212
pub mod fs;
1313

14+
/// Non-panicking print helper for UEFI.
15+
///
16+
/// The uefi crate's `println!` calls `.expect()` on write results, which
17+
/// panics when the UEFI shell's ConsoleLogger returns an error (e.g. after
18+
/// the user presses 'q' during `-b` page break mode). This version silently
19+
/// ignores write errors to avoid crashing.
20+
#[doc(hidden)]
21+
pub fn _print_safe(args: core::fmt::Arguments) {
22+
uefi::system::with_stdout(|stdout| {
23+
let _ = core::fmt::Write::write_fmt(stdout, args);
24+
});
25+
}
26+
1427
fn get_shell_protocol() -> &'static ShellProtocol {
1528
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles");
1629

framework_lib/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,23 @@ pub mod touchscreen_win;
3131
pub mod usbhub;
3232

3333
#[cfg(feature = "uefi")]
34-
#[macro_use]
3534
extern crate uefi;
3635

36+
// Override uefi crate's print!/println! macros with non-panicking versions.
37+
// The uefi crate's versions call .expect() on write results, which crashes
38+
// when the UEFI shell returns an error after 'q' is pressed during -b pagination.
39+
#[cfg(feature = "uefi")]
40+
macro_rules! print {
41+
($($arg:tt)*) => ($crate::fw_uefi::_print_safe(core::format_args!($($arg)*)));
42+
}
43+
#[cfg(feature = "uefi")]
44+
macro_rules! println {
45+
() => ($crate::fw_uefi::_print_safe(core::format_args!("\n")));
46+
($($arg:tt)*) => ($crate::fw_uefi::_print_safe(
47+
core::format_args!("{}\n", core::format_args!($($arg)*))
48+
));
49+
}
50+
3751
pub mod capsule;
3852
pub mod capsule_content;
3953
pub mod ccgx;

0 commit comments

Comments
 (0)