use super::{
KernelEndpointHeader, Lane, NonNull, PackedEndpointHandle, PublicKernelEndpoint, SessionId,
};
impl<'cfg, T, U, C, const MAX_RV: usize> crate::integration::SessionKit<'cfg, T, U, C, MAX_RV>
where
T: crate::transport::Transport + 'cfg,
U: crate::runtime::consts::LabelUniverse + 'cfg,
C: crate::runtime::config::Clock + 'cfg,
{
pub(super) unsafe fn drop_public_endpoint_raw<const ROLE: u8>(
ptr: NonNull<()>,
handle: PackedEndpointHandle,
) {
let Some(endpoint) = (unsafe {
Self::public_endpoint_ptr_from_header::<'cfg, ROLE>(ptr, handle)
}) else {
return;
};
unsafe {
core::ptr::drop_in_place(endpoint);
}
}
pub(super) unsafe fn prepare_revoke_public_endpoint_raw<const ROLE: u8>(
ptr: NonNull<()>,
sid: SessionId,
lanes: *mut Lane,
lane_capacity: usize,
terminal: *mut (),
) -> usize {
let header = unsafe { ptr.cast::<KernelEndpointHeader<'cfg>>().as_ref() };
if header.role() != ROLE || header.generation() == 0 {
return 0;
}
let endpoint = ptr
.cast::<PublicKernelEndpoint<'cfg, ROLE, T, U, C, MAX_RV>>()
.as_ptr();
let endpoint = unsafe { &mut *endpoint };
if !endpoint.matches_session(sid) {
return 0;
}
let mut released = 0usize;
endpoint.for_each_physical_lane(|owned_lane| {
if released < lane_capacity {
unsafe {
lanes.add(released).write(owned_lane);
}
}
released += 1;
});
debug_assert!(
released <= lane_capacity,
"public endpoint revoke lane buffer must cover every owned lane"
);
let terminal = unsafe {
&mut *terminal.cast::<crate::endpoint::kernel::EndpointRevocationTerminal<'cfg>>()
};
endpoint.prepare_public_owner_revocation(terminal);
core::cmp::min(released, lane_capacity)
}
pub(super) unsafe fn finish_revoke_public_endpoint_raw<const ROLE: u8>(
ptr: NonNull<()>,
sid: SessionId,
) {
let header = unsafe { ptr.cast::<KernelEndpointHeader<'cfg>>().as_ref() };
if header.role() != ROLE || header.generation() == 0 {
return;
}
let endpoint = ptr
.cast::<PublicKernelEndpoint<'cfg, ROLE, T, U, C, MAX_RV>>()
.as_ptr();
let endpoint = unsafe { &mut *endpoint };
if endpoint.matches_session(sid) {
endpoint.finish_public_owner_revocation();
}
}
}