Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Emscripten functions to run jsc #409

Merged
merged 3 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions lib/emscripten/src/emscripten_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/emscripten/src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
12 changes: 11 additions & 1 deletion lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions lib/emscripten/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/emscripten/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down