Skip to content

Commit

Permalink
Merge #456
Browse files Browse the repository at this point in the history
456: Command/openssl r=syrusakbary a=piranna

Mocks for missing functions needed by `openssl` command.

Co-authored-by: Jesús Leganés-Combarro 'piranna <[email protected]>
  • Loading branch information
bors[bot] and piranna committed May 21, 2019
2 parents f3220a0 + 490b94b commit 7b9e289
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/emscripten/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
- **\_pthread_key_create** &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#host-apis)
```rust

```
- **\_pthread_rwlock_destroy** &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#host-apis)
```rust

```
- **\_pthread_rwlock_init** &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#host-apis)
```rust

```
- **\_pthread_rwlock_wrlock** &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#host-apis)
```rust

```
- **\_pthread_setspecific** &nbsp;&nbsp;&nbsp;&nbsp;[:top:](#host-apis)
```rust
Expand Down
39 changes: 39 additions & 0 deletions lib/emscripten/src/emscripten_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,6 +110,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
Expand Down Expand Up @@ -185,6 +202,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");
Expand Down Expand Up @@ -216,6 +239,22 @@ 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
Expand Down
13 changes: 13 additions & 0 deletions lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod signal;
mod storage;
mod syscalls;
mod time;
mod ucontext;
mod utils;
mod varargs;

Expand Down Expand Up @@ -722,6 +723,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),
Expand Down Expand Up @@ -772,11 +774,16 @@ 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),
"_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),
"_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),
Expand Down Expand Up @@ -816,6 +823,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
"_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() {
Expand Down
20 changes: 20 additions & 0 deletions lib/emscripten/src/ucontext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
}

0 comments on commit 7b9e289

Please sign in to comment.