sel4/arch/arm/
vm_attributes.rs

1//
2// Copyright 2023, Colias Group, LLC
3//
4// SPDX-License-Identifier: MIT
5//
6
7use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not};
8
9use crate::{newtype_methods, sys};
10
11/// Corresponds to `seL4_ARM_VMAttributes`.
12#[derive(Debug, Copy, Clone, PartialEq, Eq)]
13pub struct VmAttributes(sys::seL4_ARM_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_ARM_VMAttributes::seL4_ARM_Default_VMAttributes);
19    pub const PAGE_CACHEABLE: Self =
20        Self::from_inner(sys::seL4_ARM_VMAttributes::seL4_ARM_PageCacheable);
21    pub const PARITY_ENABLED: Self =
22        Self::from_inner(sys::seL4_ARM_VMAttributes::seL4_ARM_ParityEnabled);
23    pub const EXECUTE_NEVER: Self =
24        Self::from_inner(sys::seL4_ARM_VMAttributes::seL4_ARM_ExecuteNever);
25
26    newtype_methods!(pub sys::seL4_ARM_VMAttributes::Type);
27
28    pub const fn has(self, rhs: Self) -> bool {
29        self.into_inner() & rhs.into_inner() != 0
30    }
31}
32
33impl Default for VmAttributes {
34    fn default() -> Self {
35        Self::DEFAULT
36    }
37}
38
39impl Not for VmAttributes {
40    type Output = Self;
41    fn not(self) -> Self {
42        Self::from_inner(self.into_inner().not())
43    }
44}
45
46impl BitOr for VmAttributes {
47    type Output = Self;
48    fn bitor(self, rhs: Self) -> Self {
49        Self::from_inner(self.into_inner().bitor(rhs.into_inner()))
50    }
51}
52
53impl BitOrAssign for VmAttributes {
54    fn bitor_assign(&mut self, rhs: Self) {
55        self.inner_mut().bitor_assign(rhs.into_inner());
56    }
57}
58
59impl BitAnd for VmAttributes {
60    type Output = Self;
61    fn bitand(self, rhs: Self) -> Self {
62        Self::from_inner(self.into_inner().bitand(rhs.into_inner()))
63    }
64}
65
66impl BitAndAssign for VmAttributes {
67    fn bitand_assign(&mut self, rhs: Self) {
68        self.inner_mut().bitand_assign(rhs.into_inner());
69    }
70}