made console_out print the bytes of its arg as ascii
This commit is contained in:
parent
f2dfad3162
commit
8680e6f470
BIN
ableos/src/wasm/bin/console_out_test.wasm
Executable file
BIN
ableos/src/wasm/bin/console_out_test.wasm
Executable file
Binary file not shown.
|
@ -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),
|
||||
|
|
|
@ -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),*
|
||||
|
|
Loading…
Reference in a new issue