diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs new file mode 100644 index 000000000..4f831e909 --- /dev/null +++ b/lib/emscripten/src/emscripten_target.rs @@ -0,0 +1,175 @@ +use crate::env::get_emscripten_data; +use wasmer_runtime_core::vm::Ctx; + +pub fn setTempRet0(ctx: &mut Ctx, a: i32) { + debug!("emscripten::setTempRet0"); +} +pub fn getTempRet0(ctx: &mut Ctx) -> i32 { + debug!("emscripten::getTempRet0"); + 0 +} +pub fn nullFunc_ji(ctx: &mut Ctx, a: i32) { + debug!("emscripten::nullFunc_ji"); +} +pub fn invoke_i(ctx: &mut Ctx, index: i32) -> i32 { + debug!("emscripten::invoke_i"); + if let Some(dyn_call_i) = &get_emscripten_data(ctx).dyn_call_i { + dyn_call_i.call(index).unwrap() + } else { + panic!("dyn_call_i is set to None"); + } +} +pub fn invoke_ii(ctx: &mut Ctx, index: i32, a1: i32) -> i32 { + debug!("emscripten::invoke_ii"); + if let Some(dyn_call_ii) = &get_emscripten_data(ctx).dyn_call_ii { + dyn_call_ii.call(index, a1).unwrap() + } else { + panic!("dyn_call_ii is set to None"); + } +} +pub fn invoke_iii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> i32 { + debug!("emscripten::invoke_iii"); + if let Some(dyn_call_iii) = &get_emscripten_data(ctx).dyn_call_iii { + dyn_call_iii.call(index, a1, a2).unwrap() + } else { + panic!("dyn_call_iii is set to None"); + } +} +pub fn invoke_iiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { + debug!("emscripten::invoke_iiii"); + if let Some(dyn_call_iiii) = &get_emscripten_data(ctx).dyn_call_iiii { + dyn_call_iiii.call(index, a1, a2, a3).unwrap() + } else { + panic!("dyn_call_iiii is set to None"); + } +} +pub fn invoke_v(ctx: &mut Ctx, index: i32) { + debug!("emscripten::invoke_v"); + if let Some(dyn_call_v) = &get_emscripten_data(ctx).dyn_call_v { + dyn_call_v.call(index).unwrap(); + } else { + panic!("dyn_call_v is set to None"); + } +} +pub fn invoke_vi(ctx: &mut Ctx, index: i32, a1: i32) { + debug!("emscripten::invoke_vi"); + if let Some(dyn_call_vi) = &get_emscripten_data(ctx).dyn_call_vi { + dyn_call_vi.call(index, a1).unwrap(); + } else { + panic!("dyn_call_vi is set to None"); + } +} +pub fn invoke_vii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) { + debug!("emscripten::invoke_vii"); + if let Some(dyn_call_vii) = &get_emscripten_data(ctx).dyn_call_vii { + dyn_call_vii.call(index, a1, a2).unwrap(); + } else { + panic!("dyn_call_vii is set to None"); + } +} +pub fn invoke_viii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) { + debug!("emscripten::invoke_viii"); + if let Some(dyn_call_viii) = &get_emscripten_data(ctx).dyn_call_viii { + dyn_call_viii.call(index, a1, a2, a3).unwrap(); + } else { + panic!("dyn_call_viii is set to None"); + } +} +pub fn invoke_viiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) { + debug!("emscripten::invoke_viiii"); + if let Some(dyn_call_viiii) = &get_emscripten_data(ctx).dyn_call_viiii { + dyn_call_viiii.call(index, a1, a2, a3, a4).unwrap(); + } else { + panic!("dyn_call_viiii is set to None"); + } +} +pub fn __Unwind_Backtrace(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::__Unwind_Backtrace"); + 0 +} +pub fn __Unwind_FindEnclosingFunction(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::__Unwind_FindEnclosingFunction"); + 0 +} +pub fn __Unwind_GetIPInfo(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::__Unwind_GetIPInfo"); + 0 +} +pub fn ___cxa_find_matching_catch_2(ctx: &mut Ctx) -> i32 { + debug!("emscripten::___cxa_find_matching_catch_2"); + 0 +} +pub fn ___cxa_find_matching_catch_3(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::___cxa_find_matching_catch_3"); + 0 +} +pub fn ___cxa_free_exception(ctx: &mut Ctx, a: i32) { + debug!("emscripten::___cxa_free_exception"); +} +pub fn ___resumeException(ctx: &mut Ctx, a: i32) { + debug!("emscripten::___resumeException"); +} +pub fn _dladdr(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::_dladdr"); + 0 +} +pub fn _pthread_cond_destroy(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_cond_destroy"); + 0 +} +pub fn _pthread_cond_init(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::_pthread_cond_init"); + 0 +} +pub fn _pthread_cond_signal(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_cond_signal"); + 0 +} +pub fn _pthread_cond_wait(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::_pthread_cond_wait"); + 0 +} +pub fn _pthread_condattr_destroy(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_condattr_destroy"); + 0 +} +pub fn _pthread_condattr_init(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_condattr_init"); + 0 +} +pub fn _pthread_condattr_setclock(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::_pthread_condattr_setclock"); + 0 +} +pub fn _pthread_mutex_destroy(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_mutex_destroy"); + 0 +} +pub fn _pthread_mutex_init(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::_pthread_mutex_init"); + 0 +} +pub fn _pthread_mutexattr_destroy(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_mutexattr_destroy"); + 0 +} +pub fn _pthread_mutexattr_init(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_mutexattr_init"); + 0 +} +pub fn _pthread_mutexattr_settype(ctx: &mut Ctx, a: i32, b: i32) -> i32 { + debug!("emscripten::_pthread_mutexattr_settype"); + 0 +} +pub fn _pthread_rwlock_rdlock(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_rwlock_rdlock"); + 0 +} +pub fn _pthread_rwlock_unlock(ctx: &mut Ctx, a: i32) -> i32 { + debug!("emscripten::_pthread_rwlock_unlock"); + 0 +} +pub fn ___gxx_personality_v0(ctx: &mut Ctx, a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) -> i32 { + debug!("emscripten::___gxx_personality_v0"); + 0 +} diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 3ed5c36dd..a58b3b118 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -27,6 +27,7 @@ mod file_descriptor; pub mod stdio; // EMSCRIPTEN APIS +mod emscripten_target; mod env; mod errno; mod exception; @@ -92,8 +93,17 @@ pub struct EmscriptenData<'a> { pub memalign: Option>, pub memset: Func<'a, (u32, u32, u32), u32>, pub stack_alloc: Func<'a, u32, u32>, - pub jumps: Vec>, + + pub dyn_call_i: Option>, + pub dyn_call_ii: Option>, + pub dyn_call_iii: Option>, + pub dyn_call_iiii: Option>, + pub dyn_call_v: Option>, + pub dyn_call_vi: Option>, + pub dyn_call_vii: Option>, + pub dyn_call_viii: Option>, + pub dyn_call_viiii: Option>, } impl<'a> EmscriptenData<'a> { @@ -108,6 +118,16 @@ impl<'a> EmscriptenData<'a> { let memset = instance.func("_memset").unwrap(); let stack_alloc = instance.func("stackAlloc").unwrap(); + let dyn_call_i = instance.func("dynCall_i").ok(); + let dyn_call_ii = instance.func("dynCall_ii").ok(); + let dyn_call_iii = instance.func("dynCall_iii").ok(); + let dyn_call_iiii = instance.func("dynCall_iiii").ok(); + let dyn_call_v = instance.func("dynCall_v").ok(); + let dyn_call_vi = instance.func("dynCall_vi").ok(); + let dyn_call_vii = instance.func("dynCall_vii").ok(); + let dyn_call_viii = instance.func("dynCall_viii").ok(); + let dyn_call_viiii = instance.func("dynCall_viiii").ok(); + EmscriptenData { malloc, free, @@ -115,6 +135,15 @@ impl<'a> EmscriptenData<'a> { memset, stack_alloc, jumps: Vec::new(), + dyn_call_i, + dyn_call_ii, + dyn_call_iii, + dyn_call_iiii, + dyn_call_v, + dyn_call_vi, + dyn_call_vii, + dyn_call_viii, + dyn_call_viiii, } } } @@ -491,6 +520,42 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_dlopen" => func!(crate::linking::_dlopen), "_dlsym" => func!(crate::linking::_dlsym), + // wasm32-unknown-emscripten + "setTempRet0" => func!(crate::emscripten_target::setTempRet0), + "getTempRet0" => func!(crate::emscripten_target::getTempRet0), + "nullFunc_ji" => func!(crate::emscripten_target::nullFunc_ji), + "invoke_i" => func!(crate::emscripten_target::invoke_i), + "invoke_ii" => func!(crate::emscripten_target::invoke_ii), + "invoke_iii" => func!(crate::emscripten_target::invoke_iii), + "invoke_iiii" => func!(crate::emscripten_target::invoke_iiii), + "invoke_v" => func!(crate::emscripten_target::invoke_v), + "invoke_vi" => func!(crate::emscripten_target::invoke_vi), + "invoke_vii" => func!(crate::emscripten_target::invoke_vii), + "invoke_viii" => func!(crate::emscripten_target::invoke_viii), + "invoke_viiii" => func!(crate::emscripten_target::invoke_viiii), + "__Unwind_Backtrace" => func!(crate::emscripten_target::__Unwind_Backtrace), + "__Unwind_FindEnclosingFunction" => func!(crate::emscripten_target::__Unwind_FindEnclosingFunction), + "__Unwind_GetIPInfo" => func!(crate::emscripten_target::__Unwind_GetIPInfo), + "___cxa_find_matching_catch_2" => func!(crate::emscripten_target::___cxa_find_matching_catch_2), + "___cxa_find_matching_catch_3" => func!(crate::emscripten_target::___cxa_find_matching_catch_3), + "___cxa_free_exception" => func!(crate::emscripten_target::___cxa_free_exception), + "___resumeException" => func!(crate::emscripten_target::___resumeException), + "_dladdr" => func!(crate::emscripten_target::_dladdr), + "_pthread_cond_destroy" => func!(crate::emscripten_target::_pthread_cond_destroy), + "_pthread_cond_init" => func!(crate::emscripten_target::_pthread_cond_init), + "_pthread_cond_signal" => func!(crate::emscripten_target::_pthread_cond_signal), + "_pthread_cond_wait" => func!(crate::emscripten_target::_pthread_cond_wait), + "_pthread_condattr_destroy" => func!(crate::emscripten_target::_pthread_condattr_destroy), + "_pthread_condattr_init" => func!(crate::emscripten_target::_pthread_condattr_init), + "_pthread_condattr_setclock" => func!(crate::emscripten_target::_pthread_condattr_setclock), + "_pthread_mutex_destroy" => func!(crate::emscripten_target::_pthread_mutex_destroy), + "_pthread_mutex_init" => func!(crate::emscripten_target::_pthread_mutex_init), + "_pthread_mutexattr_destroy" => func!(crate::emscripten_target::_pthread_mutexattr_destroy), + "_pthread_mutexattr_init" => func!(crate::emscripten_target::_pthread_mutexattr_init), + "_pthread_mutexattr_settype" => func!(crate::emscripten_target::_pthread_mutexattr_settype), + "_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock), + "_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock), + "___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0), }, "global" => { "NaN" => Global::new(Value::F64(f64::NAN)),