2022-08-03 04:53:02 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Umut İnan Erdoğan <umutinanerdogan@pm.me>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
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 {
|
2022-08-01 06:50:41 -05:00
|
|
|
_name: String,
|
|
|
|
_data: Vec<u8>,
|
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 enum HandleResource {
|
2022-07-28 20:15:02 -05:00
|
|
|
Channel,
|
|
|
|
Socket,
|
|
|
|
BinaryData,
|
2022-08-03 04:53:02 -05:00
|
|
|
StorageDevice,
|
|
|
|
FileDescriptor,
|
2022-08-04 09:03:44 -05:00
|
|
|
FsNode,
|
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")?,
|
2022-08-03 04:53:02 -05:00
|
|
|
HandleResource::Socket => write!(f, "-Socket")?,
|
|
|
|
HandleResource::StorageDevice => write!(f, "-StorageDevice")?,
|
|
|
|
HandleResource::FileDescriptor => write!(f, "-FileDescriptor")?,
|
2022-08-04 09:03:44 -05:00
|
|
|
HandleResource::FsNode => write!(f, "-FsNode")?,
|
2022-07-28 03:39:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Handle {
|
2022-07-28 20:15:02 -05:00
|
|
|
pub fn new(htype: HandleResource) -> Self {
|
2022-08-03 04:53:02 -05:00
|
|
|
// FIXME: check if inner collides
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|