1
0
Fork 0
forked from AbleOS/ableos

made console_out print the bytes of its arg as ascii

This commit is contained in:
elfein727 2022-01-01 19:07:56 -08:00
parent f2dfad3162
commit 8680e6f470
3 changed files with 144 additions and 134 deletions

Binary file not shown.

View file

@ -1,3 +1,6 @@
use alloc::string::String;
use wasmi::TrapKind;
use {
alloc::format,
wasm_sys::SysCall,
@ -23,13 +26,13 @@ impl Externals for HostFunctions {
fn invoke_index(
&mut self,
index: usize,
_args: RuntimeArgs,
args: RuntimeArgs,
) -> Result<Option<RuntimeValue>, Trap> {
match index.into() {
// Take in one arg discard the rest
SysCall::KILL => {
info!("Program run at runtime called a system call");
debug!("Runtime arguments: {:?}", _args);
debug!("Runtime arguments: {:?}", args);
Ok(None)
}
// Do nothing
@ -42,7 +45,13 @@ impl Externals for HostFunctions {
}
SysCall::CONSOLE_OUT => {
info!("Out");
// Eventually change this to 2- ptr and len
if args.len() != 1 {
return Err(Trap::new(TrapKind::UnexpectedSignature));
}
let arg: u64 = args.nth(0);
let buf = unsafe { String::from_utf8_unchecked(arg.to_le_bytes().to_vec()) };
println!["{}", buf];
Ok(None)
}
SysCall::CONSOLE_GET_TITLE => Ok(None),

View file

@ -9,6 +9,7 @@ macro_rules! syscall_enum {
syscall_enum![@get_last $($VariantTail),*]
};
($($Variant:ident=$Value:expr,)*) => {
#[allow(clippy::upper_case_acronyms)]
#[repr(usize)]
pub enum SysCall {
$($Variant = $Value),*