diff --git a/crate/memory/src/memory_set/handler/shared.rs b/crate/memory/src/memory_set/handler/shared.rs index 7ffd8ab3..96dbb549 100644 --- a/crate/memory/src/memory_set/handler/shared.rs +++ b/crate/memory/src/memory_set/handler/shared.rs @@ -28,7 +28,11 @@ impl SharedGuard { self.target.remove(&virtAddr); } pub fn get(&self, addr: usize) -> Option { - Some(self.target.get(&addr).unwrap().clone()) + match self.target.get(&addr) { + Some(physAddr) => Some(physAddr.clone()), + None => None + } + //Some(self.target.get(&addr).unwrap().clone()) } } @@ -47,7 +51,7 @@ impl Drop for SharedGuard { #[derive(Debug, Clone)] pub struct Shared { allocator: T, - guard: Option>>> + guard: Arc>> } impl MemoryHandler for Shared { @@ -57,8 +61,7 @@ impl MemoryHandler for Shared { fn map(&self, pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr) { //assert!(self.guard.is_some(), "remapping memory area") - let guard = self.guard.clone(); - let physAddrOpt = guard.unwrap().lock().get(addr); + let physAddrOpt = self.guard.lock().get(addr); if physAddrOpt.is_none() { // not mapped yet let entry = pt.map(addr, 0); entry.set_present(false); @@ -90,14 +93,13 @@ impl MemoryHandler for Shared { fn handle_page_fault(&self, pt: &mut dyn PageTable, addr: VirtAddr) -> bool { let entry = pt.get_entry(addr).expect("failed to get entry"); - let guard = self.guard.clone(); - let physAddrOpt = guard.clone().unwrap().lock().get(addr); + let physAddrOpt = self.guard.lock().get(addr); if entry.present() { // not a delay case return false; } else if physAddrOpt.is_none() { // physical memory not alloced. - let frame = guard.clone().unwrap().lock().alloc(addr).unwrap(); + let frame = self.guard.lock().alloc(addr).unwrap(); entry.set_target(frame); entry.set_present(true); entry.update(); @@ -124,7 +126,7 @@ impl Shared { pub fn new(allocator: T) -> Self { Shared { allocator: allocator.clone(), - guard: Some(Arc::new(Mutex::new(SharedGuard::new(allocator)))) + guard: Arc::new(Mutex::new(SharedGuard::new(allocator))) } } } \ No newline at end of file diff --git a/user b/user index 5557c941..c62bccb6 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit 5557c941083754f9e6c85de9ea3e101693c9f9c7 +Subproject commit c62bccb6b1866c1faeb113e769786aaa4699434c