sel4/
cnode_cap_data.rs

1//
2// Copyright 2023, Colias Group, LLC
3//
4// SPDX-License-Identifier: MIT
5//
6
7use crate::{newtype_methods, sys, Word, WORD_SIZE};
8
9/// Corresponds to `seL4_CNode_CapData`.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct CNodeCapData(sys::seL4_CNode_CapData);
12
13impl CNodeCapData {
14    newtype_methods!(pub sys::seL4_CNode_CapData);
15
16    pub fn new(guard: Word, guard_size: usize) -> Self {
17        Self::from_inner(sys::seL4_CNode_CapData::new(
18            guard,
19            guard_size.try_into().unwrap(),
20        ))
21    }
22
23    pub fn skip(num_bits: usize) -> Self {
24        Self::new(0, num_bits)
25    }
26
27    pub fn skip_high_bits(cnode_size_bits: usize) -> Self {
28        Self::skip(WORD_SIZE - cnode_size_bits)
29    }
30
31    pub fn into_word(self) -> Word {
32        let [word] = self.into_inner().0.into_inner();
33        word
34    }
35}