sel4/arch/x86/
vm_attributes.rs1use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not};
8
9use crate::{newtype_methods, sel4_cfg_if, sys};
10
11#[derive(Debug, Copy, Clone, PartialEq, Eq)]
13pub struct VmAttributes(sys::seL4_X86_VMAttributes::Type);
14
15impl VmAttributes {
16 pub const NONE: Self = Self::from_inner(0);
17 pub const DEFAULT: Self =
18 Self::from_inner(sys::seL4_X86_VMAttributes::seL4_X86_Default_VMAttributes);
19 pub const CACHE_DISABLED: Self =
20 Self::from_inner(sys::seL4_X86_VMAttributes::seL4_X86_CacheDisabled);
21
22 sel4_cfg_if! {
23 if #[sel4_cfg(all(ARCH_X86_64, VTX))] {
24 pub const EPT_DEFAULT: Self =
25 Self::from_inner(sys::seL4_X86_EPT_VMAttributes::seL4_X86_EPT_Default_VMAttributes);
26 pub const EPT_CACHE_DISABLED: Self =
27 Self::from_inner(sys::seL4_X86_EPT_VMAttributes::seL4_X86_EPT_Uncacheable);
28 }
29 }
30
31 newtype_methods!(pub sys::seL4_X86_VMAttributes::Type);
32
33 pub const fn has(self, rhs: Self) -> bool {
34 self.into_inner() & rhs.into_inner() != 0
35 }
36}
37
38impl Default for VmAttributes {
39 fn default() -> Self {
40 Self::DEFAULT
41 }
42}
43
44impl Not for VmAttributes {
45 type Output = Self;
46 fn not(self) -> Self {
47 Self::from_inner(self.into_inner().not())
48 }
49}
50
51impl BitOr for VmAttributes {
52 type Output = Self;
53 fn bitor(self, rhs: Self) -> Self {
54 Self::from_inner(self.into_inner().bitor(rhs.into_inner()))
55 }
56}
57
58impl BitOrAssign for VmAttributes {
59 fn bitor_assign(&mut self, rhs: Self) {
60 self.inner_mut().bitor_assign(rhs.into_inner());
61 }
62}
63
64impl BitAnd for VmAttributes {
65 type Output = Self;
66 fn bitand(self, rhs: Self) -> Self {
67 Self::from_inner(self.into_inner().bitand(rhs.into_inner()))
68 }
69}
70
71impl BitAndAssign for VmAttributes {
72 fn bitand_assign(&mut self, rhs: Self) {
73 self.inner_mut().bitand_assign(rhs.into_inner());
74 }
75}