diff --git a/kernel/src/elf_loader.rs b/kernel/src/elf_loader.rs index 0a036789b..5459f4328 100644 --- a/kernel/src/elf_loader.rs +++ b/kernel/src/elf_loader.rs @@ -49,7 +49,7 @@ pub struct MappedModule<'a> { } /// Maps a grub module, which already lives in reserved physical memory, into the KernelLand. -pub fn map_module(module: &impl Module) -> MappedModule<'_> { +pub fn map_module(module: &impl Module) -> Result, KernelError> { let start_address_aligned = module.start_address().floor(); // Use start_address_aligned to calculate the number of pages, to avoid an off-by-one. let module_len_aligned = utils::align_up(module.end_address().addr() - start_address_aligned.addr(), PAGE_SIZE); @@ -76,12 +76,12 @@ pub fn map_module(module: &impl Module) -> MappedModule<'_> { slice::from_raw_parts(start.addr() as *const u8, len) }); - MappedModule { + Ok(MappedModule { mapping_addr, start, len, elf - } + }) } impl<'a> Drop for MappedModule<'a> { diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 293d95d18..8dad711b6 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -128,7 +128,8 @@ fn main() { info!("Loading all the init processes"); for module in crate::arch::get_modules() { info!("Loading {}", module.name()); - let mapped_module = elf_loader::map_module(&module); + let mapped_module = elf_loader::map_module(&module) + .unwrap_or_else(|_| panic!("Unable to find available memory for module {}", module.name())); let proc = ProcessStruct::new(String::from(module.name()), elf_loader::get_kacs(&mapped_module)).unwrap(); let (ep, sp) = { let mut pmemlock = proc.pmemory.lock(); @@ -206,7 +207,7 @@ unsafe fn do_panic(msg: core::fmt::Arguments<'_>, stackdump_source: Option(mapped_kernel_elf: &'a Option>) -> Option<(&'a ElfFile<'a>, &'a[Entry32])> {