1
0
Fork 0
forked from koniifer/ableos

implementing socket related IPC

This commit is contained in:
able 2022-07-28 20:15:02 -05:00
parent f6d0c71a24
commit 3f4c9fdb5a
8 changed files with 88 additions and 26 deletions

14
Cargo.lock generated
View file

@ -38,6 +38,7 @@ dependencies = [
"genfs", "genfs",
"hashbrown 0.7.2", "hashbrown 0.7.2",
"kernel", "kernel",
"lazy_static",
"libwasm", "libwasm",
"linked_list_allocator", "linked_list_allocator",
"lliw", "lliw",
@ -54,7 +55,7 @@ dependencies = [
"rkyv", "rkyv",
"serde", "serde",
"shadeable", "shadeable",
"spin", "spin 0.9.2",
"toml", "toml",
"uart_16550", "uart_16550",
"unicode-width", "unicode-width",
@ -310,7 +311,7 @@ dependencies = [
"bitflags", "bitflags",
"genfs", "genfs",
"rlibc", "rlibc",
"spin", "spin 0.9.2",
] ]
[[package]] [[package]]
@ -439,6 +440,9 @@ name = "lazy_static"
version = "1.4.0" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
dependencies = [
"spin 0.5.2",
]
[[package]] [[package]]
name = "libc" name = "libc"
@ -896,6 +900,12 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.9.2" version = "0.9.2"

View file

@ -42,6 +42,8 @@ test-args = [
] ]
[dependencies] [dependencies]
lazy_static = { version = "*", features = ["spin_no_std"] }
linked_list_allocator = "0.9.0" linked_list_allocator = "0.9.0"
lliw = "0.2.0" lliw = "0.2.0"
spin = "0.9" spin = "0.9"
@ -57,8 +59,6 @@ axel = { git = "https://git.ablecorp.us/able/aos_userland" }
versioning = { git = "https://git.ablecorp.us/able/aos_userland" } versioning = { git = "https://git.ablecorp.us/able/aos_userland" }
embedded-graphics = "*" embedded-graphics = "*"
pc-keyboard = "0.5" pc-keyboard = "0.5"
[dependencies.logos] [dependencies.logos]
version = "0.12" version = "0.12"
default-features = false default-features = false

View file

@ -11,15 +11,14 @@ pub struct BinaryData {
data: Vec<u8>, data: Vec<u8>,
} }
#[derive(Debug)] #[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub enum HandleResource { pub enum HandleResource {
Channel(Channel), Channel,
// Device Socket,
/// Used for things like files or images or the like BinaryData,
BinaryData(BinaryData),
} }
#[derive(Debug)] #[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub struct Handle { pub struct Handle {
inner: u128, inner: u128,
res: HandleResource, res: HandleResource,
@ -29,8 +28,9 @@ impl Display for Handle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Handle-{:032x}", self.inner)?; write!(f, "Handle-{:032x}", self.inner)?;
match &self.res { match &self.res {
HandleResource::Channel(_) => write!(f, "-Channel")?, HandleResource::Channel => write!(f, "-Channel")?,
HandleResource::BinaryData(data) => write!(f, "-Binary-{}", &data.name)?, HandleResource::BinaryData => write!(f, "-Binary")?,
Socket => write!(f, "-Socket")?,
} }
Ok(()) Ok(())
@ -39,10 +39,10 @@ impl Display for Handle {
use crate::handle::HandleResource::*; use crate::handle::HandleResource::*;
impl Handle { impl Handle {
pub fn from_channel(channel: Channel) -> Self { pub fn new(htype: HandleResource) -> Self {
Self { Self {
inner: generate_process_pass(), inner: generate_process_pass(),
res: Channel(channel), res: htype,
} }
} }
} }

View file

@ -1,16 +1,46 @@
use self::{channel::Channel, socket::Socket}; use hashbrown::HashMap;
use crate::handle::Handle;
use self::{
channel::Channel,
socket::{Socket, SocketError},
};
pub mod channel; pub mod channel;
pub mod socket; pub mod socket;
pub static IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService { lazy_static::lazy_static! {
sockets: vec![], pub static ref IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService {
channels: vec![], sockets: HashMap::new(),
channels: HashMap::new(),
}); });
}
pub struct IPCService { pub struct IPCService {
pub sockets: Vec<Socket>, pub sockets: HashMap<Handle, Socket>,
pub channels: Vec<Channel>, pub channels: HashMap<Handle, Socket>,
// TODO: Add a public board of each down below which use some method of pointing to the above // TODO: Add a public board of each down below which use some method of pointing to the above
} }
impl IPCService {}
// Socket Related Impl
impl IPCService {
pub fn create_socket(&mut self) -> Handle {
let handle = Handle::new(crate::handle::HandleResource::Socket);
let sock = Socket::new();
self.sockets.insert(handle.clone(), sock);
handle
}
pub fn send_socket(&mut self, handle: Handle, data: String) -> Result<(), SocketError> {
let sock = self.sockets.get_mut(&handle);
match sock {
Some(socket) => {
return socket.write(data);
}
None => return Err(SocketError::NonexistantSocket),
}
}
}

