diff --git a/ableos/src/rhai_shell/mod.rs b/ableos/src/rhai_shell/mod.rs index 8b88867..cb9fa0f 100644 --- a/ableos/src/rhai_shell/mod.rs +++ b/ableos/src/rhai_shell/mod.rs @@ -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 } diff --git a/ableos/src/wasm_jumploader/host_functions.rs b/ableos/src/wasm_jumploader/host_functions.rs index 25cfa2e..1c21f31 100644 --- a/ableos/src/wasm_jumploader/host_functions.rs +++ b/ableos/src/wasm_jumploader/host_functions.rs @@ -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) = 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 { let index = match field_name { "add" => ADD_FUNC_INDEX, + "send_signal" => SEND_SIGNAL_INDEX, _ => { return Err(Error::Instantiation(format!( "Export {} not found", diff --git a/ableos/src/wasm_jumploader/mod.rs b/ableos/src/wasm_jumploader/mod.rs index 35b4788..e379b01 100644 --- a/ableos/src/wasm_jumploader/mod.rs +++ b/ableos/src/wasm_jumploader/mod.rs @@ -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"); diff --git a/userland/aos_wasm_stress_test/Cargo.lock b/userland/aos_wasm_stress_test/Cargo.lock index d208d60..6b2bc0f 100644 --- a/userland/aos_wasm_stress_test/Cargo.lock +++ b/userland/aos_wasm_stress_test/Cargo.lock @@ -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" diff --git a/userland/aos_wasm_stress_test/readme.md b/userland/aos_wasm_stress_test/readme.md index 03b81cc..3a68e32 100644 --- a/userland/aos_wasm_stress_test/readme.md +++ b/userland/aos_wasm_stress_test/readme.md @@ -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 diff --git a/userland/aos_wasm_stress_test/src/main.rs b/userland/aos_wasm_stress_test/src/main.rs index a3fd82b..73ee380 100644 --- a/userland/aos_wasm_stress_test/src/main.rs +++ b/userland/aos_wasm_stress_test/src/main.rs @@ -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; diff --git a/userland/root_rs/ext2.img b/userland/root_rs/ext2.img index 4927e5a..15b29de 100644 Binary files a/userland/root_rs/ext2.img and b/userland/root_rs/ext2.img differ