Skip to content

uefi: system::with_* now take mutably closure #1663

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
May 11, 2025
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
2 changes: 2 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
## Changed
- **Breaking:** `boot::stall` now take `core::time::Duration` instead of `usize`.
- `table::cfg::*_GUID` constants now deprecated. Use `ConfigTableEntry::*_GUID` instead.
- `system::with_config_table`, `system::with_stdin`, `system::with_stdout` and `system::with_stderr`
now take mutably closure.


# uefi - 0.35.0 (2025-05-04)
Expand Down
42 changes: 34 additions & 8 deletions uefi/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ pub fn uefi_revision() -> Revision {
/// }
/// });
/// ```
pub fn with_config_table<F, R>(f: F) -> R
pub fn with_config_table<F, R>(mut f: F) -> R
where
F: Fn(&[ConfigTableEntry]) -> R,
F: FnMut(&[ConfigTableEntry]) -> R,
{
let st = table::system_table_raw_panicking();
// SAFETY: valid per requirements of `set_system_table`.
Expand All @@ -83,6 +83,7 @@ where
} else {
unsafe { slice::from_raw_parts(ptr, len) }
};

f(slice)
}

Expand All @@ -92,9 +93,9 @@ where
///
/// This function will panic if called after exiting boot services, or if stdin
/// is not available.
pub fn with_stdin<F, R>(f: F) -> R
pub fn with_stdin<F, R>(mut f: F) -> R
where
F: Fn(&mut Input) -> R,
F: FnMut(&mut Input) -> R,
{
let st = table::system_table_raw_panicking();
// SAFETY: valid per requirements of `set_system_table`.
Expand All @@ -118,9 +119,9 @@ where
///
/// This function will panic if called after exiting boot services, or if stdout
/// is not available.
pub fn with_stdout<F, R>(f: F) -> R
pub fn with_stdout<F, R>(mut f: F) -> R
where
F: Fn(&mut Output) -> R,
F: FnMut(&mut Output) -> R,
{
let st = table::system_table_raw_panicking();
// SAFETY: valid per requirements of `set_system_table`.
Expand All @@ -144,9 +145,9 @@ where
///
/// This function will panic if called after exiting boot services, or if stderr
/// is not available.
pub fn with_stderr<F, R>(f: F) -> R
pub fn with_stderr<F, R>(mut f: F) -> R
where
F: Fn(&mut Output) -> R,
F: FnMut(&mut Output) -> R,
{
let st = table::system_table_raw_panicking();
// SAFETY: valid per requirements of `set_system_table`.
Expand All @@ -163,3 +164,28 @@ where

f(stderr)
}

#[cfg(test)]
mod tests {
use super::*;

#[allow(dead_code)]
#[allow(clippy::assertions_on_constants)]
fn with_config_table_compile_test() {
assert!(false, "compile test only");

let mut acpi2_address = None;

with_config_table(|slice| {
for i in slice {
match i.guid {
ConfigTableEntry::ACPI2_GUID => {
acpi2_address = Some(i.address);
break;
}
_ => {}
}
}
});
}
}
Loading