You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
695 B
24 lines
695 B
//! Helper functions
|
|
|
|
use super::*;
|
|
|
|
pub trait PageTableExt: PageTable {
|
|
// Take some special care here.
|
|
// TEMP_PAGE_ADDR mapping might be overwritten in the `f` below.
|
|
// So this should be really high in kernel space when necessary.
|
|
const TEMP_PAGE_ADDR: VirtAddr = 0xcafeb000;
|
|
|
|
fn with_temporary_map<T, D>(
|
|
&mut self,
|
|
target: PhysAddr,
|
|
f: impl FnOnce(&mut Self, &mut D) -> T,
|
|
) -> T {
|
|
self.map(Self::TEMP_PAGE_ADDR, target);
|
|
let data =
|
|
unsafe { &mut *(self.get_page_slice_mut(Self::TEMP_PAGE_ADDR).as_ptr() as *mut D) };
|
|
let ret = f(self, data);
|
|
self.unmap(Self::TEMP_PAGE_ADDR);
|
|
ret
|
|
}
|
|
}
|