77 lines
1.9 KiB
Rust
77 lines
1.9 KiB
Rust
use {
|
|
crate::interp::{HFIDT, OBJECTS},
|
|
alloc::string::String,
|
|
log::trace,
|
|
wasmi::{Caller, TypedFunc},
|
|
};
|
|
|
|
use super::{HostState, WasmContext};
|
|
|
|
pub fn host_register_idt_handler(
|
|
caller: Caller<'_, HostState>,
|
|
interupt_number: i32,
|
|
address_start: i32,
|
|
length_of_string: i32,
|
|
) -> i32 {
|
|
// TODO: get the proc_id to address which function it is
|
|
// TODO: Register the function name and proc_id into the idt handler
|
|
|
|
let mem = caller.get_export("memory").unwrap().into_memory().unwrap();
|
|
let mem_array = mem.data(&caller);
|
|
let mut name = String::new();
|
|
for i in address_start..(address_start + length_of_string) {
|
|
let ch = mem_array[i as usize] as char;
|
|
name.push(ch);
|
|
}
|
|
|
|
let index = interupt_number as usize;
|
|
|
|
let hf = HFIDT.lock();
|
|
|
|
// hf.insert(index);
|
|
|
|
trace!("{}", name);
|
|
0
|
|
}
|
|
|
|
use crate::interp::Handle;
|
|
|
|
pub fn host_make_object(
|
|
mut caller: Caller<'_, HostState>,
|
|
address_start: i32,
|
|
length_of_string: i32,
|
|
) -> i64 {
|
|
trace!(
|
|
"Called with addr {{ start {} length {} }}",
|
|
address_start,
|
|
length_of_string
|
|
);
|
|
let mem = caller.get_export("memory").unwrap().into_memory().unwrap();
|
|
let mem_array = mem.data(&caller);
|
|
let mut name = String::new();
|
|
for i in address_start..(address_start + length_of_string) {
|
|
let ch = mem_array[i as usize] as char;
|
|
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);
|
|
|
|
olock.push(Some(obj))
|
|
}
|
|
caller.data_mut().handles.push(hand);
|
|
// hand.into()
|
|
hand.as_u64().try_into().unwrap()
|
|
}
|
|
|
|
pub type WFIDT = TypedFunc<(), ()>;
|
|
|
|
fn get_fn_from_wc(wc: WasmContext, function_name: String) -> WFIDT {
|
|
wc.instance
|
|
.get_typed_func(wc.store, &function_name)
|
|
.unwrap()
|
|
}
|