wasm jumploader patches
This commit is contained in:
parent
ab3110923e
commit
3ce2026d32
|
@ -36,6 +36,7 @@ use alloc::string::{String, ToString};
|
||||||
use rhai::Engine;
|
use rhai::Engine;
|
||||||
use x86_64::instructions::interrupts::{disable, enable};
|
use x86_64::instructions::interrupts::{disable, enable};
|
||||||
|
|
||||||
|
use crate::wasm_jumploader::interp;
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::{shutdown, sloop},
|
arch::{shutdown, sloop},
|
||||||
kmain::{tick, TICK},
|
kmain::{tick, TICK},
|
||||||
|
@ -81,6 +82,8 @@ fn engine_construction() -> Engine {
|
||||||
engine.register_fn("shutdown", shutdown);
|
engine.register_fn("shutdown", shutdown);
|
||||||
engine.register_fn("peek", peek_memory);
|
engine.register_fn("peek", peek_memory);
|
||||||
engine.register_fn("poke", poke_memory);
|
engine.register_fn("poke", poke_memory);
|
||||||
|
engine.register_fn("sloop", sloop);
|
||||||
|
engine.register_fn("wasm", interp);
|
||||||
engine
|
engine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use wasmi::{
|
||||||
pub struct HostExternals {}
|
pub struct HostExternals {}
|
||||||
|
|
||||||
const ADD_FUNC_INDEX: usize = 0;
|
const ADD_FUNC_INDEX: usize = 0;
|
||||||
|
const SEND_SIGNAL_INDEX: usize = 1;
|
||||||
|
|
||||||
impl Externals for HostExternals {
|
impl Externals for HostExternals {
|
||||||
fn invoke_index(
|
fn invoke_index(
|
||||||
|
@ -22,6 +23,14 @@ impl Externals for HostExternals {
|
||||||
println!("SYSCALL: {} + {} = {}", a, b, result);
|
println!("SYSCALL: {} + {} = {}", a, b, result);
|
||||||
Ok(Some(RuntimeValue::I32(result as i32)))
|
Ok(Some(RuntimeValue::I32(result as i32)))
|
||||||
}
|
}
|
||||||
|
SEND_SIGNAL_INDEX => {
|
||||||
|
let pid: u32 = args.nth_checked(0)?;
|
||||||
|
let signal: u32 = args.nth_checked(1)?;
|
||||||
|
|
||||||
|
println!("SYSCALL: send signal {} to pid {}", signal, pid);
|
||||||
|
let ret = RuntimeValue::I32(0);
|
||||||
|
Ok(Some(ret))
|
||||||
|
}
|
||||||
_ => panic!("Unimplemented function at {}", index),
|
_ => panic!("Unimplemented function at {}", index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +40,7 @@ impl HostExternals {
|
||||||
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
||||||
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index {
|
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index {
|
||||||
ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
||||||
|
SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
signature.params() == params && signature.return_type() == ret_ty
|
signature.params() == params && signature.return_type() == ret_ty
|
||||||
|
@ -41,6 +51,7 @@ impl ModuleImportResolver for HostExternals {
|
||||||
fn resolve_func(&self, field_name: &str, signature: &Signature) -> Result<FuncRef, Error> {
|
fn resolve_func(&self, field_name: &str, signature: &Signature) -> Result<FuncRef, Error> {
|
||||||
let index = match field_name {
|
let index = match field_name {
|
||||||
"add" => ADD_FUNC_INDEX,
|
"add" => ADD_FUNC_INDEX,
|
||||||
|
"send_signal" => SEND_SIGNAL_INDEX,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Error::Instantiation(format!(
|
return Err(Error::Instantiation(format!(
|
||||||
"Export {} not found",
|
"Export {} not found",
|
||||||
|
|
|
@ -10,17 +10,20 @@ use wasmi::{ImportsBuilder, ModuleInstance};
|
||||||
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
|
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
|
||||||
|
|
||||||
pub fn interp() {
|
pub fn interp() {
|
||||||
info!("Interpreting...");
|
trace!("Interpreting...");
|
||||||
let fs = &*FILE_SYSTEM.lock();
|
let fs = &*FILE_SYSTEM.lock();
|
||||||
info!("Got filesystem");
|
trace!("Got filesystem");
|
||||||
let file = fs
|
let file = fs
|
||||||
.open(b"/home/able/bins/test.wasm", OpenOptions::new().read(true))
|
.open(
|
||||||
|
b"/home/able/bins/aos_wasm_stress_test.wasm",
|
||||||
|
OpenOptions::new().read(true),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut wasm_binary = Vec::new();
|
let mut wasm_binary = Vec::new();
|
||||||
|
|
||||||
let ret = file.read_to_end(&mut wasm_binary).unwrap();
|
let ret = file.read_to_end(&mut wasm_binary).unwrap();
|
||||||
info!("Binary size {}", ret);
|
trace!("Binary size {}", ret);
|
||||||
// Load wasm binary and prepare it for instantiation.
|
// Load wasm binary and prepare it for instantiation.
|
||||||
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");
|
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");
|
||||||
|
|
||||||
|
|
2
userland/aos_wasm_stress_test/Cargo.lock
generated
2
userland/aos_wasm_stress_test/Cargo.lock
generated
|
@ -12,4 +12,4 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libwasm"
|
name = "libwasm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/able/libwasm.git#502187e8734b54df3c6cae2baf2315539a3ec49b"
|
source = "git+https://git.ablecorp.us/able/libwasm.git#dedbb769ba01a4b75992437e52ca9a5c2bb9e0f9"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
This is a stress test and simple progrram for ableOS.
|
This is a stress test and simple program for ableOS.
|
||||||
|
|
||||||
|
|
||||||
There should be two sub commands echo and input
|
|
||||||
|
|
|
@ -1,12 +1,36 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![deny(improper_ctypes)]
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn start() -> i32 {
|
fn start() -> i32 {
|
||||||
let ret = unsafe { add(1, 2) };
|
let ret = unsafe { add(1, 2) };
|
||||||
|
unsafe {
|
||||||
|
send_signal(PID(1), Signals::Quit);
|
||||||
|
}
|
||||||
|
|
||||||
ret as i32
|
ret as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
use libwasm::syscalls::add;
|
extern "C" {
|
||||||
|
|
||||||
|
/// Send a signal to a process
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `pid` - The PID of the process to send the signal to
|
||||||
|
/// * `signal` - The signal to send
|
||||||
|
pub fn send_signal(pid: PID, signal: Signals) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
use {
|
||||||
|
libwasm::process::{signals::Signals, PID},
|
||||||
|
libwasm::syscalls::add,
|
||||||
|
};
|
||||||
|
|
||||||
|
use libwasm::*;
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(_info: &PanicInfo) -> ! {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue