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
#![no_std]
#![feature(asm, decl_macro, const_generics, unsafe_block_in_unsafe_fn, never_type)]
#![deny(unsafe_op_in_unsafe_fn)]
pub mod caps;
pub mod syscall;
#[cfg(feature = "can_alloc")]
pub mod channel;
#[cfg(feature = "can_alloc")]
pub mod early_logger;
#[cfg(feature = "can_alloc")]
extern crate alloc;
use core::{convert::TryFrom, num::TryFromIntError};
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct Handle(pub u32);
pub const ZERO_HANDLE: Handle = Handle(0);
impl TryFrom<usize> for Handle {
type Error = TryFromIntError;
fn try_from(value: usize) -> Result<Self, Self::Error> {
Ok(Handle(u32::try_from(value)?))
}
}
#[cfg(feature = "ptah")]
impl ptah::Serialize for Handle {
fn serialize<W>(&self, serializer: &mut ptah::Serializer<W>) -> ptah::ser::Result<()>
where
W: ptah::Writer,
{
serializer.serialize_handle(self.0 as ptah::Handle)
}
}
#[cfg(feature = "ptah")]
impl<'de> ptah::Deserialize<'de> for Handle {
fn deserialize(deserializer: &mut ptah::Deserializer<'de>) -> ptah::de::Result<Handle> {
Ok(Handle(deserializer.deserialize_handle()?))
}
}
bitflags::bitflags! {
struct HandleRights: u32 {
const MODIFY = 0b1;
const DUPLICATE = 0b10;
const TRANSFER = 0b100;
const MAP = 0x1000;
const SEND = 0x1_0000;
const RECEIVE = 0x10_0000;
}
}