Skip to content

Commit 4eb4791

Browse files
committed
Only load what you have to load.
1 parent 83fb430 commit 4eb4791

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/program.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,21 @@ impl TransientProgramArea {
224224

225225
let mut iter = loader.iter_program_headers();
226226
while let Some(Ok(ph)) = iter.next() {
227-
if ph.p_vaddr() >= 0x2000_1000 {
227+
if ph.p_vaddr() as *mut u32 >= self.memory_bottom
228+
&& ph.p_type() == neotron_loader::ProgramHeader::PT_LOAD
229+
{
228230
println!("Loading {} bytes to 0x{:08x}", ph.p_memsz(), ph.p_vaddr());
229231
let ram = unsafe {
230232
core::slice::from_raw_parts_mut(ph.p_vaddr() as *mut u8, ph.p_memsz() as usize)
231233
};
234+
// Zero all of it.
232235
for b in ram.iter_mut() {
233236
*b = 0;
234237
}
235-
source.uncached_read(ph.p_offset(), &mut ram[0..ph.p_filesz() as usize])?;
238+
// Replace some of those zeros with bytes from disk.
239+
if ph.p_filesz() != 0 {
240+
source.uncached_read(ph.p_offset(), &mut ram[0..ph.p_filesz() as usize])?;
241+
}
236242
}
237243
}
238244

0 commit comments

Comments
 (0)