Skip to content

Commit 5162ce0

Browse files
committed
uefi: _print more failsafe
When one accidentally call println! after exit_boot_services, one now at least gets some more debugging info why the machine suddenly reboots. Specifically, this prints now info to `integration-test-debugcon.log` in such a case.
1 parent 4ca4daa commit 5162ce0

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

uefi/src/helpers/println.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@ use core::fmt::Write;
44
/// INTERNAL API! Helper for print macros.
55
#[doc(hidden)]
66
pub fn _print(args: core::fmt::Arguments) {
7-
system_table_boot()
8-
.expect("boot services are not active")
9-
.stdout()
10-
.write_fmt(args)
11-
.expect("Failed to write to stdout");
7+
if let Some(mut bs) = system_table_boot() {
8+
bs.stdout()
9+
.write_fmt(args)
10+
.expect("Failed to write to stdout");
11+
} else {
12+
// Ease debugging: Depending on logger, this might write to serial or
13+
// debugcon.
14+
log::debug!("You are using `print!` after the boot services have been exited.");
15+
}
1216
}
1317

1418
/// Prints to the standard output.
19+
///
20+
/// # Usage
21+
/// Use this as soon as boot services have not been exited.
22+
///
23+
/// You should never use this macro in a custom Logger ([`log::Log`] impl) to
24+
/// prevent a circular runtime dependency.
1525
///
1626
/// # Panics
1727
/// Will panic if `SYSTEM_TABLE` is `None` (Before [`uefi::helpers::init()`] and
@@ -30,6 +40,12 @@ macro_rules! print {
3040

3141
/// Prints to the standard output, with a newline.
3242
///
43+
/// # Usage
44+
/// Use this as soon as boot services have not been exited.
45+
///
46+
/// You should never use this macro in a custom Logger ([`log::Log`] impl) to
47+
/// prevent a circular runtime dependency.
48+
///
3349
/// # Panics
3450
/// Will panic if `SYSTEM_TABLE` is `None` (Before [`uefi::helpers::init()`] and
3551
/// after [`uefi::prelude::SystemTable::exit_boot_services()`]).

0 commit comments

Comments
 (0)