sel4_sys/
ipc_buffer.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
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

use core::mem;
use core::ops::Range;
use core::slice;

use sel4_bitfield_ops::{get_bits, set_bits, set_bits_from_slice, PrimInt, UnsignedPrimInt};

use crate::{seL4_CPtr, seL4_IPCBuffer, seL4_Word};

impl seL4_IPCBuffer {
    pub(crate) fn get_mr(&self, i: usize) -> seL4_Word {
        self.msg[i]
    }

    pub(crate) fn set_mr(&mut self, i: usize, value: seL4_Word) {
        self.msg[i] = value;
    }

    pub(crate) fn get_mr_bits<T>(&self, range: Range<usize>) -> T
    where
        T: PrimInt,
        T::Unsigned: TryFrom<seL4_Word>,
    {
        T::cast_from_unsigned(get_bits(&self.msg, range))
    }

    pub(crate) fn set_mr_bits<T>(&mut self, range: Range<usize>, value: T)
    where
        T: PrimInt,
        T::Unsigned: TryInto<seL4_Word>,
    {
        set_bits(&mut self.msg, range, T::cast_to_unsigned(value))
    }

    pub(crate) fn set_mr_bits_from_slice<T>(&mut self, range: Range<usize>, value: &[T])
    where
        T: UnsignedPrimInt,
        usize: TryFrom<T>,
    {
        set_bits_from_slice(&mut self.msg, range, value, 0)
    }

    #[allow(dead_code)]
    pub(crate) fn msg_bytes_mut(&mut self) -> &'static mut [u8] {
        let msg = &mut self.msg;
        unsafe {
            slice::from_raw_parts_mut(
                msg.as_mut_ptr().cast::<u8>(),
                msg.len() * mem::size_of::<seL4_Word>(),
            )
        }
    }

    #[allow(dead_code)]
    pub(crate) fn get_cap(&self, i: usize) -> seL4_CPtr {
        self.caps_or_badges[i]
    }

    pub(crate) fn set_cap(&mut self, i: usize, cptr: seL4_CPtr) {
        self.caps_or_badges[i] = cptr;
    }
}