From ad8178bb2a5f60ba0479abdf64f7e273caeed1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 19 May 2019 19:16:04 +0200 Subject: [PATCH 1/7] [pthread] `rwlock_destroy()`, `rwlock_init()` and `rwlock_wrlock()` --- lib/emscripten/src/README.md | 12 ++++++++++++ lib/emscripten/src/emscripten_target.rs | 12 ++++++++++++ lib/emscripten/src/lib.rs | 3 +++ 3 files changed, 27 insertions(+) diff --git a/lib/emscripten/src/README.md b/lib/emscripten/src/README.md index 54b9f9dc1..801a0f55e 100644 --- a/lib/emscripten/src/README.md +++ b/lib/emscripten/src/README.md @@ -52,6 +52,18 @@ - **\_pthread_key_create**     [:top:](#host-apis) ```rust + ``` +- **\_pthread_rwlock_destroy**     [:top:](#host-apis) + ```rust + + ``` +- **\_pthread_rwlock_init**     [:top:](#host-apis) + ```rust + + ``` +- **\_pthread_rwlock_wrlock**     [:top:](#host-apis) + ```rust + ``` - **\_pthread_setspecific**     [:top:](#host-apis) ```rust diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 88073bc32..17c0d2aa2 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -105,6 +105,18 @@ pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_key_create"); 0 } +pub fn _pthread_rwlock_destroy(_ctx: &mut Ctx, _rwlock: i32) -> i32 { + debug!("emscripten::_pthread_rwlock_destroy({})", _rwlock); + 0 +} +pub fn _pthread_rwlock_init(_ctx: &mut Ctx, _rwlock: i32, _attr: i32) -> i32 { + debug!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr); + 0 +} +pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 { + debug!("emscripten::_pthread_rwlock_wrlock({})", _rwlock); + 0 +} pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 { debug!("emscripten::_pthread_create"); 0 diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 88237eb29..dbdd78d17 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -772,6 +772,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_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), + "_pthread_rwlock_destroy" => func!(crate::emscripten_target::_pthread_rwlock_destroy), + "_pthread_rwlock_init" => func!(crate::emscripten_target::_pthread_rwlock_init), + "_pthread_rwlock_wrlock" => func!(crate::emscripten_target::_pthread_rwlock_wrlock), "___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0), "_getdtablesize" => func!(crate::emscripten_target::_getdtablesize), "_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr), From 7690febe77a91a5cef1a5152ffffe5c7a852599a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 19 May 2019 19:37:57 +0200 Subject: [PATCH 2/7] `getnameinfo()` --- lib/emscripten/src/emscripten_target.rs | 14 ++++++++++++++ lib/emscripten/src/lib.rs | 1 + 2 files changed, 15 insertions(+) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 17c0d2aa2..44820ad63 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -228,6 +228,20 @@ pub fn _getloadavg(_ctx: &mut Ctx, _loadavg: i32, _nelem: i32) -> i32 { debug!("emscripten::getloadavg"); 0 } +pub fn _getnameinfo( + _ctx: &mut Ctx, + _addr: i32, + _addrlen: i32, + _host: i32, + _hostlen: i32, + _serv: i32, + _servlen: i32, + _flags: i32 +) -> i32 { + debug!("emscripten::_getnameinfo({}, {}, {}, {}, {}, {}, {})", + _addr, _addrlen, _host, _hostlen, _serv, _servlen, _flags); + 0 +} // Invoke functions // They save the stack to allow unwinding diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index dbdd78d17..828b3eb6e 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -780,6 +780,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr), "_gethostbyname_r" => func!(crate::emscripten_target::_gethostbyname_r), "_getloadavg" => func!(crate::emscripten_target::_getloadavg), + "_getnameinfo" => func!(crate::emscripten_target::_getnameinfo), "invoke_dii" => func!(crate::emscripten_target::invoke_dii), "invoke_diiii" => func!(crate::emscripten_target::invoke_diiii), "invoke_iiiii" => func!(crate::emscripten_target::invoke_iiiii), From 2eb5ca1e4819d9e16ae284c62637791240032b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 19 May 2019 20:16:00 +0200 Subject: [PATCH 3/7] `_gai_strerror()` --- lib/emscripten/src/emscripten_target.rs | 6 ++++++ lib/emscripten/src/lib.rs | 1 + 2 files changed, 7 insertions(+) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 44820ad63..df3319ab8 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -197,6 +197,12 @@ pub fn ___gxx_personality_v0( debug!("emscripten::___gxx_personality_v0"); 0 } + +pub fn _gai_strerror(_ctx: &mut Ctx, _ecode: i32) -> i32 { + debug!("emscripten::_gai_strerror({})", _ecode); + 0 +} + #[cfg(target_os = "linux")] pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 { debug!("emscripten::getdtablesize"); diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 828b3eb6e..039ad2af6 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -776,6 +776,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_pthread_rwlock_init" => func!(crate::emscripten_target::_pthread_rwlock_init), "_pthread_rwlock_wrlock" => func!(crate::emscripten_target::_pthread_rwlock_wrlock), "___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0), + "_gai_strerror" => func!(crate::emscripten_target::_gai_strerror), "_getdtablesize" => func!(crate::emscripten_target::_getdtablesize), "_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr), "_gethostbyname_r" => func!(crate::emscripten_target::_gethostbyname_r), From f8cfb04e29c69e6d42c9c82638ee1881f91e67b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 19 May 2019 20:24:49 +0200 Subject: [PATCH 4/7] `_alarm()` --- lib/emscripten/src/emscripten_target.rs | 5 +++++ lib/emscripten/src/lib.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index df3319ab8..3e0ab599a 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -15,6 +15,11 @@ pub fn getTempRet0(ctx: &mut Ctx) -> i32 { get_emscripten_data(ctx).temp_ret_0 } +pub fn _alarm(_ctx: &mut Ctx, _seconds: u32) -> i32 { + debug!("emscripten::_alarm({})", _seconds); + 0 +} + pub fn _atexit(_ctx: &mut Ctx, _func: i32) -> i32 { debug!("emscripten::_atexit"); // TODO: implement atexit properly diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 039ad2af6..5fc06d74b 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -722,6 +722,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_dlsym" => func!(crate::linking::_dlsym), // wasm32-unknown-emscripten + "_alarm" => func!(crate::emscripten_target::_alarm), "_atexit" => func!(crate::emscripten_target::_atexit), "setTempRet0" => func!(crate::emscripten_target::setTempRet0), "getTempRet0" => func!(crate::emscripten_target::getTempRet0), From 8995060f9bcb54d71c98134bfc94ead8395cd668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 19 May 2019 20:53:24 +0200 Subject: [PATCH 5/7] Mocks for `_getcontext`, `_makecontext`, `_setcontext` and `_swapcontext` --- lib/emscripten/src/emscripten_target.rs | 17 +++++++++++++++++ lib/emscripten/src/lib.rs | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 3e0ab599a..5dbbe1266 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -856,3 +856,20 @@ pub fn invoke_viidddddddd( a10 ); } + +// ucontext.h +pub fn _getcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { + debug!("emscripten::_getcontext({})", _ucp); + 0 +} +pub fn _makecontext(_ctx: &mut Ctx, _ucp: i32, _func: i32, _argc: i32, _argv: i32) { + debug!("emscripten::_makecontext({}, {}, {}, {})", _ucp, _func, _argc, _argv); +} +pub fn _setcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { + debug!("emscripten::_setcontext({})", _ucp); + 0 +} +pub fn _swapcontext(_ctx: &mut Ctx, _oucp: i32, _ucp: i32) -> i32 { + debug!("emscripten::_swapcontext({}, {})", _oucp, _ucp); + 0 +} diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 5fc06d74b..4e1e746bf 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -822,6 +822,12 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "invoke_viid" => func!(crate::emscripten_target::invoke_viid), "invoke_viidii" => func!(crate::emscripten_target::invoke_viidii), "invoke_viidddddddd" => func!(crate::emscripten_target::invoke_viidddddddd), + + // ucontext.h + "_getcontext" => func!(crate::emscripten_target::_getcontext), + "_makecontext" => func!(crate::emscripten_target::_makecontext), + "_setcontext" => func!(crate::emscripten_target::_setcontext), + "_swapcontext" => func!(crate::emscripten_target::_swapcontext), }; for null_func_name in globals.null_func_names.iter() { From 34e16d4a84f8fa14d67b556b569fa802cd5ffd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 20 May 2019 22:54:58 +0200 Subject: [PATCH 6/7] Move `ucontext` related functions to their own namespace --- lib/emscripten/src/emscripten_target.rs | 17 ----------------- lib/emscripten/src/lib.rs | 11 ++++++----- lib/emscripten/src/ucontext.rs | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 lib/emscripten/src/ucontext.rs diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 5dbbe1266..3e0ab599a 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -856,20 +856,3 @@ pub fn invoke_viidddddddd( a10 ); } - -// ucontext.h -pub fn _getcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { - debug!("emscripten::_getcontext({})", _ucp); - 0 -} -pub fn _makecontext(_ctx: &mut Ctx, _ucp: i32, _func: i32, _argc: i32, _argv: i32) { - debug!("emscripten::_makecontext({}, {}, {}, {})", _ucp, _func, _argc, _argv); -} -pub fn _setcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { - debug!("emscripten::_setcontext({})", _ucp); - 0 -} -pub fn _swapcontext(_ctx: &mut Ctx, _oucp: i32, _ucp: i32) -> i32 { - debug!("emscripten::_swapcontext({}, {})", _oucp, _ucp); - 0 -} diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 4e1e746bf..f60156bab 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -44,6 +44,7 @@ mod signal; mod storage; mod syscalls; mod time; +mod ucontext; mod utils; mod varargs; @@ -823,11 +824,11 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "invoke_viidii" => func!(crate::emscripten_target::invoke_viidii), "invoke_viidddddddd" => func!(crate::emscripten_target::invoke_viidddddddd), - // ucontext.h - "_getcontext" => func!(crate::emscripten_target::_getcontext), - "_makecontext" => func!(crate::emscripten_target::_makecontext), - "_setcontext" => func!(crate::emscripten_target::_setcontext), - "_swapcontext" => func!(crate::emscripten_target::_swapcontext), + // ucontext + "_getcontext" => func!(crate::ucontext::_getcontext), + "_makecontext" => func!(crate::ucontext::_makecontext), + "_setcontext" => func!(crate::ucontext::_setcontext), + "_swapcontext" => func!(crate::ucontext::_swapcontext), }; for null_func_name in globals.null_func_names.iter() { diff --git a/lib/emscripten/src/ucontext.rs b/lib/emscripten/src/ucontext.rs new file mode 100644 index 000000000..a7dce73a1 --- /dev/null +++ b/lib/emscripten/src/ucontext.rs @@ -0,0 +1,18 @@ +use wasmer_runtime_core::vm::Ctx; + + +pub fn _getcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { + debug!("emscripten::_getcontext({})", _ucp); + 0 +} +pub fn _makecontext(_ctx: &mut Ctx, _ucp: i32, _func: i32, _argc: i32, _argv: i32) { + debug!("emscripten::_makecontext({}, {}, {}, {})", _ucp, _func, _argc, _argv); +} +pub fn _setcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { + debug!("emscripten::_setcontext({})", _ucp); + 0 +} +pub fn _swapcontext(_ctx: &mut Ctx, _oucp: i32, _ucp: i32) -> i32 { + debug!("emscripten::_swapcontext({}, {})", _oucp, _ucp); + 0 +} From 490b94b814af9a1371896b74ad72f0f5521221ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 21 May 2019 19:12:35 +0200 Subject: [PATCH 7/7] Fix linting --- lib/emscripten/src/emscripten_target.rs | 8 +++++--- lib/emscripten/src/ucontext.rs | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 3e0ab599a..36f3650ee 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -247,10 +247,12 @@ pub fn _getnameinfo( _hostlen: i32, _serv: i32, _servlen: i32, - _flags: i32 + _flags: i32, ) -> i32 { - debug!("emscripten::_getnameinfo({}, {}, {}, {}, {}, {}, {})", - _addr, _addrlen, _host, _hostlen, _serv, _servlen, _flags); + debug!( + "emscripten::_getnameinfo({}, {}, {}, {}, {}, {}, {})", + _addr, _addrlen, _host, _hostlen, _serv, _servlen, _flags + ); 0 } diff --git a/lib/emscripten/src/ucontext.rs b/lib/emscripten/src/ucontext.rs index a7dce73a1..abf4e1de2 100644 --- a/lib/emscripten/src/ucontext.rs +++ b/lib/emscripten/src/ucontext.rs @@ -1,12 +1,14 @@ use wasmer_runtime_core::vm::Ctx; - pub fn _getcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { debug!("emscripten::_getcontext({})", _ucp); 0 } pub fn _makecontext(_ctx: &mut Ctx, _ucp: i32, _func: i32, _argc: i32, _argv: i32) { - debug!("emscripten::_makecontext({}, {}, {}, {})", _ucp, _func, _argc, _argv); + debug!( + "emscripten::_makecontext({}, {}, {}, {})", + _ucp, _func, _argc, _argv + ); } pub fn _setcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 { debug!("emscripten::_setcontext({})", _ucp);