Skip to content

Add cargo feature for ignoring logger errors #132

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

Merged
merged 1 commit into from
Apr 4, 2020
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ default = []
alloc = []
exts = []
logger = []
# Ignore text output errors in logger as a workaround for firmware issues that
# were observed on the VirtualBox UEFI implementation (see uefi-rs#121)
ignore-logger-errors = []

[dependencies]
bitflags = "1.2.1"
Expand Down
27 changes: 20 additions & 7 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,26 @@ impl<'boot> log::Log for Logger {
fn log(&self, record: &log::Record) {
if let Some(mut ptr) = self.writer {
let writer = unsafe { ptr.as_mut() };
// FIXME: Some UEFI firmware implementations e.g. VrtualBox's implementation
// occasionally report a EFI_DEVICE_ERROR with some text dropped out within
// SimpleTextOutput protocol, which is a firmware bug. In that case, we will
// get a `fmt::Error` here. Since the `log` crate gives no other option to
// deal with output errors, we ignore the `Result` here to prevent potential
// panics from happening.
DecoratedLog::write(writer, record.level(), record.args()).unwrap_or_default();
let result = DecoratedLog::write(writer, record.level(), record.args());

// Some UEFI implementations, such as the one used by VirtualBox,
// may intermittently drop out some text from SimpleTextOutput and
// report an EFI_DEVICE_ERROR. This will be reported here as an
// `fmt::Error`, and given how the `log` crate is designed, our main
// choices when that happens are to ignore the error or panic.
//
// Ignoring errors is bad, especially when they represent loss of
// precious early-boot system diagnosis data, so we panic by
// default. But if you experience this problem and want your UEFI
// application to keep running when it happens, you can enable the
// `ignore-logger-error` cargo feature. If you do so, logging errors
// will be ignored by `uefi-rs` instead.
//
if cfg!(feature = "ignore-logger-errors") {
core::mem::drop(result)
} else {
result.unwrap()
}
}
}

Expand Down