1 //! This module provides miscellaneous opinionated but optional helpers to
2 //! better integrate your application with the Rust runtime and the Rust
3 //! ecosystem.
4 //!
5 //! For now, this includes:
6 //! - using [`uefi::allocator::Allocator`] as global allocator (feature `global_allocator`)
7 //! - an implementation of [`log::Log`] (feature `logger`) which logs to
8 //! the stdout text protocol of UEFI (as long as boot services were not
9 //! excited) and to the [debugcon device](https://phip1611.de/blog/how-to-use-qemus-debugcon-feature/)
10 //! (only on x86) (feature `log-debugcon`).
11 //! - [`print!`][print_macro] and [`println!`][println_macro] macros defaulting
12 //! to the uefi boot service stdout stream
13 //! - default panic handler (feature `panic_handler`)
14 //!
15 //! **PLEASE NOTE** that these helpers are meant for the pre exit boot service
16 //! epoch.
17 //!
18 //! [print_macro]: uefi::print!
19 //! [println_macro]: uefi::println!
20
21 use crate::Result;
22 #[doc(hidden)]
23 pub use println::_print;
24
25 #[cfg(feature = "global_allocator")]
26 mod global_allocator;
27 #[cfg(feature = "logger")]
28 mod logger;
29 #[cfg(feature = "panic_handler")]
30 mod panic_handler;
31 mod println;
32
33 /// Initialize all helpers defined in [`uefi::helpers`] whose Cargo features
34 /// are activated.
35 ///
36 /// This must be called as early as possible, before trying to use logging.
37 ///
38 /// **PLEASE NOTE** that these helpers are meant for the pre exit boot service
39 /// epoch. Limited functionality might work after exiting them, such as logging
40 /// to the debugcon device.
41 ///
42 /// # Panics
43 ///
44 /// This function may panic if called more than once.
45 #[allow(clippy::missing_const_for_fn)]
init() -> Result<()>46 pub fn init() -> Result<()> {
47 // Set up logging.
48 #[cfg(feature = "logger")]
49 unsafe {
50 logger::init();
51 }
52
53 Ok(())
54 }
55
56 #[allow(clippy::missing_const_for_fn)]
exit()57 pub(crate) fn exit() {
58 #[cfg(feature = "logger")]
59 logger::disable();
60 }
61