use super::*; #[derive(Debug, Clone)] pub struct ByFrame { allocator: T, } impl MemoryHandler for ByFrame { fn box_clone(&self) -> Box { Box::new(self.clone()) } fn map(&self, pt: &mut PageTable, addr: VirtAddr, attr: &MemoryAttr) { let target = self.allocator.alloc().expect("failed to allocate frame"); let entry = pt.map(addr, target); entry.set_present(true); attr.apply(entry); } fn unmap(&self, pt: &mut PageTable, addr: VirtAddr) { let target = pt.get_entry(addr).expect("fail to get entry").target(); self.allocator.dealloc(target); pt.unmap(addr); } fn handle_page_fault(&self, _pt: &mut PageTable, _addr: VirtAddr) -> bool { false } } impl ByFrame { pub fn new(allocator: T) -> Self { ByFrame { allocator } } }