master
Graham Kelly 2023-04-12 15:11:11 -04:00
parent cfb080f08b
commit 2a733f3903
5 changed files with 53 additions and 18 deletions

View File

@ -1,6 +1,10 @@
use crate::arch::hardware_random_u64;
use alloc::vec::Vec;
use core::fmt::{self, Formatter};
use crate::interp::objects::{Object, OBJECTS};
use {
crate::arch::hardware_random_u64,
alloc::vec::Vec,
core::fmt::{self, Formatter},
};
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub struct OSHandle {
pub id: u64,
@ -21,19 +25,30 @@ impl OSHandle {
pub struct Handle {
id: OSHandle,
perms: Permissions,
r#ref: usize,
}
impl Handle {
pub fn new() -> Handle {
pub fn new(r#ref: usize) -> Handle {
Handle {
id: OSHandle::random_new(),
perms: Permissions::new(),
r#ref,
}
}
pub fn as_u64(&self) -> u64 {
self.id.id
}
pub fn get<R, F: for <'a> FnOnce(Option<&'a mut Object>) -> R>(&self,f: F) -> R{
let l = OBJECTS;
let mut olock = l.lock();
let a = olock.get_mut(self.r#ref).and_then(|a|{
a.as_mut()
});
return f(a);
}
}
impl fmt::Display for Handle {

View File

@ -34,7 +34,7 @@ pub fn host_register_idt_handler(
0
}
use crate::interp::Handle;
use crate::interp::{Handle, objects::{Object, ObjectHeader, ObjectSpecial}};
pub fn host_make_object(
mut caller: Caller<'_, HostState>,
@ -54,14 +54,17 @@ pub fn host_make_object(
name.push(ch);
}
trace!("Object Name {}", name);
let hand = Handle::new();
{
let binding = OBJECTS;
let mut olock = binding.lock();
let obj = xml::XMLElement::new(name);
let binding = OBJECTS;
let mut olock = binding.lock();
let hand = Handle::new(olock.len());
let obj = xml::XMLElement::new(name);
olock.push(Some(obj))
}
olock.push(Some(Object{
header: ObjectHeader{
},
special: ObjectSpecial::Xml(obj)
}));
caller.data_mut().handles.push(hand);
// hand.into()
hand.as_u64().try_into().unwrap()

View File

@ -1,5 +1,5 @@
mod host_functions;
mod objects;
pub mod objects;
use {
crate::{
handle::{self, Handle},

View File

@ -1,9 +1,19 @@
use alloc::vec;
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};
use spin::{Lazy, Mutex};
pub type HostObjects = Vec<Option<xml::XMLElement>>;
pub struct Object {
pub header: ObjectHeader,
pub special: ObjectSpecial,
}
pub struct ObjectHeader {}
pub enum ObjectSpecial {
Xml(xml::XMLElement),
}
pub type HostObjects = Vec<Option<Object>>;
pub const OBJECTS: Lazy<Mutex<HostObjects>> = Lazy::new(|| {
let mut obj = vec![];

View File

@ -13,7 +13,7 @@ impl Drop for Object{
}
impl Object{
fn to_global(self) -> [u64; 4]{
pub fn to_global(self) -> [u64; 4]{
let b = unsafe {
sys::make_global(self.id).into()
};
@ -21,9 +21,16 @@ impl Object{
return b;
}
fn from_global(a: [u64; 4]) -> Object{
pub fn from_global(a: [u64; 4]) -> Object{
return Object{id: unsafe {
sys::take_global(a.into())
}};
}
pub fn new(name: &str) -> Object{
return Object{id: unsafe {
let a = name.as_ptr();
sys::create_object(a, name.len() as i32)
}};
}
}