2022-07-28 03:39:20 -05:00
|
|
|
//! A handle is a u128 with a set of permissions
|
|
|
|
//! and a resource connected to it
|
|
|
|
|
2022-08-01 06:09:05 -05:00
|
|
|
use crate::arch::generate_process_pass;
|
2022-07-28 03:39:20 -05:00
|
|
|
use core::fmt::Display;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct BinaryData {
|
|
|
|
name: String,
|
|
|
|
data: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
2022-07-28 20:15:02 -05:00
|
|
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
2022-07-28 03:39:20 -05:00
|
|
|
pub enum HandleResource {
|
2022-07-28 20:15:02 -05:00
|
|
|
Channel,
|
|
|
|
Socket,
|
2022-07-29 12:48:45 -05:00
|
|
|
|
2022-07-28 20:15:02 -05:00
|
|
|
BinaryData,
|
2022-07-28 03:39:20 -05:00
|
|
|
}
|
|
|
|
|
2022-07-28 20:15:02 -05:00
|
|
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
2022-07-28 03:39:20 -05:00
|
|
|
pub struct Handle {
|
2022-07-29 06:13:26 -05:00
|
|
|
pub inner: u128,
|
|
|
|
pub res: HandleResource,
|
2022-07-28 03:39:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Handle {
|
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
|
|
write!(f, "Handle-{:032x}", self.inner)?;
|
|
|
|
match &self.res {
|
2022-07-28 20:15:02 -05:00
|
|
|
HandleResource::Channel => write!(f, "-Channel")?,
|
|
|
|
HandleResource::BinaryData => write!(f, "-Binary")?,
|
|
|
|
Socket => write!(f, "-Socket")?,
|
2022-07-28 03:39:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use crate::handle::HandleResource::*;
|
|
|
|
impl Handle {
|
2022-07-28 20:15:02 -05:00
|
|
|
pub fn new(htype: HandleResource) -> Self {
|
2022-07-28 03:39:20 -05:00
|
|
|
Self {
|
|
|
|
inner: generate_process_pass(),
|
2022-07-28 20:15:02 -05:00
|
|
|
res: htype,
|
2022-07-28 03:39:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|