Reorder heap initialization

This commit is contained in:
Zhang Junyang
2024-12-31 14:37:51 +08:00
committed by Tate, Hongliang Tian
parent 5ea366bced
commit 7676f8ec95
4 changed files with 14 additions and 13 deletions

View File

@ -38,13 +38,10 @@ fn parse_bootloader_name(mb1_info: &MultibootLegacyInfo) -> &str {
fn parse_kernel_commandline(mb1_info: &MultibootLegacyInfo) -> &str {
let mut cmdline = "";
if mb1_info.cmdline != 0 {
let ptr = paddr_to_vaddr(mb1_info.cmdline as usize) as *const i8;
// SAFETY: the command line is C-style zero-terminated string.
unsafe {
let cstr = paddr_to_vaddr(mb1_info.cmdline as usize) as *const i8;
let cstr = core::ffi::CStr::from_ptr(cstr);
cmdline = cstr.to_str().unwrap();
}
let cstr = unsafe { core::ffi::CStr::from_ptr(ptr) };
cmdline = cstr.to_str().unwrap();
}
cmdline
}

View File

@ -32,6 +32,8 @@ pub struct BootInfo {
}
/// Gets the boot information.
///
/// This function is usable after initialization with [`init_after_heap`].
pub fn boot_info() -> &'static BootInfo {
INFO.get().unwrap()
}
@ -90,10 +92,11 @@ pub(crate) struct EarlyBootInfo {
/// The boot-time information.
pub(crate) static EARLY_INFO: Once<EarlyBootInfo> = Once::new();
/// Initializes the runtime information.
/// Initializes the boot information.
///
/// This function allows the run-time getters to work properly.
pub(crate) fn init() {
/// This function copies the boot-time accessible information to the heap to
/// allow [`boot_info`] to work properly.
pub(crate) fn init_after_heap() {
let boot_time_info = EARLY_INFO.get().unwrap();
INFO.call_once(|| BootInfo {

View File

@ -75,14 +75,15 @@ unsafe fn init() {
#[cfg(feature = "cvm_guest")]
arch::init_cvm_guest();
logger::init();
// SAFETY: This function is called only once and only on the BSP.
unsafe { cpu::local::early_init_bsp_local_base() };
// SAFETY: This function is called only once and only on the BSP.
unsafe { mm::heap_allocator::init() };
boot::init();
logger::init();
boot::init_after_heap();
mm::frame::allocator::init();
mm::kspace::init_kernel_page_table(mm::init_page_meta());

View File

@ -12,7 +12,7 @@ use core::str::FromStr;
use log::{LevelFilter, Metadata, Record};
use spin::Once;
use crate::boot::BOOT_TIME_INFO;
use crate::boot::EARLY_INFO;
static LOGGER: Logger = Logger::new();
@ -82,7 +82,7 @@ pub(crate) fn init() {
}
fn get_log_level() -> Option<LevelFilter> {
let kcmdline = BOOT_TIME_INFO.get().unwrap().kernel_cmdline;
let kcmdline = EARLY_INFO.get().unwrap().kernel_cmdline;
// Although OSTD is agnostic of the parsing of the kernel command line,
// the logger assumes that it follows the Linux kernel command line format.