From 6022ec8efc783a442881a4a9fa5a2cdb03fca7bc Mon Sep 17 00:00:00 2001 From: WangRunji Date: Tue, 17 Jul 2018 11:45:55 +0800 Subject: [PATCH] Fix load user program out of range --- kernel/src/process/context.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/src/process/context.rs b/kernel/src/process/context.rs index aca7c7e..13f0166 100644 --- a/kernel/src/process/context.rs +++ b/kernel/src/process/context.rs @@ -65,6 +65,9 @@ impl Context { let virt_addr = ph.virtual_addr() as usize; let offset = ph.offset() as usize; let file_size = ph.file_size() as usize; + if file_size == 0 { + return; + } use core::slice; let target = unsafe { slice::from_raw_parts_mut(virt_addr as *mut u8, file_size) }; target.copy_from_slice(&data[offset..offset + file_size]); @@ -117,7 +120,7 @@ impl Context { impl Debug for Context { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{:?}", self.arch) + write!(f, "{:x?}", self.arch) } }