fix bug: sys_mmap didn't zero clean the anonymous memory

We can use delay mode or eager mode(in added comment codes)
WRJ's great work!
master
chyyuu 6 years ago
parent 5080ee2579
commit 734e01cc46

@ -44,6 +44,11 @@ impl<T: FrameAllocator> MemoryHandler for Delay<T> {
entry.set_target(frame); entry.set_target(frame);
entry.set_present(true); entry.set_present(true);
entry.update(); entry.update();
//init with zero for delay mmap mode
let data = pt.get_page_slice_mut(addr);
for x in data {
*x = 0;
}
true true
} }
} }

@ -114,7 +114,7 @@ impl Drop for KernelStack {
/// Handle page fault at `addr`. /// Handle page fault at `addr`.
/// Return true to continue, false to halt. /// Return true to continue, false to halt.
pub fn handle_page_fault(addr: usize) -> bool { pub fn handle_page_fault(addr: usize) -> bool {
// debug!("page fault @ {:#x}", addr); debug!("page fault @ {:#x}", addr);
// This is safe as long as page fault never happens in page fault handler // This is safe as long as page fault never happens in page fault handler
unsafe { process_unsafe().vm.handle_page_fault(addr) } unsafe { process_unsafe().vm.handle_page_fault(addr) }

@ -46,9 +46,15 @@ pub fn sys_mmap(
addr, addr,
addr + len, addr + len,
prot.to_attr(), prot.to_attr(),
// ByFrame::new(GlobalFrameAlloc), //eagle mmap mode
Delay::new(GlobalFrameAlloc), Delay::new(GlobalFrameAlloc),
"mmap_anon", "mmap_anon",
); );
//init with zero for eagle mmap mode
// let data = unsafe { slice::from_raw_parts_mut(addr as *mut u8, len) };
// for x in data {
// *x = 0;
// }
return Ok(addr); return Ok(addr);
} else { } else {
// only check // only check

Loading…
Cancel
Save