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