replace some unwrap() and comment the cow pgfault handler

master
lcy1996 6 years ago
parent 7d7cedfdd0
commit 9d803e87d9

@ -176,7 +176,7 @@ impl MemoryArea {
let entry = pt.map(addr,0);
self.flags.apply(entry);
}
let entry = pt.get_entry(addr).unwrap();
let entry = pt.get_entry(addr).expect("fail to get entry");
entry.set_present(false);
entry.update();
@ -194,13 +194,13 @@ impl MemoryArea {
for page in Page::range_of(self.start_addr, self.end_addr) {
let addr = page.start_address();
if self.phys_start_addr.is_none() {
if pt.get_entry(addr).unwrap().present(){
let target = pt.get_entry(addr).unwrap().target();
if pt.get_entry(addr).expect("fail to get entry").present(){
let target = pt.get_entry(addr).expect("fail to get entry").target();
T::dealloc_frame(target);
}
else{
// set valid for pt.unmap function
pt.get_entry(addr).unwrap().set_present(true);
pt.get_entry(addr).expect("fail to get entry").set_present(true);
}
}
pt.unmap(addr);

@ -117,7 +117,7 @@ impl<T: PageTable, M: SwapManager, S: Swapper> SwapExt<T, M, S> {
targetpt.token()
};
targetpt.with(||{
let entry = page_table.get_entry(addr).unwrap();
let entry = page_table.get_entry(addr).expect("failed to get page entry when set swappable");
if entry.present() {
let frame = Frame::new(pt as usize, addr, pttoken);
swap_manager.push(frame);
@ -283,7 +283,7 @@ impl<T: PageTable, M: SwapManager, S: Swapper> SwapExt<T, M, S> {
{
info!("try handling delayed frame allocator");
let need_alloc ={
let entry = self.page_table.get_entry(addr).unwrap();
let entry = self.page_table.get_entry(addr).expect("fail to get entry");
//info!("got entry!");
!entry.present() && !entry.swapped()
};
@ -311,6 +311,7 @@ impl<T: PageTable, M: SwapManager, S: Swapper> SwapExt<T, M, S> {
}
// now we didn't attach the cow so the present will be false when swapped(), to enable the cow some changes will be needed
match self.page_table.get_entry(addr) {
// infact the get_entry(addr) should not be None here
None => return false,
Some(entry) => if !entry.swapped() { return false; },
}

@ -0,0 +1 @@
Subproject commit a37a65fa13a00c5aa0068c3f2b5d55af6a37dd93

@ -25,7 +25,7 @@ pub fn setup_page_table(frame: Frame) {
// Set kernel identity map
// 0x10000000 ~ 1K area
p2.map_identity(0x40, EF::VALID | EF::READABLE | EF::WRITABLE);
// 0x80000000 ~ 12M area for
// 0x80000000 ~ 12M area
p2.map_identity(KERNEL_P2_INDEX, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE);
p2.map_identity(KERNEL_P2_INDEX + 1, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE);
p2.map_identity(KERNEL_P2_INDEX + 2, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE);
@ -62,7 +62,7 @@ impl PageTable for ActivePageTable {
// we may need frame allocator to alloc frame for new page table(first/second)
self.0.map_to(page, frame, flags, &mut FrameAllocatorForRiscv)
.unwrap().flush();
self.get_entry(addr).unwrap()
self.get_entry(addr).expect("fail to get entry")
}
/*

@ -68,7 +68,7 @@ pub fn alloc_frame() -> Option<usize> {
let ret = FRAME_ALLOCATOR.lock().alloc().map(|id| id * PAGE_SIZE + MEMORY_OFFSET);
trace!("Allocate frame: {:x?}", ret);
//do we need : unsafe { ACTIVE_TABLE_SWAP.force_unlock(); } ???
Some(ret.unwrap_or_else(|| active_table_swap().swap_out_any::<InactivePageTable0>().ok().unwrap()))
Some(ret.unwrap_or_else(|| active_table_swap().swap_out_any::<InactivePageTable0>().ok().expect("fail to swap out page")))
}
pub fn dealloc_frame(target: usize) {
@ -123,27 +123,27 @@ pub fn page_fault_handler(addr: usize) -> bool {
let mmset_ptr = mmsets.get(targetid);
// get current mmset
let current_mmset = unsafe{&mut *(mmset_ptr.unwrap().clone() as *mut MemorySet)};
let current_mmset = unsafe{&mut *(mmset_ptr.expect("fail to get mmset_ptr").clone() as *mut MemorySet)};
//check whether the vma is legal
if(current_mmset.find_area(addr).is_none()){
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()){
if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, false, || alloc_frame().expect("fail to alloc frame")){
return true;
}
},
None => {
info!("get pt from processor()");
if(process().get_memory_set_mut().find_area(addr).is_none()){
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()){
if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, true, || alloc_frame().expect("fail to alloc frame")){
return true;
}
},
@ -152,10 +152,12 @@ pub fn page_fault_handler(addr: usize) -> bool {
// Handle copy on write (not being used now)
/*
unsafe { ACTIVE_TABLE.force_unlock(); }
if active_table().page_fault_handler(addr, || alloc_frame().unwrap()){
if active_table().page_fault_handler(addr, || alloc_frame().expect("fail to alloc frame")){
return true;
}
*/
false
}

@ -114,7 +114,7 @@ impl ContextImpl {
let kstack = KernelStack::new();
let id = memory_set_record().iter()
.position(|x| x.clone() == mmset_ptr).unwrap();
.position(|x| x.clone() == mmset_ptr).expect("id not exist");
memory_set_record().remove(id);
let mut ret = Box::new(ContextImpl {
@ -164,9 +164,9 @@ impl ContextImpl {
info!("temporary copy data!");
let kstack = KernelStack::new();
// remove the raw pointer for the memory set since it will
// remove the raw pointer for the memory set in memory_set_record
let id = memory_set_record().iter()
.position(|x| x.clone() == mmset_ptr).unwrap();
.position(|x| x.clone() == mmset_ptr).expect("id not exist");
memory_set_record().remove(id);
let mut ret = Box::new(ContextImpl {
@ -191,16 +191,6 @@ impl ContextImpl {
impl Drop for ContextImpl{
fn drop(&mut self){
info!("come in to drop for ContextImpl");
// remove the new memory set to the recorder (deprecated in the latest version)
/*
let id = memory_set_record().iter()
.position(|x| unsafe{(*(x.clone() as *mut MemorySet)).token() == self.memory_set.token()});
if id.is_some(){
info!("remove id {:x?}", id.unwrap());
memory_set_record().remove(id.unwrap());
}
*/
//set the user Memory pages in the memory set unswappable
let Self {ref mut arch, ref mut memory_set, ref mut kstack, ..} = self;
let pt = {
@ -210,7 +200,7 @@ impl Drop for ContextImpl{
for page in Page::range_of(area.get_start_addr(), area.get_end_addr()) {
let addr = page.start_address();
unsafe {
active_table_swap().remove_from_swappable(pt, addr, || alloc_frame().unwrap());
active_table_swap().remove_from_swappable(pt, addr, || alloc_frame().expect("alloc frame failed"));
}
}
}

Loading…
Cancel
Save