Skip to content

Commit

Permalink
fixup! Kernel: Get kernel builtins through arch abstraction API
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Feb 21, 2019
1 parent 68c2bef commit 04f628e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions kernel/src/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MappedModule<'_>, 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);
Expand All @@ -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> {
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -206,7 +207,7 @@ unsafe fn do_panic(msg: core::fmt::Arguments<'_>, stackdump_source: Option<Stack
let mapped_kernel_module = crate::arch::i386::multiboot::try_get_boot_information()
.and_then(|info| info.module_tags().nth(0));
let mapped_kernel_elf = mapped_kernel_module.as_ref()
.and_then(|module| Some(elf_loader::map_module(module)));
.and_then(|module| elf_loader::map_module(module).ok());

/// Gets the symbol table of a mapped module.
fn get_symbols<'a>(mapped_kernel_elf: &'a Option<MappedModule<'_>>) -> Option<(&'a ElfFile<'a>, &'a[Entry32])> {
Expand Down

0 comments on commit 04f628e

Please sign in to comment.