From 9b3294a5f21583841c1655f22f95e8dc67598392 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 16 Nov 2018 00:17:05 +0800 Subject: [PATCH] fix clear bss when load user program. 'sh' works! --- kernel/src/process/context.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/src/process/context.rs b/kernel/src/process/context.rs index a2e9127f..57df1194 100644 --- a/kernel/src/process/context.rs +++ b/kernel/src/process/context.rs @@ -80,12 +80,11 @@ impl ContextImpl { 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]); + let mem_size = ph.mem_size() as usize; + + let target = unsafe { ::core::slice::from_raw_parts_mut(virt_addr as *mut u8, mem_size) }; + target[..file_size].copy_from_slice(&data[offset..offset + file_size]); + target[file_size..].iter_mut().for_each(|x| *x = 0); } ustack_top = push_args_at_stack(args, ustack_top); });