1
0
Fork 0
forked from AbleOS/ableos

Simplified signature checking in wasm jumploader

This commit is contained in:
Erin 2022-05-08 13:32:19 +02:00 committed by ondra05
parent ae70548cc0
commit 86f466cdb0

View file

@ -14,108 +14,24 @@ const SEND_SIGNAL_INDEX: usize = 1;
pub struct HostExternals; pub struct HostExternals;
impl HostExternals { impl HostExternals {
fn check_signature(&self, index: usize, signature: &Signature) -> bool { fn check_signature(&self, index: usize, signature: &Signature) -> bool {
match index { let (params, ret_ty): (&[_], _) = match index {
ADD_FUNC_INDEX => { ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
let (params, ret_ty): (&[ValueType], Option<ValueType>) = SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
(&[ValueType::I32, ValueType::I32], Some(ValueType::I32)); GET_TIME_INDEX => (&[], Some(ValueType::I32)),
if params.len() != signature.params().len() { GET_RANDOM_INDEX => (&[], Some(ValueType::I32)),
return false; GET_INPUT_INDEX => (&[], Some(ValueType::I32)),
} PRINT_CHAR => (&[ValueType::I32], None),
if ret_ty != signature.return_type() { _ => return false,
return false; };
}
for (ty, param) in params.iter().zip(signature.params()) {
if *ty != *param {
return false;
}
}
true
}
SEND_SIGNAL_INDEX => { if params.len() != signature.params().len() || ret_ty != signature.return_type() {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = false
(&[ValueType::I32, ValueType::I32], Some(ValueType::I32)); } else {
if params.len() != signature.params().len() { params
return false; .iter()
} .zip(signature.params())
if ret_ty != signature.return_type() { .find(|(ty, param)| ty != param)
return false; .is_none()
}
for (ty, param) in params.iter().zip(signature.params()) {
if *ty != *param {
return false;
}
}
true
}
GET_TIME_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) =
(&[], Some(ValueType::I32));
if params.len() != signature.params().len() {
return false;
}
if ret_ty != signature.return_type() {
return false;
}
for (ty, param) in params.iter().zip(signature.params()) {
if *ty != *param {
return false;
}
}
true
}
GET_RANDOM_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) =
(&[], Some(ValueType::I32));
if params.len() != signature.params().len() {
return false;
}
if ret_ty != signature.return_type() {
return false;
}
for (ty, param) in params.iter().zip(signature.params()) {
if *ty != *param {
return false;
}
}
true
}
GET_INPUT_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) =
(&[], Some(ValueType::I32));
if params.len() != signature.params().len() {
return false;
}
if ret_ty != signature.return_type() {
return false;
}
for (ty, param) in params.iter().zip(signature.params()) {
if *ty != *param {
return false;
}
}
true
}
PRINT_CHAR => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = (&[ValueType::I32], None);
if params.len() != signature.params().len() {
return false;
}
if ret_ty != signature.return_type() {
return false;
}
for (ty, param) in params.iter().zip(signature.params()) {
if *ty != *param {
return false;
}
}
true
}
_ => false,
} }
} }
} }