1
0
Fork 0
forked from AbleOS/ableos
ableOS_v1Change/ableos/src/wasm_jumploader/mod.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

pub mod host_functions;
extern crate wasmi;
// extern crate wabt;
use alloc::vec::Vec;
use genfs::{Fs, OpenOptions};
use wasmi::{ImportsBuilder, ModuleInstance, NopExternals};
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
pub fn interp() {
let fs = &*FILE_SYSTEM.lock();
let file = fs
.open(b"/home/able/test.wasm", OpenOptions::new().read(true))
.unwrap();
let mut wasm_binary = Vec::new();
let ret = file.read_to_end(&mut wasm_binary).unwrap();
// Load wasm binary and prepare it for instantiation.
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");
let imports = ImportsBuilder::new().with_resolver("env", &host_functions::HostExternals {});
// Instantiate a module with empty imports and
// assert that there is no `start` function.
let instance = ModuleInstance::new(&module, &imports)
.expect("failed to instantiate wasm module")
.assert_no_start();
let ret = instance
.invoke_export("start", &[], &mut HostExternals {})
.expect("failed to execute export");
info!("collected wasm return value: {:?}", ret);
}