forked from AbleOS/ableos
49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
//! A handle is a u128 with a set of permissions
|
|
//! and a resource connected to it
|
|
|
|
use crate::Path;
|
|
use crate::{arch::generate_process_pass, channels::Channel};
|
|
use core::fmt::Display;
|
|
|
|
#[derive(Debug)]
|
|
pub struct BinaryData {
|
|
name: String,
|
|
data: Vec<u8>,
|
|
}
|
|
|
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
|
pub enum HandleResource {
|
|
Channel,
|
|
Socket,
|
|
BinaryData,
|
|
}
|
|
|
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
|
pub struct Handle {
|
|
pub inner: u128,
|
|
pub res: HandleResource,
|
|
}
|
|
|
|
impl Display for Handle {
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
write!(f, "Handle-{:032x}", self.inner)?;
|
|
match &self.res {
|
|
HandleResource::Channel => write!(f, "-Channel")?,
|
|
HandleResource::BinaryData => write!(f, "-Binary")?,
|
|
Socket => write!(f, "-Socket")?,
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
use crate::handle::HandleResource::*;
|
|
impl Handle {
|
|
pub fn new(htype: HandleResource) -> Self {
|
|
Self {
|
|
inner: generate_process_pass(),
|
|
res: htype,
|
|
}
|
|
}
|
|
}
|