View file

@ -1,16 +1,21 @@
// SEEALSO: https://git.ablecorp.us/able/ableos/src/branch/master/ableos/src/relib/network/socket.rs // SEEALSO: https://git.ablecorp.us/able/ableos/src/branch/master/ableos/src/relib/network/socket.rs
pub enum SocketError { pub enum SocketError {
NonexistantSocket,
EmptySocket, EmptySocket,
} }
#[derive(Debug)]
pub struct Socket { pub struct Socket {
name: Option<String>,
stream: Vec<u8>, stream: Vec<u8>,
} }
impl Socket { impl Socket {
pub fn new() -> Self { pub fn new() -> Self {
Self { stream: vec![] } Self {
name: None,
stream: vec![],
}
} }
pub fn write(&mut self, data: String) -> Result<(), SocketError> { pub fn write(&mut self, data: String) -> Result<(), SocketError> {
for c in data.chars() { for c in data.chars() {
@ -28,4 +33,8 @@ impl Socket {
} }
return Err(SocketError::EmptySocket); return Err(SocketError::EmptySocket);
} }
pub fn name(&mut self, name: String) {
self.name = Some(name);
}
} }

View file

@ -1,14 +1,18 @@
#![allow(clippy::empty_loop)] #![allow(clippy::empty_loop)]
use core::sync::atomic::Ordering;
use crate::arch::drivers::sysinfo::master; use crate::arch::drivers::sysinfo::master;
use crate::ipc::{self, IPC};
use crate::scheduler::SCHEDULER; use crate::scheduler::SCHEDULER;
use crate::time::fetch_time;
use crate::{ use crate::{
arch::{init, sloop}, arch::{init, sloop},
relib::network::socket::{SimpleSock, Socket}, relib::network::socket::{SimpleSock, Socket},
scratchpad, scratchpad,
}; };
use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE}; use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE};
use kernel::KERNEL_VERSION; use kernel::{KERNEL_VERSION, TICK};
use spin::Lazy; use spin::Lazy;
// TODO: Change this structure to allow for multiple cores loaded // TODO: Change this structure to allow for multiple cores loaded
@ -25,6 +29,13 @@ pub fn kernel_main() -> ! {
log::set_max_level(log::LevelFilter::Off); log::set_max_level(log::LevelFilter::Off);
} }
let mut ipc_service = IPC.lock();
// create some channels or whatever here then drop it
let handle = ipc_service.create_socket();
ipc_service.send_socket(handle, "nerd".to_string());
drop(ipc_service);
x86_64::instructions::interrupts::without_interrupts(|| { x86_64::instructions::interrupts::without_interrupts(|| {
SCHEDULER.lock().enqueue_spawn(scratchpad); SCHEDULER.lock().enqueue_spawn(scratchpad);
}); });

View file

@ -217,6 +217,7 @@ fn engine_construction() -> Engine {
engine.register_fn("poke", poke_memory); engine.register_fn("poke", poke_memory);
engine.register_fn("sloop", sloop); engine.register_fn("sloop", sloop);
engine.register_fn("log_dump", log_dump); engine.register_fn("log_dump", log_dump);
// engine.register_fn("ls", ls);
engine engine
} }

View file

@ -7,6 +7,7 @@ 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::handle::Handle;
use crate::ipc::IPC;
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;