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

43 lines
1.3 KiB
Rust
Raw Normal View History

pub mod host_functions;
extern crate wasmi;
// extern crate wabt;
use genfs::{Fs, OpenOptions};
2022-02-12 03:25:02 -06:00
use wasmi::{ImportsBuilder, ModuleInstance};
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
pub fn interp() {
2022-02-26 07:35:36 -06:00
trace!("Interpreting...");
let fs = &*FILE_SYSTEM.lock();
2022-02-26 07:35:36 -06:00
trace!("Got filesystem");
let file = fs
2022-02-26 07:35:36 -06:00
.open(
b"/home/able/bins/aos_wasm_stress_test.wasm",
OpenOptions::new().read(true),
)
.unwrap();
let mut wasm_binary = Vec::new();
let ret = file.read_to_end(&mut wasm_binary).unwrap();
2022-02-26 07:35:36 -06:00
trace!("Binary size {}", ret);
// 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");
2022-02-12 03:25:02 -06:00
println!("collected wasm return value: {:?}", ret);
}