sel4/
reply_authority.rs
1use sel4_config::{sel4_cfg, sel4_cfg_if};
8
9use crate::{sys, NoExplicitInvocationContext};
10
11#[sel4_cfg(KERNEL_MCS)]
12use crate::cap;
13
14#[sel4_cfg(not(KERNEL_MCS))]
15use crate::{InvocationContext, MessageInfo};
16
17pub type ReplyAuthority<C = NoExplicitInvocationContext> = ReplyAuthorityImpl<C>;
19
20sel4_cfg_if! {
21 if #[sel4_cfg(KERNEL_MCS)] {
22 pub type ReplyAuthorityImpl<C> = cap::Reply<C>;
23
24 impl<C> ReplyAuthority<C> {
25 pub(crate) fn into_sys_reply_authority(self) -> sys::ReplyAuthority {
26 self.bits()
27 }
28 }
29 } else {
30 pub type ReplyAuthorityImpl<C> = ImplicitReplyAuthority<C>;
31
32 impl<C> ReplyAuthority<C> {
33 pub(crate) fn into_sys_reply_authority(self) -> sys::ReplyAuthority {
34 }
35 }
36
37 #[derive(Default)]
39 pub struct ImplicitReplyAuthority<C> {
40 invocation_context: C,
41 }
42
43 impl<C> ImplicitReplyAuthority<C> {
44 pub const fn new(invocation_context: C) -> Self {
45 Self {
46 invocation_context,
47 }
48 }
49
50 pub fn into_invocation_context(self) -> C {
51 self.invocation_context
52 }
53 }
54
55 impl<C: InvocationContext> ImplicitReplyAuthority<C> {
56 pub fn reply(self, info: MessageInfo) {
58 self.into_invocation_context()
59 .with_context(|ipc_buffer| ipc_buffer.inner_mut().seL4_Reply(info.into_inner()))
60 }
61 }
62
63 impl ConveysReplyAuthority for () {
64 type C = NoExplicitInvocationContext;
65
66 fn into_reply_authority(self) -> ReplyAuthority<Self::C> {
67 ImplicitReplyAuthority::default()
68 }
69 }
70 }
71}
72
73pub trait ConveysReplyAuthority {
75 type C;
76
77 fn into_reply_authority(self) -> ReplyAuthority<Self::C>;
78}
79
80impl<C> ConveysReplyAuthority for ReplyAuthority<C> {
81 type C = C;
82
83 fn into_reply_authority(self) -> ReplyAuthority<Self::C> {
84 self
85 }
86}