adding handles

master
able 2022-07-28 03:39:20 -05:00
parent 42abdc6137
commit 64c21f30ba
5 changed files with 119 additions and 73 deletions

51
ableos/src/channels.rs Normal file
View File

@ -0,0 +1,51 @@
use core::fmt::Display;
use alloc::collections::VecDeque;
use kernel::proccess::PID;
use crate::{arch::generate_process_pass, handle::Handle};
#[derive(Debug)]
pub struct ChannelPermission {
pub owner: bool,
pub producer: bool,
pub consumer: bool,
/// Whether or not the process can be destructive about reading
pub distructive_consumer: bool,
}
#[derive(Debug)]
pub struct Channel {
inner: VecDeque<u8>,
// TODO(able): change this to a hashmap i think
permission_list: Vec<(PID, ChannelPermission)>,
}
impl Channel {
pub fn new() -> Self {
let deq = VecDeque::from([]);
Self {
inner: deq,
permission_list: vec![],
}
}
pub fn read(&mut self) -> Result<u8, ChannelError> {
if let Some(abc) = self.inner.pop_front() {
return Ok(abc);
}
return Err(ChannelError::EmptyBuffer);
}
pub fn send(&mut self, data: u8) {
self.inner.push_back(data);
}
}
pub enum ChannelError {
EmptyBuffer,
InvalidPermissions,
}

47
ableos/src/handle.rs Normal file
View File

@ -0,0 +1,47 @@
//! 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)]
pub enum HandleResource {
Channel(Channel),
// Device
BinaryData(BinaryData),
}
#[derive(Debug)]
pub struct Handle {
inner: u128,
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(data) => write!(f, "-Binary-{}", &data.name)?,
}
Ok(())
}
}
use crate::handle::HandleResource::*;
impl Handle {
pub fn from_channel(channel: Channel) -> Self {
Self {
inner: generate_process_pass(),
res: Channel(channel),
}
}
}

View File

@ -67,6 +67,8 @@ pub mod wasm_jumploader;
pub mod allocator;
// pub use allocator as aalloc;
pub mod channels;
pub mod handle;
mod unicode_utils;
pub mod vga_e;

View File

@ -38,3 +38,9 @@ impl Scheduler {
self.task_queue.pop_front()
}
}
pub enum WakeConditions {
Time,
ReceivedMessageInChannel,
GainedAccessToChannel,
}

View File

@ -1,13 +1,18 @@
use core::fmt::Error;
// use crate::aalloc::aalloc;
use crate::arch::generate_process_pass;
use crate::arch::interrupts::{reset_pit_for_cpu, set_pit_2};
use crate::channels::{Channel, ChannelPermission};
use crate::devices::pci;
use crate::filesystem::FILE_SYSTEM;
use crate::handle::Handle;
use crate::rhai_shell::shell;
use crate::rhai_shell::KEYBUFF;
use crate::wasm_jumploader::run_program;
use crate::SCREEN_BUFFER;
use acpi::{AcpiTables, PlatformInfo};
use alloc::collections::{vec_deque, VecDeque};
use cpuio::inb;
use cpuio::outb;
use genfs::Fs;
@ -32,6 +37,7 @@ impl acpi::AcpiHandler for AcpiStruct {
todo!("unmap_physical_region");
}
}
#[derive(Debug)]
pub struct Path {
pub path: Vec<String>,
@ -91,37 +97,15 @@ pub fn scratchpad() {
*/
let _abc = Path::new("/home/able".to_string());
for _ in 0..10 {
debug!("{}", generate_process_pass());
}
/*
debug!("start the graphics");
let mut abcde = SCREEN_BUFFER.lock();
abcde.force_redraw();
abcde.draw_filled_circle(100, 100, 300, 0x0000ff00);
abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000);
abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000);
abcde.draw_line(100, 100, 400, 200, 0xff000000);
abcde.copy_to_buffer();
debug!("end the graphics");
// */
// kernel::aalloc::AAlloc::intialize();
let home_path = Path::new("/home/able".to_string());
let mut chan = Channel::new();
let perms = ChannelPermission {
owner: true,
producer: false,
consumer: false,
distructive_consumer: false,
};
chan.permission_list.push((0, perms));
let ret = chan.read();
let chan_handle = Handle::from_channel(chan);
println!("{}", chan_handle);
real_shell();
}
@ -280,47 +264,3 @@ pub fn sound_off() {
};
reset_pit_for_cpu();
}
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
#[derive(Debug)]
pub struct ChannelPermission {
owner: bool,
producer: bool,
consumer: bool,
/// Whether or not the process can be destructive about reading
distructive_consumer: bool,
}
#[derive(Debug)]
pub struct Channel {
inner: Vec<u8>,
permission_list: Vec<(PID, ChannelPermission)>,
}
impl Channel {
pub fn new() -> Self {
Self {
inner: vec![],
permission_list: vec![],
}
}
}
pub enum ChannelErrors {}