fix DelayHandler & MemoryAttr

toolchain_update
WangRunji 6 years ago
parent 704af94211
commit 557f021c08

@ -21,8 +21,8 @@ impl<T: FrameAllocator> MemoryHandler for Delay<T> {
let entry = pt.get_entry(addr).expect("failed to get entry"); let entry = pt.get_entry(addr).expect("failed to get entry");
if entry.present() { if entry.present() {
self.allocator.dealloc(entry.target()); self.allocator.dealloc(entry.target());
pt.unmap(addr);
} }
pt.unmap(addr);
} }
fn page_fault_handler(&self, pt: &mut PageTable, addr: VirtAddr) -> bool { fn page_fault_handler(&self, pt: &mut PageTable, addr: VirtAddr) -> bool {
@ -33,8 +33,7 @@ impl<T: FrameAllocator> MemoryHandler for Delay<T> {
} }
let frame = self.allocator.alloc().expect("failed to alloc frame"); let frame = self.allocator.alloc().expect("failed to alloc frame");
entry.set_target(frame); entry.set_target(frame);
entry.set_present(true); self.flags.apply(entry);
entry.update();
true true
} }
} }

@ -83,7 +83,6 @@ pub struct MemoryAttr {
readonly: bool, readonly: bool,
execute: bool, execute: bool,
mmio: bool, mmio: bool,
hide: bool,
} }
impl MemoryAttr { impl MemoryAttr {
@ -116,26 +115,18 @@ impl MemoryAttr {
self 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 ** @brief apply the memory attribute to a page table entry
** @param entry: &mut impl Entry ** @param entry: &mut impl Entry
** the page table entry to apply the attribute ** the page table entry to apply the attribute
** @retval none ** @retval none
*/ */
fn apply(&self, entry: &mut Entry) { pub fn apply(&self, entry: &mut Entry) {
if self.user { entry.set_user(true); } entry.set_present(true);
if self.readonly { entry.set_writable(false); } entry.set_user(self.user);
if self.execute { entry.set_execute(true); } entry.set_writable(!self.readonly);
if self.mmio { entry.set_mmio(true); } entry.set_execute(self.execute);
if self.hide { entry.set_present(false); } entry.set_mmio(self.mmio);
if self.user || self.readonly || self.execute || self.mmio || self.hide { entry.update(); } entry.update();
} }
} }

@ -116,8 +116,8 @@ impl Entry for PageEntry {
} }
fn execute(&self) -> bool { !self.0.flags().contains(EF::NO_EXECUTE) } 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 set_execute(&mut self, value: bool) { self.as_flags().set(EF::NO_EXECUTE, !value); }
fn mmio(&self) -> bool { unimplemented!() } fn mmio(&self) -> bool { false }
fn set_mmio(&mut self, value: bool) { unimplemented!() } fn set_mmio(&mut self, value: bool) { }
} }
fn get_entry_ptr(addr: usize, level: u8) -> *mut PageEntry { fn get_entry_ptr(addr: usize, level: u8) -> *mut PageEntry {

Loading…
Cancel
Save