loader: handle sections on page boundaries

Handle a section that ends exactly at a page boundary.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-08-15 21:54:59 +08:00
parent 1b315de830
commit 4700275b93

View file

@ -296,7 +296,7 @@ impl MiniElf {
// If this is not a new page, ensure the uninitialized values from between // If this is not a new page, ensure the uninitialized values from between
// this section and the previous one are all zeroed out. // this section and the previous one are all zeroed out.
if this_page != current_page_addr { if this_page != current_page_addr || previous_addr == current_page_addr {
if VDBG {println!("1 {:08x} -> {:08x}", top as usize, this_page);} if VDBG {println!("1 {:08x} -> {:08x}", top as usize, this_page);}
allocator.map_page(satp, top as usize, this_page, flag_defaults); allocator.map_page(satp, top as usize, this_page, flag_defaults);
allocator.change_owner(pid as XousPid, top as usize); allocator.change_owner(pid as XousPid, top as usize);
@ -334,7 +334,7 @@ impl MiniElf {
} }
// Part 2: Copy any full pages. // Part 2: Copy any full pages.
while bytes_to_copy > PAGE_SIZE { while bytes_to_copy >= PAGE_SIZE {
if VDBG {println!("2 {:08x} -> {:08x}", top as usize, this_page);} if VDBG {println!("2 {:08x} -> {:08x}", top as usize, this_page);}
allocator.map_page(satp, top as usize, this_page, flag_defaults); allocator.map_page(satp, top as usize, this_page, flag_defaults);
allocator.change_owner(pid as XousPid, top as usize); allocator.change_owner(pid as XousPid, top as usize);
@ -682,9 +682,9 @@ fn copy_processes(cfg: &mut BootConfig) {
);} );}
// If this is not a new page, ensure the uninitialized values from between // If this is not a new page, ensure the uninitialized values from between
// this section and the previous one are all zeroed out. // this section and the previous one are all zeroed out.
if this_page != page_addr { if this_page != page_addr || previous_addr == page_addr {
if VDBG {println!("New page @ {:08x}", this_page);} if VDBG {println!("New page @ {:08x}", this_page);}
if previous_addr != 0 { if previous_addr != 0 && previous_addr != page_addr {
if VDBG {println!( if VDBG {println!(
"Zeroing-out remainder of previous page: {:08x} (mapped to physical address {:08x})", "Zeroing-out remainder of previous page: {:08x} (mapped to physical address {:08x})",
previous_addr, top as usize, previous_addr, top as usize,
@ -714,8 +714,9 @@ fn copy_processes(cfg: &mut BootConfig) {
} }
let first_chunk_offset = section.virt as usize & (PAGE_SIZE - 1); let first_chunk_offset = section.virt as usize & (PAGE_SIZE - 1);
if VDBG {println!( if VDBG {println!(
"First chunk is {} bytes, copying from {:08x}:{:08x} -> {:08x}:{:08x} (virt: {:08x})", "Section chunk is {} bytes, {} from {:08x}:{:08x} -> {:08x}:{:08x} (virt: {:08x})",
first_chunk_size, first_chunk_size,
if section.no_copy() { "zeroing" } else { "copying" },
src_addr as usize, src_addr as usize,
unsafe { src_addr.add(first_chunk_size) as usize }, unsafe { src_addr.add(first_chunk_size) as usize },
unsafe { top.add(first_chunk_offset) as usize }, unsafe { top.add(first_chunk_offset) as usize },
@ -740,12 +741,12 @@ fn copy_processes(cfg: &mut BootConfig) {
bytes_to_copy -= first_chunk_size; bytes_to_copy -= first_chunk_size;
// Part 2: Copy any full pages. // Part 2: Copy any full pages.
while bytes_to_copy > PAGE_SIZE { while bytes_to_copy >= PAGE_SIZE {
cfg.extra_pages += 1; cfg.extra_pages += 1;
top = cfg.get_top() as *mut u8; top = cfg.get_top() as *mut u8;
// println!( // println!(
// "Copying next page from {:08x} {:08x}", // "Copying next page from {:08x} {:08x} ({} bytes to go...)",
// src_addr as usize, top as usize // src_addr as usize, top as usize, bytes_to_copy
// ); // );
if !section.no_copy() { if !section.no_copy() {
unsafe { unsafe {