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

Binary file not shown.