1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::{VmFlags, VmMeta, PPN};
use core::{fmt, marker::PhantomData};
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct Pte<Meta: VmMeta>(pub usize, pub(crate) PhantomData<Meta>);
impl<Meta: VmMeta> Pte<Meta> {
pub const ZERO: Self = Self(0, PhantomData);
#[inline]
pub fn ppn(self) -> PPN<Meta> {
Meta::ppn(self.0)
}
#[inline]
pub fn is_leaf(self) -> bool {
Meta::is_leaf(self.0)
}
#[inline]
pub fn is_huge(self, level: usize) -> bool {
Meta::is_huge(self.0, level)
}
#[inline]
pub fn is_valid(self) -> bool {
Meta::is_valid(self.0)
}
#[inline]
pub fn flags(mut self) -> VmFlags<Meta> {
Meta::clear_ppn(&mut self.0);
unsafe { VmFlags::from_raw(self.0) }
}
}
impl<Meta: VmMeta> fmt::Debug for Pte<Meta> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Pte(")?;
self.0.fmt(f)?;
write!(f, ")")
}
}