diff --git a/CHANGELOG.md b/CHANGELOG.md index 91b04b3ad92..a06380a5480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All PRs to the Wasmer repository must add to this file. Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#409](https://github.com/wasmerio/wasmer/pull/409) Improved Emscripten functions to run JavascriptCore compiled to wasm - [#399](https://github.com/wasmerio/wasmer/pull/399) Add example of using a plugin extended from WASI - [#397](https://github.com/wasmerio/wasmer/pull/397) Fix WASI fs abstraction to work on Windows - [#390](https://github.com/wasmerio/wasmer/pull/390) Pin released wapm version and add it as a git submodule diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 5b14a109948..8e107bd3c7a 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -15,6 +15,15 @@ pub fn getTempRet0(ctx: &mut Ctx) -> i32 { get_emscripten_data(ctx).temp_ret_0 } +pub fn _atexit(_ctx: &mut Ctx, _func: i32) -> i32 { + debug!("emscripten::_atexit"); + // TODO: implement atexit properly + // __ATEXIT__.unshift({ + // func: func, + // arg: arg + // }); + 0 +} pub fn __Unwind_Backtrace(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::__Unwind_Backtrace"); 0 @@ -45,14 +54,42 @@ pub fn _dladdr(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_dladdr"); 0 } +pub fn _pthread_attr_init(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_attr_init"); + 0 +} +pub fn _pthread_attr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_attr_destroy"); + 0 +} +pub fn _pthread_attr_getstack( + _ctx: &mut Ctx, + _stackaddr: i32, + _stacksize: i32, + _other: i32, +) -> i32 { + debug!("emscripten::_pthread_attr_getstack"); + // TODO: Translate from Emscripten + // HEAP32[stackaddr >> 2] = STACK_BASE; + // HEAP32[stacksize >> 2] = TOTAL_STACK; + 0 +} pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_cond_destroy"); 0 } +pub fn _pthread_cond_timedwait(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 { + debug!("emscripten::_pthread_cond_timedwait"); + 0 +} pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_getspecific"); 0 } +pub fn _pthread_getattr_np(_ctx: &mut Ctx, _thread: i32, _attr: i32) -> i32 { + debug!("emscripten::_pthread_getattr_np"); + 0 +} pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_setspecific"); 0 @@ -69,6 +106,10 @@ pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i3 debug!("emscripten::_pthread_create"); 0 } +pub fn _pthread_detach(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_detach"); + 0 +} pub fn _pthread_join(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_join"); 0 diff --git a/lib/emscripten/src/exception.rs b/lib/emscripten/src/exception.rs index 1f2b098d8ac..f37c015e530 100644 --- a/lib/emscripten/src/exception.rs +++ b/lib/emscripten/src/exception.rs @@ -28,3 +28,9 @@ pub fn ___cxa_uncaught_exception(_ctx: &mut Ctx) -> i32 { debug!("emscripten::___cxa_uncaught_exception"); -1 } + +pub fn ___cxa_pure_virtual(_ctx: &mut Ctx) { + debug!("emscripten::___cxa_pure_virtual"); + // ABORT = true + panic!("Pure virtual function called!"); +} diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index c41e4b96d11..116a0e88d37 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -619,6 +619,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_llvm_eh_typeid_for" => func!(crate::process::_llvm_eh_typeid_for), "_raise" => func!(crate::process::_raise), "_sem_init" => func!(crate::process::_sem_init), + "_sem_destroy" => func!(crate::process::_sem_destroy), "_sem_post" => func!(crate::process::_sem_post), "_sem_wait" => func!(crate::process::_sem_wait), "_getgrent" => func!(crate::process::_getgrent), @@ -658,6 +659,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch), "___cxa_end_catch" => func!(crate::exception::___cxa_end_catch), "___cxa_uncaught_exception" => func!(crate::exception::___cxa_uncaught_exception), + "___cxa_pure_virtual" => func!(crate::exception::___cxa_pure_virtual), // Time "_gettimeofday" => func!(crate::time::_gettimeofday), @@ -686,6 +688,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_llvm_cos_f64" => func!(crate::math::_llvm_cos_f64), "_llvm_exp2_f32" => func!(crate::math::_llvm_exp2_f32), "_llvm_exp2_f64" => func!(crate::math::_llvm_exp2_f64), + "_llvm_trunc_f64" => func!(crate::math::_llvm_trunc_f64), "_emscripten_random" => func!(crate::math::_emscripten_random), // Jump @@ -704,6 +707,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_dlsym" => func!(crate::linking::_dlsym), // wasm32-unknown-emscripten + "_atexit" => func!(crate::emscripten_target::_atexit), "setTempRet0" => func!(crate::emscripten_target::setTempRet0), "getTempRet0" => func!(crate::emscripten_target::getTempRet0), "invoke_i" => func!(crate::emscripten_target::invoke_i), @@ -726,10 +730,15 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___resumeException" => func!(crate::emscripten_target::___resumeException), "_dladdr" => func!(crate::emscripten_target::_dladdr), "_pthread_create" => func!(crate::emscripten_target::_pthread_create), + "_pthread_detach" => func!(crate::emscripten_target::_pthread_detach), "_pthread_join" => func!(crate::emscripten_target::_pthread_join), - "_pthread_cond_destroy" => func!(crate::emscripten_target::_pthread_cond_destroy), + "_pthread_attr_init" => func!(crate::emscripten_target::_pthread_attr_init), + "_pthread_attr_destroy" => func!(crate::emscripten_target::_pthread_attr_destroy), + "_pthread_attr_getstack" => func!(crate::emscripten_target::_pthread_attr_getstack), "_pthread_cond_init" => func!(crate::emscripten_target::_pthread_cond_init), + "_pthread_cond_destroy" => func!(crate::emscripten_target::_pthread_cond_destroy), "_pthread_cond_signal" => func!(crate::emscripten_target::_pthread_cond_signal), + "_pthread_cond_timedwait" => func!(crate::emscripten_target::_pthread_cond_timedwait), "_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), @@ -743,6 +752,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock), "_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate), "_pthread_getspecific" => func!(crate::emscripten_target::_pthread_getspecific), + "_pthread_getattr_np" => func!(crate::emscripten_target::_pthread_getattr_np), "_pthread_setspecific" => func!(crate::emscripten_target::_pthread_setspecific), "_pthread_once" => func!(crate::emscripten_target::_pthread_once), "_pthread_key_create" => func!(crate::emscripten_target::_pthread_key_create), diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index e0eb10c7dc5..3256b49c53b 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -44,6 +44,11 @@ pub fn _llvm_exp2_f64(_ctx: &mut Ctx, value: f64) -> f64 { 2f64.powf(value) } +pub fn _llvm_trunc_f64(_ctx: &mut Ctx, value: f64) -> f64 { + debug!("emscripten::_llvm_trunc_f64"); + value.trunc() +} + pub fn _emscripten_random(_ctx: &mut Ctx) -> f64 { debug!("emscripten::_emscripten_random"); -1.0 diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index 319dc9eb466..dbbbcebc286 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -83,7 +83,12 @@ pub fn _raise(_ctx: &mut Ctx, _one: i32) -> i32 { pub fn _sem_init(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_sem_init"); - -1 + 0 +} + +pub fn _sem_destroy(_ctx: &mut Ctx, _one: i32) -> i32 { + debug!("emscripten::_sem_destroy"); + 0 } pub fn _sem_post(_ctx: &mut Ctx, _one: i32) -> i32 {