Skip to content

Commit ce2bcc2

Browse files
committed
Add system::stdout_handle() accessor
Provides direct access to the stdout handle from the system table. This complements the existing with_stdout() function, which only exposes the Output protocol. Having the handle is useful for opening additional protocols on the console device or passing it to UEFI functions that require a device handle. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent d8482d7 commit ce2bcc2

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# uefi - [Unreleased]
22

33
## Added
4+
- Added `system::stdout_handle()`.
45
- Added `proto::ata::AtaRequestBuilder::read_pio()`.
56
- Added `proto::shell::Shell::{var(), set_var(), vars()}`
67
- Added `proto::pci::root_bridge::PciRootBridgeIo::configuration()`.

uefi/src/system.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::proto::console::text::{Input, Output};
1313
use crate::table::cfg::ConfigTableEntry;
1414
use crate::table::{self, Revision};
15-
use crate::{CStr16, Char16};
15+
use crate::{CStr16, Char16, Handle};
1616
use core::slice;
1717

1818
/// Get the firmware vendor string.
@@ -139,6 +139,23 @@ where
139139
f(stdout)
140140
}
141141

142+
/// Get the [`Handle`] associated with stdout.
143+
///
144+
/// # Panics
145+
///
146+
/// This function will panic if called after exiting boot services, or if stdout
147+
/// is not available.
148+
#[must_use]
149+
pub fn stdout_handle() -> Handle {
150+
let st = table::system_table_raw_panicking();
151+
// SAFETY: valid per requirements of `set_system_table`.
152+
let st = unsafe { st.as_ref() };
153+
// The I/O protocols cannot be used after exiting boot services.
154+
assert!(!st.boot_services.is_null(), "boot services are not active");
155+
// SAFETY: stdout_handle is a valid handle per UEFI specification.
156+
unsafe { Handle::from_ptr(st.stdout_handle) }.expect("stdout is not available")
157+
}
158+
142159
/// Call `f` with the [`Output`] protocol attached to stderr.
143160
///
144161
/// # Panics

0 commit comments

Comments
 (0)