use core::{ marker::PhantomData, mem, }; use crate::{ Arch, VirtualAddress, }; #[must_use = "The page table must be flushed, or the changes unsafely ignored"] pub struct PageFlush { virt: VirtualAddress, phantom: PhantomData, } impl PageFlush { pub fn new(virt: VirtualAddress) -> Self { Self { virt, phantom: PhantomData, } } pub fn flush(self) { unsafe { A::invalidate(self.virt); } } pub unsafe fn ignore(self) { mem::forget(self); } } #[must_use = "The page table must be flushed, or the changes unsafely ignored"] pub struct PageFlushAll { phantom: PhantomData, } impl PageFlushAll { pub fn new() -> Self { Self { phantom: PhantomData, } } pub fn consume(&self, flush: PageFlush) { unsafe { flush.ignore(); } } pub fn flush(self) { unsafe { A::invalidate_all(); } } pub unsafe fn ignore(self) { mem::forget(self); } }