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 powers of two >= 2; 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::U32<0, { MAX as u32 }>>
20        + Into<bounded::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, each large enough for a `libc::c_int`.
37pub unsafe trait Canary: Receive {
38    const LAYOUT: Self;
39}