Skip to content

Commit 4bb641f

Browse files
committed
Add remaining WithMRs variants and wrappers
Add WithMRs variants at the sys level for: NBRecv, ReplyRecv, and (MCS-only) NBSendRecv, NBSendWait, NBWait. Add high-level wrappers for every IPC syscall that was missing one: - Endpoint: nb_send_with_mrs, nb_recv_with_mrs, reply_recv_with_mrs - Notification: wait_with_mrs, nb_wait, nb_wait_with_mrs, poll - Cap<T>: nb_send_recv_with_mrs, nb_send_wait, nb_send_wait_with_mrs - Standalone: reply_with_mrs Signed-off-by: Mark Old <mold@redhat.com>
1 parent 99e3dda commit 4bb641f

2 files changed

Lines changed: 440 additions & 0 deletions

File tree

crates/sel4/src/syscalls.rs

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ impl<C: InvocationContext> cap::Endpoint<C> {
6767
})
6868
}
6969

70+
pub fn nb_send_with_mrs<T: FastMessages>(self, info: MessageInfo, messages: T) {
71+
let [msg0, msg1, msg2, msg3] = messages.prepare_in();
72+
self.invoke(|cptr, ipc_buffer| {
73+
ipc_buffer.inner_mut().seL4_NBSendWithMRs(
74+
cptr.bits(),
75+
info.into_inner(),
76+
msg0,
77+
msg1,
78+
msg2,
79+
msg3,
80+
)
81+
})
82+
}
83+
7084
/// Corresponds to `seL4_Recv`.
7185
pub fn recv(self, reply_authority: impl ConveysReplyAuthority) -> (MessageInfo, Badge) {
7286
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
@@ -134,6 +148,28 @@ impl<C: InvocationContext> cap::Endpoint<C> {
134148
})
135149
}
136150

151+
pub fn nb_recv_with_mrs(self, reply_authority: impl ConveysReplyAuthority) -> RecvWithMRs {
152+
let mut msg = [0; NUM_FAST_MESSAGE_REGISTERS];
153+
let [mr0, mr1, mr2, mr3] = &mut msg;
154+
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
155+
ipc_buffer.inner_mut().seL4_NBRecvWithMRs(
156+
cptr.bits(),
157+
Some(mr0),
158+
Some(mr1),
159+
Some(mr2),
160+
Some(mr3),
161+
reply_authority
162+
.into_reply_authority()
163+
.into_sys_reply_authority(),
164+
)
165+
});
166+
RecvWithMRs {
167+
info: MessageInfo::from_inner(raw_msg_info),
168+
badge,
169+
msg,
170+
}
171+
}
172+
137173
pub fn recv_with_mrs(self, reply_authority: impl ConveysReplyAuthority) -> RecvWithMRs {
138174
let mut msg = [0; NUM_FAST_MESSAGE_REGISTERS];
139175
let [mr0, mr1, mr2, mr3] = &mut msg;
@@ -156,6 +192,34 @@ impl<C: InvocationContext> cap::Endpoint<C> {
156192
}
157193
}
158194

