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 x86_64::instructions::interrupts::{disable, enable};
|
||||
|
||||
use crate::wasm_jumploader::interp;
|
||||
use crate::{
|
||||
arch::{shutdown, sloop},
|
||||
kmain::{tick, TICK},
|
||||
|
@ -81,6 +82,8 @@ fn engine_construction() -> Engine {
|
|||
engine.register_fn("shutdown", shutdown);
|
||||
engine.register_fn("peek", peek_memory);
|
||||
engine.register_fn("poke", poke_memory);
|
||||
engine.register_fn("sloop", sloop);
|
||||
engine.register_fn("wasm", interp);
|
||||
engine
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use wasmi::{
|
|||
pub struct HostExternals {}
|
||||
|
||||
const ADD_FUNC_INDEX: usize = 0;
|
||||
const SEND_SIGNAL_INDEX: usize = 1;
|
||||
|
||||
impl Externals for HostExternals {
|
||||
fn invoke_index(
|
||||
|
@ -22,6 +23,14 @@ impl Externals for HostExternals {
|
|||
println!("SYSCALL: {} + {} = {}", a, b, result);
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +40,7 @@ impl HostExternals {
|
|||
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
||||
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index {
|
||||
ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
||||
SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
||||
_ => return false,
|
||||
};
|
||||
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> {
|
||||
let index = match field_name {
|
||||
"add" => ADD_FUNC_INDEX,
|
||||
"send_signal" => SEND_SIGNAL_INDEX,
|
||||
_ => {
|
||||
return Err(Error::Instantiation(format!(
|
||||
"Export {} not found",
|
||||
|
|
|
@ -10,17 +10,20 @@ use wasmi::{ImportsBuilder, ModuleInstance};
|
|||
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
|
||||
|
||||
pub fn interp() {
|
||||
info!("Interpreting...");
|
||||
trace!("Interpreting...");
|
||||
let fs = &*FILE_SYSTEM.lock();
|
||||
info!("Got filesystem");
|
||||
trace!("Got filesystem");
|
||||
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();
|
||||
|
||||
let mut wasm_binary = Vec::new();
|
||||
|
||||
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.
|
||||
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]]
|
||||
name = "libwasm"
|
||||
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_main]
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
#[no_mangle]
|
||||
fn start() -> i32 {
|
||||
let ret = unsafe { add(1, 2) };
|
||||
unsafe {
|
||||
send_signal(PID(1), Signals::Quit);
|
||||
}
|
||||
|
||||
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