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

use sel4_config::{sel4_cfg, sel4_cfg_if};

use crate::sys;

#[sel4_cfg(KERNEL_MCS)]
use crate::cap;

/// Configuration-dependant alias for conveying reply authority to syscalls.
pub type ReplyAuthority = ReplyAuthorityImpl;

sel4_cfg_if! {
    if #[sel4_cfg(KERNEL_MCS)] {
        pub type ReplyAuthorityImpl = cap::Reply;

        impl ReplyAuthority {
            pub(crate) fn into_sys_reply_authority(self) -> sys::ReplyAuthority {
                self.bits()
            }
        }
    } else {
        pub type ReplyAuthorityImpl = ImplicitReplyAuthority;

        impl ReplyAuthority {
            pub(crate) fn into_sys_reply_authority(self) -> sys::ReplyAuthority {
            }
        }

        /// Under this configuration, no reply authority is required.
        pub struct ImplicitReplyAuthority;

        impl ConveysReplyAuthority for () {
            fn into_reply_authority(self) -> ReplyAuthority {
                ImplicitReplyAuthority
            }
        }
    }
}

/// Trait for types from which [`ReplyAuthority`] can be derived.
pub trait ConveysReplyAuthority {
    fn into_reply_authority(self) -> ReplyAuthority;
}

impl ConveysReplyAuthority for ReplyAuthority {
    fn into_reply_authority(self) -> ReplyAuthority {
        self
    }
}