ableos/kernel/src/interp.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

2023-04-05 12:29:20 -05:00
use alloc::vec::Vec;
use log::trace;
use wasmi::{Caller, Func, Linker, Module, Store};
pub fn wasm() -> Result<(), wasmi::Error> {
use wasmi::Config;
use wasmi::Engine;
trace!("");
let conf = Config::default();
let engine = Engine::new(&conf);
trace!("Engine constructed");
let wasm = include_bytes!("../../wasm_syscall_test.wasm");
trace!("Loading WASM binary");
let module = Module::new(&engine, &wasm[..]).unwrap();
trace!("Constructing wasm module");
let mut store = Store::new(&engine, 42);
trace!("constructing host store");
let read_mem_addr = Func::wrap(&mut store, |caller: Caller<'_, HostState>, param: u64| {
read_memory_address(caller, param);
panic!(":)")
});
let mut linker = <Linker<HostState>>::new(&engine);
linker.define("host", "read_mem_addr", read_mem_addr)?;
trace!("Linked read_mem_addr");
let instance = linker.instantiate(&mut store, &module)?.start(&mut store)?;
trace!("Instanced the engine and module");
let hello = instance.get_typed_func::<(), ()>(&store, "_start")?;
hello.call(&mut store, ())?;
trace!("Called _start");
Ok(())
}
pub type HostState = u32;
pub fn read_memory_address(caller: Caller<'_, HostState>, address: u64) -> u64 {
trace!("Address: {}", address);
0
}