195+
pub fn reply_recv_with_mrs<T: FastMessages>(
196+
self,
197+
info: MessageInfo,
198+
messages: T,
199+
reply_authority: impl ConveysReplyAuthority,
200+
) -> RecvWithMRs {
201+
let mut msg = messages.prepare_in_out();
202+
let [mr0, mr1, mr2, mr3] = &mut msg;
203+
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
204+
ipc_buffer.inner_mut().seL4_ReplyRecvWithMRs(
205+
cptr.bits(),
206+
info.into_inner(),
207+
Some(mr0),
208+
Some(mr1),
209+
Some(mr2),
210+
Some(mr3),
211+
reply_authority
212+
.into_reply_authority()
213+
.into_sys_reply_authority(),
214+
)
215+
});
216+
RecvWithMRs {
217+
info: MessageInfo::from_inner(raw_msg_info),
218+
badge,
219+
msg,
220+
}
221+
}
222+
159223
pub fn call_with_mrs<T: FastMessages>(self, info: MessageInfo, messages: T) -> CallWithMRs {
160224
let mut msg = messages.prepare_in_out();
161225
let [mr0, mr1, mr2, mr3] = &mut msg;
@@ -188,6 +252,61 @@ impl<C: InvocationContext> cap::Notification<C> {
188252
self.invoke(|cptr, ipc_buffer| ipc_buffer.inner_mut().seL4_Wait(cptr.bits()));
189253
(wait_message_info_from_sys(info), badge)
190254
}
255+
256+
#[sel4_cfg(KERNEL_MCS)]
257+
pub fn wait_with_mrs(self) -> WaitWithMRs {
258+
let mut msg = [0; NUM_FAST_MESSAGE_REGISTERS];
259+
let [mr0, mr1, mr2, mr3] = &mut msg;
260+
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
261+
ipc_buffer.inner_mut().seL4_WaitWithMRs(
262+
cptr.bits(),
263+
Some(mr0),
264+
Some(mr1),
265+
Some(mr2),
266+
Some(mr3),
267+
)
268+
});
269+
WaitWithMRs {
270+
info: wait_message_info_from_sys(raw_msg_info),
271+
badge,
272+
msg,
273+
}
274+
}
275+
276+
/// Corresponds to `seL4_NBWait`.
277+
#[sel4_cfg(KERNEL_MCS)]
278+
pub fn nb_wait(self) -> (WaitMessageInfo, Badge) {
279+
let (info, badge) =
280+
self.invoke(|cptr, ipc_buffer| ipc_buffer.inner_mut().seL4_NBWait(cptr.bits()));
281+
(wait_message_info_from_sys(info), badge)
282+
}
283+
284+
#[sel4_cfg(KERNEL_MCS)]
285+
pub fn nb_wait_with_mrs(self) -> WaitWithMRs {
286+
let mut msg = [0; NUM_FAST_MESSAGE_REGISTERS];
287+
let [mr0, mr1, mr2, mr3] = &mut msg;
288+
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
289+
ipc_buffer.inner_mut().seL4_NBWaitWithMRs(
290+
cptr.bits(),
291+
Some(mr0),
292+
Some(mr1),
293+
Some(mr2),
294+
Some(mr3),
295+
)
296+
});
297+
WaitWithMRs {
298+
info: wait_message_info_from_sys(raw_msg_info),
299+
badge,
300+
msg,
301+
}
302+
}
303+
304+
/// Corresponds to `seL4_Poll`.
305+
pub fn poll(self) -> (MessageInfo, Badge) {
306+
let (raw_msg_info, badge) =
307+
self.invoke(|cptr, ipc_buffer| ipc_buffer.inner_mut().seL4_Poll(cptr.bits()));
308+
(MessageInfo::from_inner(raw_msg_info), badge)
309+
}
191310
}
192311

