From 73ad16d367de9e0966dbeeddf2cf23eb22473d07 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 6 Apr 2020 15:29:37 +0800 Subject: [PATCH] loader: fix loading when init spans pages Due to an issue withow MiniELF files were loaded, one page was mapped to two addresses rather than having two adjacent addresses mapped. This occurred when a small section spanned two pages. This has now been corrected, and an additional test binary will be added to demonstrate the issue. Signed-off-by: Sean Cross --- loader/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/loader/src/main.rs b/loader/src/main.rs index 00af11acf..18ca2ea08 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -200,6 +200,7 @@ impl MiniElf { /// The process will have been already loaded in stage 1. This simply assigns /// memory maps as necessary. pub fn load(&self, allocator: &mut BootConfig, load_offset: usize, pid: XousPid) -> usize { + println!("Mapping PID {} starting at offset {:08x}", pid, load_offset); let mut allocated_bytes = 0; let mut page_addr: usize = 0; @@ -291,6 +292,7 @@ impl MiniElf { // Part 3: Copy the final residual partial page if bytes_to_copy > 0 { + let this_page = (section.virt as usize + section.len()) & !(PAGE_SIZE - 1); allocator.map_page(satp, top as usize, this_page, flag_defaults); allocated_bytes += PAGE_SIZE; top -= PAGE_SIZE; @@ -632,6 +634,8 @@ fn copy_processes(cfg: &mut BootConfig) { // Zero out the page, if necessary. unsafe { bzero(top, top.add(section.virt as usize & (PAGE_SIZE - 1))) }; + } else { + println!("Reusing existing page @ {:08x}", this_page); } // Part 1: Copy the first chunk over.