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
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: MIT
//

use crate::{newtype_methods, sys, Word, WORD_SIZE};

/// Corresponds to `seL4_CNode_CapData`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CNodeCapData(sys::seL4_CNode_CapData);

impl CNodeCapData {
    newtype_methods!(pub sys::seL4_CNode_CapData);

    pub fn new(guard: Word, guard_size: usize) -> Self {
        Self::from_inner(sys::seL4_CNode_CapData::new(
            guard,
            guard_size.try_into().unwrap(),
        ))
    }

    pub fn skip(num_bits: usize) -> Self {
        Self::new(0, num_bits)
    }

    pub fn skip_high_bits(cnode_size_bits: usize) -> Self {
        Self::skip(WORD_SIZE - cnode_size_bits)
    }

    pub fn into_word(self) -> Word {
        let [word] = self.into_inner().0.into_inner();
        word
    }
}