kernel/src/bootinfo.rs

31 lines
930 B
Rust

use bootloader_api::BootInfo;
use core::ops::Deref;
use spin::Once;
unsafe impl Sync for BootInfoHolder {}
pub struct BootInfoHolder(Once<&'static BootInfo>);
impl BootInfoHolder {
pub fn set(&self, bootinfo: &'static BootInfo) {
assert!(!self.0.is_completed(), "Boot info can only be set once!");
self.0.call_once(|| bootinfo);
}
}
impl Deref for BootInfoHolder {
type Target = &'static BootInfo;
fn deref(&self) -> &Self::Target {
#[expect(
clippy::expect_used,
reason = "
Bootinfo gets initialized during _start, se any use before initialization is a bug.
Error propagation would result in having to write a justified unwrap every time bootinfo is used, so just panic.
"
)]
self.0.get().expect("Boot info used before initialization!")
}
}
pub static BOOTINFO: BootInfoHolder = BootInfoHolder(Once::new());