sel4/arch/arm/
vm_attributes.rs

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: MIT
//

use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not};

use crate::{newtype_methods, sys};

/// Corresponds to `seL4_ARM_VMAttributes`.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct VmAttributes(sys::seL4_ARM_VMAttributes::Type);

impl VmAttributes {
    pub const NONE: Self = Self::from_inner(0);
    pub const DEFAULT: Self =
        Self::from_inner(sys::seL4_ARM_VMAttributes::seL4_ARM_Default_VMAttributes);
    pub const PAGE_CACHEABLE: Self =
        Self::from_inner(sys::seL4_ARM_VMAttributes::seL4_ARM_PageCacheable);
    pub const PARITY_ENABLED: Self =
        Self::from_inner(sys::seL4_ARM_VMAttributes::seL4_ARM_ParityEnabled);
    pub const EXECUTE_NEVER: Self =
        Self::from_inner(sys::seL4_ARM_VMAttributes::seL4_ARM_ExecuteNever);

    newtype_methods!(pub sys::seL4_ARM_VMAttributes::Type);

    pub const fn has(self, rhs: Self) -> bool {
        self.into_inner() & rhs.into_inner() != 0
    }
}

impl Default for VmAttributes {
    fn default() -> Self {
        Self::DEFAULT
    }
}

impl Not for VmAttributes {
    type Output = Self;
    fn not(self) -> Self {
        Self::from_inner(self.into_inner().not())
    }
}

impl BitOr for VmAttributes {
    type Output = Self;
    fn bitor(self, rhs: Self) -> Self {
        Self::from_inner(self.into_inner().bitor(rhs.into_inner()))
    }
}

impl BitOrAssign for VmAttributes {
    fn bitor_assign(&mut self, rhs: Self) {
        self.inner_mut().bitor_assign(rhs.into_inner());
    }
}

impl BitAnd for VmAttributes {
    type Output = Self;
    fn bitand(self, rhs: Self) -> Self {
        Self::from_inner(self.into_inner().bitand(rhs.into_inner()))
    }
}

impl BitAndAssign for VmAttributes {
    fn bitand_assign(&mut self, rhs: Self) {
        self.inner_mut().bitand_assign(rhs.into_inner());
    }
}