adding handles

This commit is contained in:
able 2022-07-28 03:39:20 -05:00
parent d2aef77b7f
commit 5b4ee4f986
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 mod allocator;
// pub use allocator as aalloc; // pub use allocator as aalloc;
pub mod channels;
pub mod handle;
mod unicode_utils; mod unicode_utils;
pub mod vga_e; pub mod vga_e;

View file

@ -38,3 +38,9 @@ impl Scheduler {
self.task_queue.pop_front() 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::aalloc::aalloc;
use crate::arch::generate_process_pass; use crate::arch::generate_process_pass;
use crate::arch::interrupts::{reset_pit_for_cpu, set_pit_2}; use crate::arch::interrupts::{reset_pit_for_cpu, set_pit_2};
use crate::channels::{Channel, ChannelPermission};
use crate::devices::pci; use crate::devices::pci;
use crate::filesystem::FILE_SYSTEM; use crate::filesystem::FILE_SYSTEM;
use crate::handle::Handle;
use crate::rhai_shell::shell; use crate::rhai_shell::shell;
use crate::rhai_shell::KEYBUFF; use crate::rhai_shell::KEYBUFF;
use crate::wasm_jumploader::run_program; use crate::wasm_jumploader::run_program;
use crate::SCREEN_BUFFER; use crate::SCREEN_BUFFER;
use acpi::{AcpiTables, PlatformInfo}; use acpi::{AcpiTables, PlatformInfo};
use alloc::collections::{vec_deque, VecDeque};
use cpuio::inb; use cpuio::inb;
use cpuio::outb; use cpuio::outb;
use genfs::Fs; use genfs::Fs;
@ -32,6 +37,7 @@ impl acpi::AcpiHandler for AcpiStruct {
todo!("unmap_physical_region"); todo!("unmap_physical_region");
} }
} }
#[derive(Debug)]
pub struct Path { pub struct Path {
pub path: Vec<String>, pub path: Vec<String>,
@ -91,37 +97,15 @@ pub fn scratchpad() {
*/ */
let _abc = Path::new("/home/able".to_string()); let home_path = 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 mut chan = Channel::new(); let mut chan = Channel::new();
let perms = ChannelPermission {
owner: true, let ret = chan.read();
producer: false,
consumer: false, let chan_handle = Handle::from_channel(chan);
distructive_consumer: false,
}; println!("{}", chan_handle);
chan.permission_list.push((0, perms));
real_shell(); real_shell();
} }
@ -280,47 +264,3 @@ pub fn sound_off() {
}; };
reset_pit_for_cpu(); 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 {}