From c58a7e0c37a5108a16c5869d8936e3a71525278a Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 20 Mar 2019 16:46:42 -0700 Subject: [PATCH] stub out/add the rest --- lib/emscripten/src/emscripten_target.rs | 37 ++++++++++++++++ lib/emscripten/src/exec.rs | 13 ++++++ lib/emscripten/src/io/unix.rs | 59 ++++++++++++++++++++++++- lib/emscripten/src/lib.rs | 20 +++++++++ lib/emscripten/src/lock.rs | 5 +++ lib/emscripten/src/math.rs | 12 +++++ lib/emscripten/src/process.rs | 5 +++ 7 files changed, 150 insertions(+), 1 deletion(-) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 656a5d7f8..c1a29750b 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -1,6 +1,8 @@ #![allow(non_snake_case)] use crate::env::get_emscripten_data; +#[cfg(target_os = "linux")] +use libc::getdtablesize; use wasmer_runtime_core::vm::Ctx; pub fn setTempRet0(_ctx: &mut Ctx, _a: i32) { @@ -171,6 +173,10 @@ pub fn _pthread_rwlock_unlock(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_rwlock_unlock"); 0 } +pub fn _pthread_setcancelstate(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_setcancelstate"); + 0 +} pub fn ___gxx_personality_v0( _ctx: &mut Ctx, _a: i32, @@ -183,6 +189,37 @@ pub fn ___gxx_personality_v0( debug!("emscripten::___gxx_personality_v0"); 0 } +#[cfg(target_os = "linux")] +pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 { + debug!("emscripten::getdtablesize"); + unsafe { getdtablesize() } +} +#[cfg(not(target_os = "linux"))] +pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 { + debug!("emscripten::getdtablesize"); + -1 +} +pub fn _gethostbyaddr(_ctx: &mut Ctx, _addr: i32, _addrlen: i32, _atype: i32) -> i32 { + debug!("emscripten::gethostbyaddr"); + 0 +} +pub fn _gethostbyname_r( + _ctx: &mut Ctx, + _name: i32, + _ret: i32, + _buf: i32, + _buflen: i32, + _out: i32, + _err: i32, +) -> i32 { + debug!("emscripten::gethostbyname_r"); + 0 +} +// NOTE: php.js has proper impl; libc has proper impl for linux +pub fn _getloadavg(_ctx: &mut Ctx, _loadavg: i32, _nelem: i32) -> i32 { + debug!("emscripten::getloadavg"); + 0 +} // round 2 pub fn nullFunc_dii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_dii"); diff --git a/lib/emscripten/src/exec.rs b/lib/emscripten/src/exec.rs index f47f09bf0..5751e3199 100644 --- a/lib/emscripten/src/exec.rs +++ b/lib/emscripten/src/exec.rs @@ -1,3 +1,4 @@ +use crate::varargs::VarArgs; use libc::execvp as libc_execvp; use std::cell::Cell; use std::ffi::CString; @@ -38,3 +39,15 @@ pub fn execvp(ctx: &mut Ctx, command_name_offset: u32, argv_offset: u32) -> i32 let args_pointer = argv.as_ptr(); unsafe { libc_execvp(command_pointer, args_pointer) } } + +/// execl +pub fn execl(_ctx: &mut Ctx, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 { + debug!("emscripten::execl"); + -1 +} + +/// execle +pub fn execle(_ctx: &mut Ctx, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 { + debug!("emscripten::execle"); + -1 +} diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index da3ddeff9..f6abad8d0 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -1,4 +1,4 @@ -use libc::printf as _printf; +use libc::{chroot as _chroot, printf as _printf}; use wasmer_runtime_core::vm::Ctx; @@ -15,3 +15,60 @@ pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { _printf(addr, extra) } } + +/// chroot +pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 { + let name = emscripten_memory_pointer!(ctx.memory(0), name_ptr) as *const i8; + unsafe { _chroot(name) } +} + +/// getprotobyname +pub fn getprotobyname(ctx: &mut Ctx, name_ptr: i32) -> i32 { + debug!("emscripten::getprotobyname"); + // TODO: actually do this logic to return correctly + let _name = emscripten_memory_pointer!(ctx.memory(0), name_ptr) as *const i8; + //unsafe { _getprotobyname(name) as i32 } + 0 +} + +/// getprotobynumber +pub fn getprotobynumber(_ctx: &mut Ctx, _one: i32) -> i32 { + debug!("emscripten::getprotobynumber"); + 0 +} + +// REVIEW: does this belong here? +/// getpwuid +pub fn getpwuid(_ctx: &mut Ctx, _uid: i32) -> i32 { + debug!("emscripten::getpwuid"); + // TODO: actually do this logic to return correctly + 0 +} + +/// longjmp +pub fn longjmp(_ctx: &mut Ctx, _one: i32, _two: i32) { + debug!("emscripten::longjump"); +} + +/// sigdelset +pub fn sigdelset(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::sigdelset"); + 0 +} + +/// sigfillset +pub fn sigfillset(_ctx: &mut Ctx, _one: i32) -> i32 { + debug!("emscripten::sigfillset"); + 0 +} + +/// tzset +pub fn tzset(_ctx: &mut Ctx) { + debug!("emscripten::tzset"); +} + +/// strptime +pub fn strptime(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { + debug!("emscripten::strptime"); + 0 +} diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 98093ef09..4dea65c2f 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -421,9 +421,21 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___lock" => func!(crate::lock::___lock), "___unlock" => func!(crate::lock::___unlock), "___wait" => func!(crate::lock::___wait), + "_flock" => func!(crate::lock::_flock), + "_chroot" => func!(crate::io::chroot), + "_getprotobyname" => func!(crate::io::getprotobyname), + "_getprotobynumber" => func!(crate::io::getprotobynumber), + "_getpwuid" => func!(crate::io::getpwuid), + "_longjmp" => func!(crate::io::longjmp), + "_sigdelset" => func!(crate::io::sigdelset), + "_sigfillset" => func!(crate::io::sigfillset), + "_tzset" => func!(crate::io::tzset), + "_strptime" => func!(crate::io::strptime), // exec "_execvp" => func!(crate::exec::execvp), + "_execl" => func!(crate::exec::execl), + "_execle" => func!(crate::exec::execle), // exit "__exit" => func!(crate::exit::exit), @@ -547,6 +559,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_setgroups" => func!(crate::process::_setgroups), "_setitimer" => func!(crate::process::_setitimer), "_usleep" => func!(crate::process::_usleep), + "_nanosleep" => func!(crate::process::_nanosleep), "_utimes" => func!(crate::process::_utimes), "_waitpid" => func!(crate::process::_waitpid), @@ -594,6 +607,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_llvm_log2_f64" => func!(crate::math::_llvm_log2_f64), "_llvm_log10_f32" => func!(crate::math::_llvm_log10_f32), "_llvm_log2_f32" => func!(crate::math::_llvm_log2_f64), + "_llvm_sin_f64" => func!(crate::math::_llvm_sin_f64), + "_llvm_cos_f64" => func!(crate::math::_llvm_cos_f64), "_emscripten_random" => func!(crate::math::_emscripten_random), // Jump @@ -641,7 +656,12 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_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), + "_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate), "___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0), + "_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), // round 2 "nullFunc_dii" => func!(crate::emscripten_target::nullFunc_dii), "nullFunc_diiii" => func!(crate::emscripten_target::nullFunc_diiii), diff --git a/lib/emscripten/src/lock.rs b/lib/emscripten/src/lock.rs index badb47a1b..f6804e9d1 100644 --- a/lib/emscripten/src/lock.rs +++ b/lib/emscripten/src/lock.rs @@ -15,3 +15,8 @@ pub fn ___unlock(_ctx: &mut Ctx, _what: c_int) { pub fn ___wait(_ctx: &mut Ctx, _which: u32, _varargs: u32, _three: u32, _four: u32) { debug!("emscripten::___wait"); } + +pub fn _flock(_ctx: &mut Ctx, _fd: u32, _op: u32) -> u32 { + debug!("emscripten::_flock"); + 0 +} diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index 63eee79b4..c73580d77 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -12,6 +12,18 @@ pub fn _llvm_log2_f64(_ctx: &mut Ctx, value: f64) -> f64 { value.log2() } +/// emscripten: _llvm_sin_f64 +pub fn _llvm_sin_f64(_ctx: &mut Ctx, value: f64) -> f64 { + debug!("emscripten::_llvm_sin_f64"); + value.sin() +} + +/// emscripten: _llvm_cos_f64 +pub fn _llvm_cos_f64(_ctx: &mut Ctx, value: f64) -> f64 { + debug!("emscripten::_llvm_cos_f64"); + value.cos() +} + pub fn _llvm_log10_f32(_ctx: &mut Ctx, _value: f64) -> f64 { debug!("emscripten::_llvm_log10_f32"); -1.0 diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index 17a31d912..ce47502e7 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -121,6 +121,11 @@ pub fn _usleep(_ctx: &mut Ctx, _one: i32) -> i32 { -1 } +pub fn _nanosleep(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::_nanosleep"); + -1 +} + pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::_utimes"); -1