diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index c9e5f7d..dc9cd40 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -122,14 +122,20 @@ pub fn page_fault_handler(addr: usize) -> bool { info!("active page table token in pg fault is {:x?}", ActivePageTable::token()); let id = memory_set_record().iter() .position(|x| unsafe{(*(x.clone() as *mut MemorySet)).get_page_table_mut().token() == ActivePageTable::token()}); - info!("id got"); let mut mmsets = memory_set_record(); - info!("mmset got"); match id { Some(targetid) => { info!("get id from memroy set recorder."); let mmset_ptr = mmsets.get(targetid); - let pt = unsafe { (*(mmset_ptr.unwrap().clone() as *mut MemorySet)).get_page_table_mut() }; + // get current mmset + + let current_mmset = unsafe{&mut *(mmset_ptr.unwrap().clone() as *mut MemorySet)}; + //check whether the vma is legal + if(current_mmset.find_area(addr).is_none()){ + return false; + } + + let pt = current_mmset.get_page_table_mut(); info!("pt got!"); if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, false, || alloc_frame().unwrap()){ return true; @@ -137,6 +143,10 @@ pub fn page_fault_handler(addr: usize) -> bool { }, None => { info!("get pt from processor()"); + if(process().get_memory_set_mut().find_area(addr).is_none()){ + return false; + } + let pt = process().get_memory_set_mut().get_page_table_mut(); info!("pt got"); if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, true, || alloc_frame().unwrap()){