Skip to main content

dope_sys/memory/
raw.rs

1use std::num;
2
3use o3::{base::num::bounded, buffer::bytes::bounded::MAX};
4
5/// # Safety
6/// Copies preserve values. Entries are in 2..=32768; capacity <= `o3::buffer::bytes::bounded::MAX`.
7/// The product of entry count and capacity is at most `isize::MAX`.
8pub unsafe trait Layout: Copy {
9    fn entries(self) -> num::NonZero<u16>;
10    fn capacity(self) -> num::NonZero<u32>;
11}
12
13/// Exact bounded lengths carried by pending and completed receive owners.
14///
15/// # Safety
16/// Conversions preserve the exact ABI-bounded count and nonzero capacity.
17pub unsafe trait Extent {
18    type Length: Copy
19        + From<bounded::raw::U32<0, { MAX as u32 }>>
20        + Into<bounded::raw::U32<0, { MAX as u32 }>>;
21    type Capacity: Copy + Into<num::NonZero<u32>>;
22}
23
24/// A receive layout retaining its original capacity proof.
25///
26/// # Safety
27/// `limit` must expose exactly the same capacity as `Layout::capacity`.
28pub unsafe trait Receive: Layout {
29    type Extent: Extent;
30
31    fn limit(self) -> <Self::Extent as Extent>::Capacity;
32}
33
34/// Fixed receive storage used by native capability canaries.
35/// # Safety
36/// `LAYOUT` has two slots so that multishot probes exercise slot reuse.
37pub unsafe trait Canary: Receive {
38    const LAYOUT: Self;
39}
40
41/// Returns a receive slot to its original native storage owner.
42pub trait Release<T> {
43    /// # Safety
44    /// The buffer is unique, has no live projections, and was issued by this owner.
45    /// Retain that storage until the return is consumed or published.
46    unsafe fn release(&mut self, buffer: T);
47}