Skip to content

Commit

Permalink
Only load what you have to load.
Browse files Browse the repository at this point in the history
  • Loading branch information
thejpster committed Jun 16, 2023
1 parent 8ac4009 commit 753d005
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,21 @@ impl TransientProgramArea {

let mut iter = loader.iter_program_headers();
while let Some(Ok(ph)) = iter.next() {
if ph.p_vaddr() >= 0x2000_1000 {
if ph.p_vaddr() as *mut u32 >= self.memory_bottom
&& ph.p_type() == neotron_loader::ProgramHeader::PT_LOAD
{
println!("Loading {} bytes to 0x{:08x}", ph.p_memsz(), ph.p_vaddr());
let ram = unsafe {
core::slice::from_raw_parts_mut(ph.p_vaddr() as *mut u8, ph.p_memsz() as usize)
};
// Zero all of it.
for b in ram.iter_mut() {
*b = 0;
}
source.uncached_read(ph.p_offset(), &mut ram[0..ph.p_filesz() as usize])?;
// Replace some of those zeros with bytes from disk.
if ph.p_filesz() != 0 {
source.uncached_read(ph.p_offset(), &mut ram[0..ph.p_filesz() as usize])?;
}
}
}

Expand Down

0 comments on commit 753d005

Please sign in to comment.