Merge branch 'master' of https://github.com/AbleTheAbove/ableos-wasm-loader
This commit is contained in:
commit
5b01f3c2b1
15
src/main.rs
15
src/main.rs
|
@ -14,12 +14,12 @@ impl HostFunctions {
|
||||||
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
||||||
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index.into() {
|
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index.into() {
|
||||||
SysCall::KILL => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
SysCall::KILL => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
||||||
|
SysCall::EMPTY => (&[], None),
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
signature.params() == params && signature.return_type() == ret_ty
|
signature.params() == params && signature.return_type() == ret_ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Externals for HostFunctions {
|
impl Externals for HostFunctions {
|
||||||
fn invoke_index(
|
fn invoke_index(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -34,12 +34,12 @@ impl Externals for HostFunctions {
|
||||||
|
|
||||||
Ok(Some(RuntimeValue::I32(result as i32)))
|
Ok(Some(RuntimeValue::I32(result as i32)))
|
||||||
}
|
}
|
||||||
SysCall::CONSOLE_RESET => {}
|
SysCall::EMPTY => Ok(None),
|
||||||
SysCall::CONSOLE_IN => {}
|
// SysCall::CONSOLE_RESET => {}
|
||||||
SysCall::CONSOLE_OUT => {}
|
// SysCall::CONSOLE_IN => {}
|
||||||
SysCall::CONSOLE_GET_TITLE => {}
|
// SysCall::CONSOLE_OUT => {}
|
||||||
SysCall::CONSOLE_SET_TITLE => {}
|
// SysCall::CONSOLE_GET_TITLE => {}
|
||||||
|
// SysCall::CONSOLE_SET_TITLE => {}
|
||||||
_ => panic!("Unimplemented function at {}", index),
|
_ => panic!("Unimplemented function at {}", index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ impl ModuleImportResolver for HostFunctions {
|
||||||
fn resolve_func(&self, field_name: &str, signature: &Signature) -> Result<FuncRef, Error> {
|
fn resolve_func(&self, field_name: &str, signature: &Signature) -> Result<FuncRef, Error> {
|
||||||
let index = match field_name {
|
let index = match field_name {
|
||||||
"add" => SysCall::KILL as usize,
|
"add" => SysCall::KILL as usize,
|
||||||
|
"empty" => SysCall::EMPTY as usize,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Error::Instantiation(format!(
|
return Err(Error::Instantiation(format!(
|
||||||
"Export {} not found",
|
"Export {} not found",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
macro_rules! syscall_enum {
|
macro_rules! syscall_enum {
|
||||||
|
() => {};
|
||||||
(@get_last $Variant:ident) => {
|
(@get_last $Variant:ident) => {
|
||||||
Self::$Variant
|
Self::$Variant
|
||||||
};
|
};
|
||||||
|
@ -71,9 +72,6 @@ syscall_enum! {
|
||||||
SOCKET_SEND=42,
|
SOCKET_SEND=42,
|
||||||
SOCKET_RECEIVE=43,
|
SOCKET_RECEIVE=43,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Security Syscalls
|
// Security Syscalls
|
||||||
ENCRYPT=50,
|
ENCRYPT=50,
|
||||||
EMPTY=0xFFFF,
|
EMPTY=0xFFFF,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
(module
|
(module
|
||||||
(import "host" "add" (func $add (param i32 i32)(result i32)))
|
(import "host" "add" (func $add (param i32 i32)(result i32)))
|
||||||
|
(; (import "host" "empty" (func $empty)) ;)
|
||||||
(func (export "main") (result i32)
|
(func (export "main") (result i32)
|
||||||
|
(; (call $empty) ;)
|
||||||
(call $add (i32.const 123) (i32.const 456))
|
(call $add (i32.const 123) (i32.const 456))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Reference in a new issue