sel4/arch/riscv/
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_RISCV_VMAttributes`.
12#[derive(Debug, Copy, Clone, PartialEq, Eq)]
13pub struct VmAttributes(sys::seL4_RISCV_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_RISCV_VMAttributes::seL4_RISCV_Default_VMAttributes);
19    pub const EXECUTE_NEVER: Self =
20        Self::from_inner(sys::seL4_RISCV_VMAttributes::seL4_RISCV_ExecuteNever);
21
22    newtype_methods!(pub sys::seL4_RISCV_VMAttributes::Type);
23
24    pub const fn has(self, rhs: Self) -> bool {
25        self.into_inner() & rhs.into_inner() != 0
26    }
27}
28
29impl Default for VmAttributes {
30    fn default() -> Self {
31        Self::DEFAULT
32    }
33}
34
35impl Not for VmAttributes {
36    type Output = Self;
37    fn not(self) -> Self {
38        Self::from_inner(self.into_inner().not())
39    }
40}
41
42impl BitOr for VmAttributes {
43    type Output = Self;
44    fn bitor(self, rhs: Self) -> Self {
45        Self::from_inner(self.into_inner().bitor(rhs.into_inner()))
46    }
47}
48
49impl BitOrAssign for VmAttributes {
50    fn bitor_assign(&mut self, rhs: Self) {
51        self.inner_mut().bitor_assign(rhs.into_inner());
52    }
53}
54
55impl BitAnd for VmAttributes {
56    type Output = Self;
57    fn bitand(self, rhs: Self) -> Self {
58        Self::from_inner(self.into_inner().bitand(rhs.into_inner()))
59    }
60}
61
62impl BitAndAssign for VmAttributes {
63    fn bitand_assign(&mut self, rhs: Self) {
64        self.inner_mut().bitand_assign(rhs.into_inner());
65    }
66}