for able
This commit is contained in:
parent
2b5076baa7
commit
4c2e52c9bb
|
@ -1,6 +1,10 @@
|
||||||
use crate::arch::hardware_random_u64;
|
use crate::interp::objects::{Object, OBJECTS};
|
||||||
use alloc::vec::Vec;
|
|
||||||
use core::fmt::{self, Formatter};
|
use {
|
||||||
|
crate::arch::hardware_random_u64,
|
||||||
|
alloc::vec::Vec,
|
||||||
|
core::fmt::{self, Formatter},
|
||||||
|
};
|
||||||
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
||||||
pub struct OSHandle {
|
pub struct OSHandle {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
|
@ -21,19 +25,30 @@ impl OSHandle {
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
id: OSHandle,
|
id: OSHandle,
|
||||||
perms: Permissions,
|
perms: Permissions,
|
||||||
|
r#ref: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handle {
|
impl Handle {
|
||||||
pub fn new() -> Handle {
|
pub fn new(r#ref: usize) -> Handle {
|
||||||
Handle {
|
Handle {
|
||||||
id: OSHandle::random_new(),
|
id: OSHandle::random_new(),
|
||||||
perms: Permissions::new(),
|
perms: Permissions::new(),
|
||||||
|
r#ref,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_u64(&self) -> u64 {
|
pub fn as_u64(&self) -> u64 {
|
||||||
self.id.id
|
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 {
|
impl fmt::Display for Handle {
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub fn host_register_idt_handler(
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::interp::Handle;
|
use crate::interp::{Handle, objects::{Object, ObjectHeader, ObjectSpecial}};
|
||||||
|
|
||||||
pub fn host_make_object(
|
pub fn host_make_object(
|
||||||
mut caller: Caller<'_, HostState>,
|
mut caller: Caller<'_, HostState>,
|
||||||
|
@ -54,14 +54,17 @@ pub fn host_make_object(
|
||||||
name.push(ch);
|
name.push(ch);
|
||||||
}
|
}
|
||||||
trace!("Object Name {}", name);
|
trace!("Object Name {}", name);
|
||||||
let hand = Handle::new();
|
let binding = OBJECTS;
|
||||||
{
|
let mut olock = binding.lock();
|
||||||
let binding = OBJECTS;
|
let hand = Handle::new(olock.len());
|
||||||
let mut olock = binding.lock();
|
let obj = xml::XMLElement::new(name);
|
||||||
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);
|
caller.data_mut().handles.push(hand);
|
||||||
// hand.into()
|
// hand.into()
|
||||||
hand.as_u64().try_into().unwrap()
|
hand.as_u64().try_into().unwrap()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mod host_functions;
|
mod host_functions;
|
||||||
mod objects;
|
pub mod objects;
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
handle::{self, Handle},
|
handle::{self, Handle},
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
use alloc::vec;
|
use alloc::{vec, vec::Vec};
|
||||||
use alloc::vec::Vec;
|
|
||||||
|
|
||||||
use spin::{Lazy, Mutex};
|
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(|| {
|
pub const OBJECTS: Lazy<Mutex<HostObjects>> = Lazy::new(|| {
|
||||||
let mut obj = vec![];
|
let mut obj = vec![];
|
||||||
|
|
|
@ -13,7 +13,7 @@ impl Drop for Object{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object{
|
impl Object{
|
||||||
fn to_global(self) -> [u64; 4]{
|
pub fn to_global(self) -> [u64; 4]{
|
||||||
let b = unsafe {
|
let b = unsafe {
|
||||||
sys::make_global(self.id).into()
|
sys::make_global(self.id).into()
|
||||||
};
|
};
|
||||||
|
@ -21,9 +21,16 @@ impl Object{
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_global(a: [u64; 4]) -> Object{
|
pub fn from_global(a: [u64; 4]) -> Object{
|
||||||
return Object{id: unsafe {
|
return Object{id: unsafe {
|
||||||
sys::take_global(a.into())
|
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)
|
||||||
|
}};
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue