print SYSCALL works

master
Able 2022-04-19 02:38:59 -05:00
parent 366de40340
commit 8c45fa4af8
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
2 changed files with 8 additions and 16 deletions

View File

@ -8,7 +8,7 @@ const ADD_FUNC_INDEX: usize = 0;
const GET_TIME_INDEX: usize = 2; const GET_TIME_INDEX: usize = 2;
const GET_RANDOM_INDEX: usize = 3; const GET_RANDOM_INDEX: usize = 3;
const GET_INPUT_INDEX: usize = 4; const GET_INPUT_INDEX: usize = 4;
const PRINT_CLEVER_HACK: usize = 5; const PRINT_CHAR: usize = 6;
const SEND_SIGNAL_INDEX: usize = 1; const SEND_SIGNAL_INDEX: usize = 1;
pub struct HostExternals; pub struct HostExternals;
@ -100,8 +100,8 @@ impl HostExternals {
true true
} }
PRINT_CLEVER_HACK => { PRINT_CHAR => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = (&[ValueType::I64], None); let (params, ret_ty): (&[ValueType], Option<ValueType>) = (&[ValueType::I32], None);
if params.len() != signature.params().len() { if params.len() != signature.params().len() {
return false; return false;
} }
@ -178,20 +178,12 @@ impl Externals for HostExternals {
Ok(Some(ret)) Ok(Some(ret))
} }
PRINT_CLEVER_HACK => { PRINT_CHAR => {
// println!("SYSCALL: print clever hack"); let chr: u8 = args.nth_checked(0)?;
trace!("SYSCALL: print: {}", chr);
let combinated = args.nth_checked::<u64>(0).unwrap().to_le_bytes(); print!("{}", char::from(chr));
for x in combinated.iter() {
let chr = *x as char;
print!("{}", chr);
}
println!("\n");
Ok(None) Ok(None)
} }
_ => { _ => {
error!("Unimplemented function at {}", index); error!("Unimplemented function at {}", index);
Err(Trap::new(wasmi::TrapKind::Unreachable)) Err(Trap::new(wasmi::TrapKind::Unreachable))
@ -208,7 +200,7 @@ impl ModuleImportResolver for HostExternals {
"get_time" => GET_TIME_INDEX, "get_time" => GET_TIME_INDEX,
"get_random" => GET_RANDOM_INDEX, "get_random" => GET_RANDOM_INDEX,
"get_input" => GET_INPUT_INDEX, "get_input" => GET_INPUT_INDEX,
"print_clever_hack" => PRINT_CLEVER_HACK, "print_char" => PRINT_CHAR,
_ => { _ => {
return Err(Error::Instantiation(format!( return Err(Error::Instantiation(format!(
"Export {} not found", "Export {} not found",

Binary file not shown.