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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use super::{Context, NonNull, OutSlot, PackedEndpointHandle, Poll};
impl<'cfg, T> crate::runtime::SessionKit<'cfg, T>
where
T: crate::transport::Transport + 'cfg,
{
pub(super) unsafe fn preview_public_send<const ROLE: u8>(
ptr: NonNull<()>,
handle: PackedEndpointHandle,
logical_label: u8,
out: *mut crate::endpoint::kernel::SendPreview,
) -> crate::endpoint::SendResult<()> {
unsafe {
// SAFETY: preview-send owns the carrier endpoint slot selected by
// `handle` for this call and writes only the caller-provided
// `SendPreview` out slot before returning.
Self::with_public_endpoint_mut::<'_, ROLE, _>(
ptr,
handle,
Err(crate::endpoint::SendError::Transport(
crate::transport::TransportError::Failed,
)),
|kernel| {
let preview = kernel.preview_send_meta(logical_label)?;
OutSlot::new(out).write(preview);
Ok(())
},
)
}
}
pub(super) unsafe fn init_public_send_state_raw<const ROLE: u8>(
ptr: NonNull<()>,
handle: PackedEndpointHandle,
init: *const crate::endpoint::kernel::SendInit,
) -> crate::endpoint::kernel::PublicOpLease {
let init = unsafe {
// SAFETY: caller provides the initialized send-state descriptor for
// this callback invocation.
&*init
};
unsafe {
// SAFETY: send-state initialization owns the carrier endpoint slot
// selected by `handle`; `init` is read during this call and not
// stored through the raw pointer.
Self::with_public_endpoint_mut::<'cfg, ROLE, _>(
ptr,
handle,
crate::endpoint::kernel::PublicOpLease::Rejected,
|kernel| kernel.init_public_send_state(init),
)
}
}
pub(super) unsafe fn reset_public_send_state_raw<const ROLE: u8>(
ptr: NonNull<()>,
handle: PackedEndpointHandle,
) {
unsafe {
// SAFETY: send-state reset owns the carrier endpoint slot selected
// by `handle` and clears only the resident public send state.
Self::with_public_endpoint_mut::<'cfg, ROLE, _>(ptr, handle, (), |kernel| {
kernel.reset_public_send_state();
});
}
}
pub(super) unsafe fn poll_send_public_endpoint<const ROLE: u8>(
ptr: NonNull<()>,
handle: PackedEndpointHandle,
payload: Option<crate::endpoint::kernel::RawSendPayload>,
cx: &mut Context<'_>,
out: *mut (),
) {
let poll = unsafe {
// SAFETY: send polling owns the carrier endpoint slot selected by
// `handle`; the payload option is consumed inside this single poll
// and the result is written to `out` after the callback returns.
Self::with_public_endpoint_mut::<'cfg, ROLE, _>(
ptr,
handle,
Poll::Ready(Err(crate::endpoint::SendError::Transport(
crate::transport::TransportError::Failed,
))),
|kernel| kernel.poll_public_send(cx, payload),
)
};
OutSlot::erased::<
Poll<crate::endpoint::SendResult<crate::endpoint::kernel::SendCommitOutcome<'cfg>>>,
>(out)
.write(poll);
}
}