From 557f021c087224159ef94ebd2d88a70bfc3c6817 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 14 Dec 2018 02:26:37 +0800 Subject: [PATCH] fix DelayHandler & MemoryAttr --- crate/memory/src/memory_set/handler/delay.rs | 5 ++--- crate/memory/src/memory_set/mod.rs | 23 ++++++-------------- kernel/src/arch/x86_64/paging.rs | 4 ++-- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/crate/memory/src/memory_set/handler/delay.rs b/crate/memory/src/memory_set/handler/delay.rs index af3003f..1a424a7 100644 --- a/crate/memory/src/memory_set/handler/delay.rs +++ b/crate/memory/src/memory_set/handler/delay.rs @@ -21,8 +21,8 @@ impl MemoryHandler for Delay { let entry = pt.get_entry(addr).expect("failed to get entry"); if entry.present() { self.allocator.dealloc(entry.target()); + pt.unmap(addr); } - pt.unmap(addr); } fn page_fault_handler(&self, pt: &mut PageTable, addr: VirtAddr) -> bool { @@ -33,8 +33,7 @@ impl MemoryHandler for Delay { } let frame = self.allocator.alloc().expect("failed to alloc frame"); entry.set_target(frame); - entry.set_present(true); - entry.update(); + self.flags.apply(entry); true } } diff --git a/crate/memory/src/memory_set/mod.rs b/crate/memory/src/memory_set/mod.rs index c474151..5582aae 100644 --- a/crate/memory/src/memory_set/mod.rs +++ b/crate/memory/src/memory_set/mod.rs @@ -83,7 +83,6 @@ pub struct MemoryAttr { readonly: bool, execute: bool, mmio: bool, - hide: bool, } impl MemoryAttr { @@ -116,26 +115,18 @@ impl MemoryAttr { self } /* - ** @brief set the memory attribute's hide bit - ** @retval MemoryAttr the memory attribute itself - */ - pub fn hide(mut self) -> Self { - self.hide = true; - self - } - /* ** @brief apply the memory attribute to a page table entry ** @param entry: &mut impl Entry ** the page table entry to apply the attribute ** @retval none */ - fn apply(&self, entry: &mut Entry) { - if self.user { entry.set_user(true); } - if self.readonly { entry.set_writable(false); } - if self.execute { entry.set_execute(true); } - if self.mmio { entry.set_mmio(true); } - if self.hide { entry.set_present(false); } - if self.user || self.readonly || self.execute || self.mmio || self.hide { entry.update(); } + pub fn apply(&self, entry: &mut Entry) { + entry.set_present(true); + entry.set_user(self.user); + entry.set_writable(!self.readonly); + entry.set_execute(self.execute); + entry.set_mmio(self.mmio); + entry.update(); } } diff --git a/kernel/src/arch/x86_64/paging.rs b/kernel/src/arch/x86_64/paging.rs index 76c89e4..0ae779d 100644 --- a/kernel/src/arch/x86_64/paging.rs +++ b/kernel/src/arch/x86_64/paging.rs @@ -116,8 +116,8 @@ impl Entry for PageEntry { } fn execute(&self) -> bool { !self.0.flags().contains(EF::NO_EXECUTE) } fn set_execute(&mut self, value: bool) { self.as_flags().set(EF::NO_EXECUTE, !value); } - fn mmio(&self) -> bool { unimplemented!() } - fn set_mmio(&mut self, value: bool) { unimplemented!() } + fn mmio(&self) -> bool { false } + fn set_mmio(&mut self, value: bool) { } } fn get_entry_ptr(addr: usize, level: u8) -> *mut PageEntry {