From 5b4ee4f986be3de7a34ea6ec8197716fd36bdc19 Mon Sep 17 00:00:00 2001 From: able Date: Thu, 28 Jul 2022 03:39:20 -0500 Subject: [PATCH] adding handles --- ableos/src/channels.rs | 51 ++++++++++++++++++++++++ ableos/src/handle.rs | 47 ++++++++++++++++++++++ ableos/src/lib.rs | 2 + ableos/src/scheduler.rs | 6 +++ ableos/src/scratchpad.rs | 86 ++++++---------------------------------- 5 files changed, 119 insertions(+), 73 deletions(-) create mode 100644 ableos/src/channels.rs create mode 100644 ableos/src/handle.rs diff --git a/ableos/src/channels.rs b/ableos/src/channels.rs new file mode 100644 index 0000000..540a0d6 --- /dev/null +++ b/ableos/src/channels.rs @@ -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, + // 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 { + 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, +} diff --git a/ableos/src/handle.rs b/ableos/src/handle.rs new file mode 100644 index 0000000..6726004 --- /dev/null +++ b/ableos/src/handle.rs @@ -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, +} + +#[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), + } + } +} diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 29788bb..af1a9cb 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -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; diff --git a/ableos/src/scheduler.rs b/ableos/src/scheduler.rs index 00b9371..ea70991 100644 --- a/ableos/src/scheduler.rs +++ b/ableos/src/scheduler.rs @@ -38,3 +38,9 @@ impl Scheduler { self.task_queue.pop_front() } } + +pub enum WakeConditions { + Time, + ReceivedMessageInChannel, + GainedAccessToChannel, +} diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index dfb5c2e..af87734 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -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, @@ -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, - - permission_list: Vec<(PID, ChannelPermission)>, -} - -impl Channel { - pub fn new() -> Self { - Self { - inner: vec![], - permission_list: vec![], - } - } -} - -pub enum ChannelErrors {}