193312
#[sel4_cfg(KERNEL_MCS)]
@@ -224,6 +343,81 @@ impl<T: IpcCapType, C: InvocationContext> Cap<T, C> {
224343
});
225344
(MessageInfo::from_inner(raw_msg_info), badge)
226345
}
346+
347+
/// Corresponds to `seL4_NBSendRecvWithMRs`.
348+
#[sel4_cfg(KERNEL_MCS)]
349+
pub fn nb_send_recv_with_mrs<U: IpcCapType, M: FastMessages>(
350+
self,
351+
info: MessageInfo,
352+
messages: M,
353+
src: Cap<U>,
354+
reply_authority: impl ConveysReplyAuthority,
355+
) -> RecvWithMRs {
356+
let mut msg = messages.prepare_in_out();
357+
let [mr0, mr1, mr2, mr3] = &mut msg;
358+
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
359+
ipc_buffer.inner_mut().seL4_NBSendRecvWithMRs(
360+
cptr.bits(),
361+
info.into_inner(),
362+
src.bits(),
363+
Some(mr0),
364+
Some(mr1),
365+
Some(mr2),
366+
Some(mr3),
367+
reply_authority
368+
.into_reply_authority()
369+
.into_sys_reply_authority(),
370+
)
371+
});
372+
RecvWithMRs {
373+
info: MessageInfo::from_inner(raw_msg_info),
374+
badge,
375+
msg,
376+
}
377+
}
378+
379+
/// Corresponds to `seL4_NBSendWait`.
380+
#[sel4_cfg(KERNEL_MCS)]
381+
pub fn nb_send_wait<U: IpcCapType>(
382+
self,
383+
info: MessageInfo,
384+
src: Cap<U>,
385+
) -> (MessageInfo, Badge) {
386+
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
387+
ipc_buffer
388+
.inner_mut()
389+
.seL4_NBSendWait(cptr.bits(), info.into_inner(), src.bits())
390+
});
391+
(MessageInfo::from_inner(raw_msg_info), badge)
392+
}
393+
394+
/// Corresponds to `seL4_NBSendWaitWithMRs`.
395+
#[sel4_cfg(KERNEL_MCS)]
396+
pub fn nb_send_wait_with_mrs<U: IpcCapType, M: FastMessages>(
397+
self,
398+
info: MessageInfo,
399+
messages: M,
400+
src: Cap<U>,
401+
) -> RecvWithMRs {
402+
let mut msg = messages.prepare_in_out();
403+
let [mr0, mr1, mr2, mr3] = &mut msg;
404+
let (raw_msg_info, badge) = self.invoke(|cptr, ipc_buffer| {
405+
ipc_buffer.inner_mut().seL4_NBSendWaitWithMRs(
406+
cptr.bits(),
407+
info.into_inner(),
408+
src.bits(),
409+
Some(mr0),
410+
Some(mr1),
411+
Some(mr2),
412+
Some(mr3),
413+
)
414+
});
415+
RecvWithMRs {
416+
info: MessageInfo::from_inner(raw_msg_info),
417+
badge,
418+
msg,
419+
}
420+
}
227421
}
228422

229423
/// Corresponds to `seL4_Reply`.
@@ -232,6 +426,16 @@ pub fn reply(ipc_buffer: &mut IpcBuffer, info: MessageInfo) {
232426
ipc_buffer.inner_mut().seL4_Reply(info.into_inner())
233427
}
234428

429+
/// Corresponds to `seL4_ReplyWithMRs`.
430+
#[sel4_cfg(not(KERNEL_MCS))]
431+
#[allow(dead_code)]
432+
pub fn reply_with_mrs<T: FastMessages>(ipc_buffer: &mut IpcBuffer, info: MessageInfo, messages: T) {
433+
let [msg0, msg1, msg2, msg3] = messages.prepare_in();
434+
ipc_buffer
435+
.inner_mut()
436+
.seL4_ReplyWithMRs(info.into_inner(), msg0, msg1, msg2, msg3)
437+
}
438+
235439
/// Corresponds to `seL4_Yield`.
236440
pub fn r#yield() {
237441
sys::seL4_Yield()
@@ -260,6 +464,14 @@ pub struct CallWithMRs {
260464
pub msg: [Word; NUM_FAST_MESSAGE_REGISTERS],
261465
}
262466

467+
/// The result of [`cap::Notification::wait_with_mrs`].
468+
#[sel4_cfg(KERNEL_MCS)]
469+
pub struct WaitWithMRs {
470+
pub info: WaitMessageInfo,
471+
pub badge: Badge,
472+
pub msg: [Word; NUM_FAST_MESSAGE_REGISTERS],
473+
}
474+
263475
type ConcreteFastMessagesForIn = [Option<Word>; NUM_FAST_MESSAGE_REGISTERS];
264476

265477
type ConcreteFastMessagesForInOut = [Word; NUM_FAST_MESSAGE_REGISTERS];

0 commit comments

Comments
 (0)