forked from AbleOS/ableos
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
pub mod host_functions;
|
|
|
|
extern crate wasmi;
|
|
// extern crate wabt;
|
|
|
|
use genfs::{Fs, OpenOptions};
|
|
use wasmi::{ImportsBuilder, ModuleInstance};
|
|
|
|
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
|
|
|
|
pub fn interp() {
|
|
trace!("Interpreting...");
|
|
let fs = &*FILE_SYSTEM.lock();
|
|
trace!("Got filesystem");
|
|
let file = fs
|
|
.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();
|
|
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");
|
|
|
|
println!("collected wasm return value: {:?}", ret);
|
|
}
|