From b78a8af228d016af38e876eca173cbb0ed31d072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 28 May 2019 09:39:49 +0200 Subject: [PATCH 01/16] Added missing functions for `pyodide` Since Pyodide is focused on running on desktop, this pull-request lacks Javascript runtime functions. It also sorted alphabetically some functions --- lib/emscripten/src/emscripten_target.rs | 116 ++++++++----- lib/emscripten/src/exception.rs | 20 +++ lib/emscripten/src/inet.rs | 6 + lib/emscripten/src/lib.rs | 113 +++++++++++-- lib/emscripten/src/libc.rs | 72 ++++++++ lib/emscripten/src/llvm.rs | 9 + lib/emscripten/src/math.rs | 10 ++ lib/emscripten/src/process.rs | 25 +++ lib/emscripten/src/signal.rs | 5 + lib/emscripten/src/syscalls/mod.rs | 214 +++++++++++++++++++++++- lib/emscripten/src/time.rs | 13 ++ lib/emscripten/src/unistd.rs | 6 + 12 files changed, 554 insertions(+), 55 deletions(-) create mode 100644 lib/emscripten/src/inet.rs create mode 100644 lib/emscripten/src/libc.rs create mode 100644 lib/emscripten/src/llvm.rs create mode 100644 lib/emscripten/src/unistd.rs diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 36f3650ee5e..dbbe4a094c4 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -5,6 +5,15 @@ use crate::env::get_emscripten_data; use libc::getdtablesize; use wasmer_runtime_core::vm::Ctx; +pub fn asm_const_i(_ctx: &mut Ctx, _val: i32) -> i32{ + debug!("emscripten::asm_const_i: {}", _val); + 0 +} + +pub fn exit_with_live_runtime(_ctx: &mut Ctx) { + debug!("emscripten::exit_with_live_runtime"); +} + pub fn setTempRet0(ctx: &mut Ctx, val: i32) { debug!("emscripten::setTempRet0: {}", val); get_emscripten_data(ctx).temp_ret_0 = val; @@ -59,10 +68,6 @@ 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({})", _a); - 0 -} pub fn _pthread_attr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_attr_destroy"); 0 @@ -82,44 +87,50 @@ pub fn _pthread_attr_getstack( // HEAP32[stacksize >> 2] = TOTAL_STACK; 0 } -pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { - debug!("emscripten::_pthread_cond_destroy"); +pub fn _pthread_attr_init(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_attr_init({})", _a); 0 } -pub fn _pthread_cond_timedwait(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 { - debug!("emscripten::_pthread_cond_timedwait"); +pub fn _pthread_attr_setstacksize(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_attr_setstacksize"); 0 } -pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 { - debug!("emscripten::_pthread_getspecific"); +pub fn _pthread_cleanup_pop(_ctx: &mut Ctx, _a: i32) -> () { + debug!("emscripten::_pthread_cleanup_pop"); +} +pub fn _pthread_cleanup_push(_ctx: &mut Ctx, _a: i32, _b: i32) -> () { + debug!("emscripten::_pthread_cleanup_push"); +} +pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_cond_destroy"); 0 } -pub fn _pthread_getattr_np(_ctx: &mut Ctx, _thread: i32, _attr: i32) -> i32 { - debug!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr); +pub fn _pthread_cond_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_cond_init"); 0 } -pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { - debug!("emscripten::_pthread_setspecific"); +pub fn _pthread_cond_signal(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_cond_signal"); 0 } -pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { - debug!("emscripten::_pthread_once"); +pub fn _pthread_cond_timedwait(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 { + debug!("emscripten::_pthread_cond_timedwait"); 0 } -pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { - debug!("emscripten::_pthread_key_create"); +pub fn _pthread_cond_wait(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_cond_wait"); 0 } -pub fn _pthread_rwlock_destroy(_ctx: &mut Ctx, _rwlock: i32) -> i32 { - debug!("emscripten::_pthread_rwlock_destroy({})", _rwlock); +pub fn _pthread_condattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_condattr_destroy"); 0 } -pub fn _pthread_rwlock_init(_ctx: &mut Ctx, _rwlock: i32, _attr: i32) -> i32 { - debug!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr); +pub fn _pthread_condattr_init(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_condattr_init"); 0 } -pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 { - debug!("emscripten::_pthread_rwlock_wrlock({})", _rwlock); +pub fn _pthread_condattr_setclock(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_condattr_setclock"); 0 } pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 { @@ -130,32 +141,27 @@ 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"); +pub fn _pthread_equal(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_equal"); 0 } -pub fn _pthread_cond_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { - debug!("emscripten::_pthread_cond_init"); - 0 +pub fn _pthread_exit(_ctx: &mut Ctx, _a: i32) -> () { + debug!("emscripten::_pthread_exit"); } -pub fn _pthread_cond_signal(_ctx: &mut Ctx, _a: i32) -> i32 { - debug!("emscripten::_pthread_cond_signal"); - 0 -} -pub fn _pthread_cond_wait(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { - debug!("emscripten::_pthread_cond_wait"); +pub fn _pthread_getattr_np(_ctx: &mut Ctx, _thread: i32, _attr: i32) -> i32 { + debug!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr); 0 } -pub fn _pthread_condattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { - debug!("emscripten::_pthread_condattr_destroy"); +pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::_pthread_getspecific"); 0 } -pub fn _pthread_condattr_init(_ctx: &mut Ctx, _a: i32) -> i32 { - debug!("emscripten::_pthread_condattr_init"); +pub fn _pthread_join(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_join"); 0 } -pub fn _pthread_condattr_setclock(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { - debug!("emscripten::_pthread_condattr_setclock"); +pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_key_create"); 0 } pub fn _pthread_mutex_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { @@ -178,6 +184,18 @@ pub fn _pthread_mutexattr_settype(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_mutexattr_settype"); 0 } +pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_once"); + 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_rdlock(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_rwlock_rdlock"); 0 @@ -186,10 +204,22 @@ pub fn _pthread_rwlock_unlock(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_rwlock_unlock"); 0 } +pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 { + debug!("emscripten::_pthread_rwlock_wrlock({})", _rwlock); + 0 +} pub fn _pthread_setcancelstate(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_setcancelstate"); 0 } +pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_pthread_setspecific"); + 0 +} +pub fn _pthread_sigmask(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 { + debug!("emscripten::_pthread_sigmask"); + 0 +} pub fn ___gxx_personality_v0( _ctx: &mut Ctx, _a: i32, @@ -222,6 +252,10 @@ pub fn _gethostbyaddr(_ctx: &mut Ctx, _addr: i32, _addrlen: i32, _atype: i32) -> debug!("emscripten::gethostbyaddr"); 0 } +pub fn _gethostbyname(_ctx: &mut Ctx, _name: i32) -> i32 { + debug!("emscripten::gethostbyname_r"); + 0 +} pub fn _gethostbyname_r( _ctx: &mut Ctx, _name: i32, diff --git a/lib/emscripten/src/exception.rs b/lib/emscripten/src/exception.rs index f37c015e530..09f04a7989b 100644 --- a/lib/emscripten/src/exception.rs +++ b/lib/emscripten/src/exception.rs @@ -8,6 +8,26 @@ pub fn ___cxa_allocate_exception(ctx: &mut Ctx, size: u32) -> u32 { env::call_malloc(ctx, size as _) } +pub fn ___cxa_current_primary_exception(_ctx: &mut Ctx) -> u32 { + debug!("emscripten::___cxa_current_primary_exception"); + unimplemented!() +} + +pub fn ___cxa_decrement_exception_refcount(_ctx: &mut Ctx, _a: u32) { + debug!("emscripten::___cxa_decrement_exception_refcount({})", _a); + unimplemented!() +} + +pub fn ___cxa_increment_exception_refcount(_ctx: &mut Ctx, _a: u32) { + debug!("emscripten::___cxa_increment_exception_refcount({})", _a); + unimplemented!() +} + +pub fn ___cxa_rethrow_primary_exception(_ctx: &mut Ctx, _a: u32) { + debug!("emscripten::___cxa_rethrow_primary_exception({})", _a); + unimplemented!() +} + /// emscripten: ___cxa_throw /// TODO: We don't have support for exceptions yet pub fn ___cxa_throw(ctx: &mut Ctx, _ptr: u32, _ty: u32, _destructor: u32) { diff --git a/lib/emscripten/src/inet.rs b/lib/emscripten/src/inet.rs new file mode 100644 index 00000000000..097dffa39ce --- /dev/null +++ b/lib/emscripten/src/inet.rs @@ -0,0 +1,6 @@ +use wasmer_runtime_core::vm::Ctx; + +pub fn addr(_ctx: &mut Ctx, _cp: i32) -> i32 { + debug!("inet::addr({})", _cp); + 0 +} diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 400bcd94f97..8a33b0d361d 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -33,8 +33,10 @@ mod errno; mod exception; mod exec; mod exit; +mod inet; mod io; mod jmp; +mod libc; mod linking; mod lock; mod math; @@ -45,6 +47,7 @@ mod storage; mod syscalls; mod time; mod ucontext; +mod unistd; mod utils; mod varargs; @@ -507,6 +510,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "__memory_base" => Global::new(Value::I32(globals.data.memory_base as i32)), "tempDoublePtr" => Global::new(Value::I32(globals.data.temp_double_ptr as i32)), + // inet + "_inet_addr" => func!(crate::inet::addr), + // IO "printf" => func!(crate::io::printf), "putchar" => func!(crate::io::putchar), @@ -557,15 +563,24 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___syscall9" => func!(crate::syscalls::___syscall9), "___syscall10" => func!(crate::syscalls::___syscall10), "___syscall12" => func!(crate::syscalls::___syscall12), + "___syscall14" => func!(crate::syscalls::___syscall14), "___syscall15" => func!(crate::syscalls::___syscall15), "___syscall20" => func!(crate::syscalls::___syscall20), + "___syscall21" => func!(crate::syscalls::___syscall21), + "___syscall25" => func!(crate::syscalls::___syscall25), + "___syscall29" => func!(crate::syscalls::___syscall29), + "___syscall32" => func!(crate::syscalls::___syscall32), "___syscall33" => func!(crate::syscalls::___syscall33), "___syscall34" => func!(crate::syscalls::___syscall34), + "___syscall36" => func!(crate::syscalls::___syscall36), "___syscall39" => func!(crate::syscalls::___syscall39), "___syscall38" => func!(crate::syscalls::___syscall38), "___syscall40" => func!(crate::syscalls::___syscall40), "___syscall41" => func!(crate::syscalls::___syscall41), "___syscall42" => func!(crate::syscalls::___syscall42), + "___syscall51" => func!(crate::syscalls::___syscall51), + "___syscall52" => func!(crate::syscalls::___syscall52), + "___syscall53" => func!(crate::syscalls::___syscall53), "___syscall54" => func!(crate::syscalls::___syscall54), "___syscall57" => func!(crate::syscalls::___syscall57), "___syscall60" => func!(crate::syscalls::___syscall60), @@ -578,23 +593,36 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___syscall85" => func!(crate::syscalls::___syscall85), "___syscall91" => func!(crate::syscalls::___syscall91), "___syscall94" => func!(crate::syscalls::___syscall94), + "___syscall96" => func!(crate::syscalls::___syscall96), "___syscall97" => func!(crate::syscalls::___syscall97), "___syscall102" => func!(crate::syscalls::___syscall102), "___syscall110" => func!(crate::syscalls::___syscall110), "___syscall114" => func!(crate::syscalls::___syscall114), "___syscall118" => func!(crate::syscalls::___syscall118), + "___syscall121" => func!(crate::syscalls::___syscall121), "___syscall122" => func!(crate::syscalls::___syscall122), + "___syscall125" => func!(crate::syscalls::___syscall125), + "___syscall132" => func!(crate::syscalls::___syscall132), + "___syscall133" => func!(crate::syscalls::___syscall133), "___syscall140" => func!(crate::syscalls::___syscall140), "___syscall142" => func!(crate::syscalls::___syscall142), + "___syscall144" => func!(crate::syscalls::___syscall144), "___syscall145" => func!(crate::syscalls::___syscall145), "___syscall146" => func!(crate::syscalls::___syscall146), + "___syscall147" => func!(crate::syscalls::___syscall147), "___syscall148" => func!(crate::syscalls::___syscall148), + "___syscall150" => func!(crate::syscalls::___syscall150), + "___syscall151" => func!(crate::syscalls::___syscall151), + "___syscall152" => func!(crate::syscalls::___syscall152), + "___syscall153" => func!(crate::syscalls::___syscall153), + "___syscall163" => func!(crate::syscalls::___syscall163), "___syscall168" => func!(crate::syscalls::___syscall168), "___syscall180" => func!(crate::syscalls::___syscall180), "___syscall181" => func!(crate::syscalls::___syscall181), "___syscall183" => func!(crate::syscalls::___syscall183), "___syscall191" => func!(crate::syscalls::___syscall191), "___syscall192" => func!(crate::syscalls::___syscall192), + "___syscall193" => func!(crate::syscalls::___syscall193), "___syscall194" => func!(crate::syscalls::___syscall194), "___syscall195" => func!(crate::syscalls::___syscall195), "___syscall196" => func!(crate::syscalls::___syscall196), @@ -606,19 +634,38 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___syscall202" => func!(crate::syscalls::___syscall202), "___syscall205" => func!(crate::syscalls::___syscall205), "___syscall207" => func!(crate::syscalls::___syscall207), + "___syscall209" => func!(crate::syscalls::___syscall209), + "___syscall211" => func!(crate::syscalls::___syscall211), "___syscall212" => func!(crate::syscalls::___syscall212), + "___syscall218" => func!(crate::syscalls::___syscall218), "___syscall219" => func!(crate::syscalls::___syscall219), "___syscall220" => func!(crate::syscalls::___syscall220), "___syscall221" => func!(crate::syscalls::___syscall221), "___syscall268" => func!(crate::syscalls::___syscall268), + "___syscall269" => func!(crate::syscalls::___syscall269), "___syscall272" => func!(crate::syscalls::___syscall272), "___syscall295" => func!(crate::syscalls::___syscall295), + "___syscall296" => func!(crate::syscalls::___syscall296), + "___syscall297" => func!(crate::syscalls::___syscall297), + "___syscall298" => func!(crate::syscalls::___syscall298), "___syscall300" => func!(crate::syscalls::___syscall300), + "___syscall301" => func!(crate::syscalls::___syscall301), + "___syscall302" => func!(crate::syscalls::___syscall302), + "___syscall303" => func!(crate::syscalls::___syscall303), + "___syscall304" => func!(crate::syscalls::___syscall304), + "___syscall305" => func!(crate::syscalls::___syscall305), + "___syscall306" => func!(crate::syscalls::___syscall306), + "___syscall307" => func!(crate::syscalls::___syscall307), + "___syscall308" => func!(crate::syscalls::___syscall308), "___syscall320" => func!(crate::syscalls::___syscall320), "___syscall324" => func!(crate::syscalls::___syscall324), "___syscall330" => func!(crate::syscalls::___syscall330), + "___syscall331" => func!(crate::syscalls::___syscall331), + "___syscall333" => func!(crate::syscalls::___syscall333), "___syscall334" => func!(crate::syscalls::___syscall334), + "___syscall337" => func!(crate::syscalls::___syscall337), "___syscall340" => func!(crate::syscalls::___syscall340), + "___syscall345" => func!(crate::syscalls::___syscall345), // Process "abort" => func!(crate::process::em_abort), @@ -647,9 +694,17 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_setitimer" => func!(crate::process::_setitimer), "_usleep" => func!(crate::process::_usleep), "_nanosleep" => func!(crate::process::_nanosleep), + "_utime" => func!(crate::process::_utime), "_utimes" => func!(crate::process::_utimes), + "_wait" => func!(crate::process::_wait), + "_wait3" => func!(crate::process::_wait3), + "_wait4" => func!(crate::process::_wait4), + "_waitid" => func!(crate::process::_waitid), "_waitpid" => func!(crate::process::_waitpid), + // Emscripten + "_emscripten_asm_const_i" => func!(crate::emscripten_target::asm_const_i), + "_emscripten_exit_with_live_runtime" => func!(crate::emscripten_target::exit_with_live_runtime), // Signal "_sigemptyset" => func!(crate::signal::_sigemptyset), @@ -673,6 +728,10 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject // Exception "___cxa_allocate_exception" => func!(crate::exception::___cxa_allocate_exception), + "___cxa_current_primary_exception" => func!(crate::exception::___cxa_current_primary_exception), + "___cxa_decrement_exception_refcount" => func!(crate::exception::___cxa_decrement_exception_refcount), + "___cxa_increment_exception_refcount" => func!(crate::exception::___cxa_increment_exception_refcount), + "___cxa_rethrow_primary_exception" => func!(crate::exception::___cxa_rethrow_primary_exception), "___cxa_throw" => func!(crate::exception::___cxa_throw), "___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch), "___cxa_end_catch" => func!(crate::exception::___cxa_end_catch), @@ -681,7 +740,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject // Time "_gettimeofday" => func!(crate::time::_gettimeofday), + "_clock_getres" => func!(crate::time::_clock_getres), "_clock_gettime" => func!(crate::time::_clock_gettime), + "_clock_settime" => func!(crate::time::_clock_settime), "___clock_gettime" => func!(crate::time::_clock_gettime), "_clock" => func!(crate::time::_clock), "_difftime" => func!(crate::time::_difftime), @@ -699,6 +760,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject // Math "f64-rem" => func!(crate::math::f64_rem), + "_llvm_copysign_f32" => func!(crate::math::_llvm_copysign_f32), + "_llvm_copysign_f64" => func!(crate::math::_llvm_copysign_f64), "_llvm_log10_f64" => func!(crate::math::_llvm_log10_f64), "_llvm_log2_f64" => func!(crate::math::_llvm_log2_f64), "_llvm_log10_f32" => func!(crate::math::_llvm_log10_f32), @@ -720,6 +783,22 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject // Bitwise "_llvm_bswap_i64" => func!(crate::bitwise::_llvm_bswap_i64), + // libc + "_execv" => func!(crate::libc::execv), + "_endpwent" => func!(crate::libc::endpwent), + "_fexecve" => func!(crate::libc::fexecve), + "_fpathconf" => func!(crate::libc::fpathconf), + "_getitimer" => func!(crate::libc::getitimer), + "_getpwent" => func!(crate::libc::getpwent), + "_killpg" => func!(crate::libc::killpg), + "_pathconf" => func!(crate::libc::pathconf), + "_siginterrupt" => func!(crate::signal::_siginterrupt), + "_setpwent" => func!(crate::libc::setpwent), + "_sigismember" => func!(crate::libc::sigismember), + "_sigpending" => func!(crate::libc::sigpending), + "___libc_current_sigrtmax" => func!(crate::libc::current_sigrtmax), + "___libc_current_sigrtmin" => func!(crate::libc::current_sigrtmin), + // Linking "_dlclose" => func!(crate::linking::_dlclose), "_dlerror" => func!(crate::linking::_dlerror), @@ -751,40 +830,47 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___cxa_free_exception" => func!(crate::emscripten_target::___cxa_free_exception), "___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_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_attr_init" => func!(crate::emscripten_target::_pthread_attr_init), + "_pthread_attr_setstacksize" => func!(crate::emscripten_target::_pthread_attr_setstacksize), + "_pthread_cleanup_pop" => func!(crate::emscripten_target::_pthread_cleanup_pop), + "_pthread_cleanup_push" => func!(crate::emscripten_target::_pthread_cleanup_push), "_pthread_cond_destroy" => func!(crate::emscripten_target::_pthread_cond_destroy), + "_pthread_cond_init" => func!(crate::emscripten_target::_pthread_cond_init), "_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), "_pthread_condattr_setclock" => func!(crate::emscripten_target::_pthread_condattr_setclock), + "_pthread_create" => func!(crate::emscripten_target::_pthread_create), + "_pthread_detach" => func!(crate::emscripten_target::_pthread_detach), + "_pthread_equal" => func!(crate::emscripten_target::_pthread_equal), + "_pthread_exit" => func!(crate::emscripten_target::_pthread_exit), + "_pthread_getattr_np" => func!(crate::emscripten_target::_pthread_getattr_np), + "_pthread_getspecific" => func!(crate::emscripten_target::_pthread_getspecific), + "_pthread_join" => func!(crate::emscripten_target::_pthread_join), + "_pthread_key_create" => func!(crate::emscripten_target::_pthread_key_create), "_pthread_mutex_destroy" => func!(crate::emscripten_target::_pthread_mutex_destroy), "_pthread_mutex_init" => func!(crate::emscripten_target::_pthread_mutex_init), "_pthread_mutexattr_destroy" => func!(crate::emscripten_target::_pthread_mutexattr_destroy), "_pthread_mutexattr_init" => func!(crate::emscripten_target::_pthread_mutexattr_init), "_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), - "_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), "_pthread_rwlock_destroy" => func!(crate::emscripten_target::_pthread_rwlock_destroy), "_pthread_rwlock_init" => func!(crate::emscripten_target::_pthread_rwlock_init), + "_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock), + "_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock), "_pthread_rwlock_wrlock" => func!(crate::emscripten_target::_pthread_rwlock_wrlock), + "_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate), + "_pthread_setspecific" => func!(crate::emscripten_target::_pthread_setspecific), + "_pthread_sigmask" => func!(crate::emscripten_target::_pthread_sigmask), "___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" => func!(crate::emscripten_target::_gethostbyname), "_gethostbyname_r" => func!(crate::emscripten_target::_gethostbyname_r), "_getloadavg" => func!(crate::emscripten_target::_getloadavg), "_getnameinfo" => func!(crate::emscripten_target::_getnameinfo), @@ -833,6 +919,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_makecontext" => func!(crate::ucontext::_makecontext), "_setcontext" => func!(crate::ucontext::_setcontext), "_swapcontext" => func!(crate::ucontext::_swapcontext), + + // unistd + "_confstr" => func!(crate::unistd::confstr), }; for null_func_name in globals.null_func_names.iter() { diff --git a/lib/emscripten/src/libc.rs b/lib/emscripten/src/libc.rs new file mode 100644 index 00000000000..4ef43f9920b --- /dev/null +++ b/lib/emscripten/src/libc.rs @@ -0,0 +1,72 @@ +extern crate libc; +extern crate wasmer_runtime_core; + +use std::convert::TryInto; + +use wasmer_runtime_core::vm::Ctx; + +pub fn current_sigrtmax(_ctx: &mut Ctx) -> i32 { + debug!("emscripten::current_sigrtmax"); + 0 +} + +pub fn current_sigrtmin(_ctx: &mut Ctx) -> i32 { + debug!("emscripten::current_sigrtmin"); + 0 +} + +pub fn endpwent(_ctx: &mut Ctx) { + debug!("emscripten::endpwent"); +} + +pub fn execv(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::execv"); + 0 +} + +pub fn fexecve(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 { + debug!("emscripten::fexecve"); + 0 +} + +pub fn fpathconf(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::fpathconf"); + 0 +} + +pub fn getitimer(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::getitimer"); + 0 +} + +pub fn getpwent(_ctx: &mut Ctx) -> i32 { + debug!("emscripten::getpwent"); + 0 +} + +pub fn killpg(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::killpg"); + 0 +} + +pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { + let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; + + unsafe { + libc::pathconf(path, name).try_into().unwrap() + } +} + +pub fn setpwent(_ctx: &mut Ctx) { + debug!("emscripten::setpwent"); +} + +pub fn sigismember(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::sigismember"); + 0 +} + +pub fn sigpending(_ctx: &mut Ctx, _a: i32) -> i32 { + debug!("emscripten::sigpending"); + 0 +} diff --git a/lib/emscripten/src/llvm.rs b/lib/emscripten/src/llvm.rs new file mode 100644 index 00000000000..ee201ba94f9 --- /dev/null +++ b/lib/emscripten/src/llvm.rs @@ -0,0 +1,9 @@ +extern crate libm; +extern crate wasmer_runtime_core; + +use libm::fma; +use wasmer_runtime_core::vm::Ctx; + +pub fn fma_f64(_ctx: &mut Ctx, x: f64, y: f64, z: f64) -> f64 { + fma(x, y, z) +} diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index d266afe701e..7e420caaed2 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -1,5 +1,15 @@ +use std::{f32, f64}; use wasmer_runtime_core::vm::Ctx; +pub fn _llvm_copysign_f32(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { + // f32::copysign(x, y) + f64::copysign(x, y) +} + +pub fn _llvm_copysign_f64(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { + f64::copysign(x, y) +} + /// emscripten: _llvm_log10_f64 pub fn _llvm_log10_f64(_ctx: &mut Ctx, value: f64) -> f64 { debug!("emscripten::_llvm_log10_f64"); diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index 538ed528fdd..cd083e94327 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -131,11 +131,36 @@ pub fn _nanosleep(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +pub fn _utime(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::_utime"); + -1 +} + pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::_utimes"); -1 } +pub fn _wait(_ctx: &mut Ctx, _one: i32) -> i32 { + debug!("emscripten::_wait"); + -1 +} + +pub fn _wait3(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { + debug!("emscripten::_wait3"); + -1 +} + +pub fn _wait4(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 { + debug!("emscripten::_wait4"); + -1 +} + +pub fn _waitid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 { + debug!("emscripten::_waitid"); + -1 +} + pub fn _waitpid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { debug!("emscripten::_waitpid"); -1 diff --git a/lib/emscripten/src/signal.rs b/lib/emscripten/src/signal.rs index 37c3ed8df7a..9b17cd8b4f0 100644 --- a/lib/emscripten/src/signal.rs +++ b/lib/emscripten/src/signal.rs @@ -16,6 +16,11 @@ pub fn _sigaction(_ctx: &mut Ctx, _signum: u32, _act: u32, _oldact: u32) -> i32 0 } +pub fn _siginterrupt(_ctx: &mut Ctx, _a: u32, _b: u32) -> i32 { + debug!("emscripten::_siginterrupt {}, {}", _a, _b); + 0 +} + #[allow(clippy::cast_ptr_alignment)] pub fn _sigaddset(ctx: &mut Ctx, set: u32, signum: u32) -> i32 { debug!("emscripten::_sigaddset {}, {}", set, signum); diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 057a8ac1961..72e2b7bf51a 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -108,6 +108,11 @@ pub fn ___syscall10(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +pub fn ___syscall14(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall14"); + -1 +} + pub fn ___syscall15(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall15"); -1 @@ -119,6 +124,36 @@ pub fn ___syscall20(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { unsafe { getpid() } } +pub fn ___syscall21(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall21"); + -1 +} + +pub fn ___syscall25(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall25"); + -1 +} + +pub fn ___syscall29(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall29"); + -1 +} + +pub fn ___syscall32(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall32"); + -1 +} + +pub fn ___syscall33(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall33"); + -1 +} + +pub fn ___syscall36(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall36"); + -1 +} + // rename pub fn ___syscall38(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall38 (rename)"); @@ -167,6 +202,21 @@ pub fn ___syscall42(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int result } +pub fn ___syscall51(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall51"); + -1 +} + +pub fn ___syscall52(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall52"); + -1 +} + +pub fn ___syscall53(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall53"); + -1 +} + pub fn ___syscall60(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall60"); -1 @@ -231,6 +281,11 @@ pub fn ___syscall91(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { 0 } +pub fn ___syscall96(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall96"); + -1 +} + pub fn ___syscall97(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall97"); -1 @@ -241,6 +296,61 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +pub fn ___syscall121(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall121"); + -1 +} + +pub fn ___syscall125(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall125"); + -1 +} + +pub fn ___syscall132(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall132"); + -1 +} + +pub fn ___syscall133(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall133"); + -1 +} + +pub fn ___syscall144(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall144"); + -1 +} + +pub fn ___syscall147(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall147"); + -1 +} + +pub fn ___syscall150(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall150"); + -1 +} + +pub fn ___syscall151(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall151"); + -1 +} + +pub fn ___syscall152(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall152"); + -1 +} + +pub fn ___syscall153(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall153"); + -1 +} + +pub fn ___syscall163(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall163"); + -1 +} + // getcwd pub fn ___syscall183(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall183"); @@ -409,8 +519,8 @@ pub fn ___syscall191(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } -pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { - debug!("emscripten::___syscall199 - stub"); +pub fn ___syscall193(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall193"); -1 } @@ -457,6 +567,26 @@ pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } +pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall199 - stub"); + -1 +} + +pub fn ___syscall209(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall209"); + -1 +} + +pub fn ___syscall211(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall211"); + -1 +} + +pub fn ___syscall218(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall218"); + -1 +} + pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall220"); -1 @@ -485,6 +615,11 @@ pub fn ___syscall268(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +pub fn ___syscall269(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall269"); + -1 +} + pub fn ___syscall272(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall272"); -1 @@ -495,22 +630,92 @@ pub fn ___syscall295(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +pub fn ___syscall296(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall296"); + -1 +} + +pub fn ___syscall297(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall297"); + -1 +} + +pub fn ___syscall298(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall298"); + -1 +} + pub fn ___syscall300(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall300"); -1 } +pub fn ___syscall301(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall301"); + -1 +} + +pub fn ___syscall302(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall302"); + -1 +} + +pub fn ___syscall303(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall303"); + -1 +} + +pub fn ___syscall304(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall304"); + -1 +} + +pub fn ___syscall305(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall305"); + -1 +} + +pub fn ___syscall306(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall306"); + -1 +} + +pub fn ___syscall307(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall307"); + -1 +} + +pub fn ___syscall308(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall308"); + -1 +} + // utimensat pub fn ___syscall320(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall320 (utimensat), {}", _which); 0 } +pub fn ___syscall331(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall331"); + -1 +} + +pub fn ___syscall333(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall333"); + -1 +} + pub fn ___syscall334(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall334"); -1 } +pub fn ___syscall337(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall337"); + -1 +} + // prlimit64 pub fn ___syscall340(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall340 (prlimit64), {}", _which); @@ -533,3 +738,8 @@ pub fn ___syscall340(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } + +pub fn ___syscall345(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall345"); + -1 +} diff --git a/lib/emscripten/src/time.rs b/lib/emscripten/src/time.rs index c35d7959601..845bc7adcf7 100644 --- a/lib/emscripten/src/time.rs +++ b/lib/emscripten/src/time.rs @@ -1,5 +1,6 @@ use super::utils::{copy_cstr_into_wasm, write_to_buf}; use libc::{c_char, c_int}; +// use libc::{c_char, c_int, clock_getres, clock_settime}; use std::mem; use std::time::SystemTime; @@ -69,6 +70,12 @@ pub fn _gettimeofday(ctx: &mut Ctx, tp: c_int, tz: c_int) -> c_int { 0 } +pub fn _clock_getres(_ctx: &mut Ctx, _clk_id: i32, _tp: i32) -> i32 { + debug!("emscripten::_clock_getres"); + // clock_getres(clk_id, tp) + 0 +} + /// emscripten: _clock_gettime #[allow(clippy::cast_ptr_alignment)] pub fn _clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int { @@ -103,6 +110,12 @@ pub fn _clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int { 0 } +pub fn _clock_settime(_ctx: &mut Ctx, _clk_id: i32, _tp: i32) -> i32 { + debug!("emscripten::_clock_settime"); + // clock_settime(clk_id, tp) + 0 +} + /// emscripten: ___clock_gettime pub fn ___clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int { debug!("emscripten::___clock_gettime {} {}", clk_id, tp); diff --git a/lib/emscripten/src/unistd.rs b/lib/emscripten/src/unistd.rs new file mode 100644 index 00000000000..f127e7cc4e4 --- /dev/null +++ b/lib/emscripten/src/unistd.rs @@ -0,0 +1,6 @@ +use wasmer_runtime_core::vm::Ctx; + +pub fn confstr(_ctx: &mut Ctx, _name: i32, _bufPointer: i32, _len: i32) -> i32 { + debug!("unistd::confstr({}, {}, {})", _name, _bufPointer, _len); + 0 +} From 5d93d9a9045822eeb9f6fb5cbe9a205eb719c824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 8 Jun 2019 19:53:21 +0200 Subject: [PATCH 02/16] Added `fb` and `gb` symbols --- lib/emscripten/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 94c8c6b0815..a96e263f609 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -511,9 +511,11 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "STACKTOP" => Global::new(Value::I32(globals.data.stacktop as i32)), "STACK_MAX" => Global::new(Value::I32(globals.data.stack_max as i32)), "DYNAMICTOP_PTR" => Global::new(Value::I32(globals.data.dynamictop_ptr as i32)), + "fb" => Global::new(Value::I32(globals.data.table_base as i32)), "tableBase" => Global::new(Value::I32(globals.data.table_base as i32)), "__table_base" => Global::new(Value::I32(globals.data.table_base as i32)), "ABORT" => Global::new(Value::I32(globals.data.abort as i32)), + "gb" => Global::new(Value::I32(globals.data.memory_base as i32)), "memoryBase" => Global::new(Value::I32(globals.data.memory_base as i32)), "__memory_base" => Global::new(Value::I32(globals.data.memory_base as i32)), "tempDoublePtr" => Global::new(Value::I32(globals.data.temp_double_ptr as i32)), From 0b416e14c31d5588ba4e3a05fc9136abdb2dd740 Mon Sep 17 00:00:00 2001 From: Syrus Date: Tue, 11 Jun 2019 17:36:13 +0200 Subject: [PATCH 03/16] Improved syscall220 debug --- lib/emscripten/src/syscalls/mod.rs | 5 ----- lib/emscripten/src/syscalls/unix.rs | 2 ++ 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index a65cf48b55c..93e41cb690b 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -631,11 +631,6 @@ pub fn ___syscall218(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } -pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { - debug!("emscripten::___syscall220"); - -1 -} - // fcntl64 pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall221 (fcntl64) {}", _which); diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index e5b3acb63a8..d167953fb94 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -74,6 +74,7 @@ use libc::{ SO_REUSEADDR, TIOCGWINSZ, }; +use std::ffi::CStr; use wasmer_runtime_core::vm::Ctx; use crate::utils; @@ -878,6 +879,7 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { i += 1; } *(dirp.add(pos + 19 + i) as *mut i8) = 0 as i8; + debug!(" => file {}", CStr::from_ptr((dirp.add(pos + 19) as *const i8)).to_str().unwrap()); } pos += offset; } From 6ce4f5dca4117d3a0742440e3dab49c68f404c5a Mon Sep 17 00:00:00 2001 From: Syrus Date: Wed, 12 Jun 2019 00:13:06 +0200 Subject: [PATCH 04/16] Minor fixes --- lib/emscripten/src/syscalls/unix.rs | 3 ++- lib/emscripten/src/unistd.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index d167953fb94..51f89233525 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -74,6 +74,7 @@ use libc::{ SO_REUSEADDR, TIOCGWINSZ, }; +#[allow(unused_imports)] use std::ffi::CStr; use wasmer_runtime_core::vm::Ctx; @@ -879,7 +880,7 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { i += 1; } *(dirp.add(pos + 19 + i) as *mut i8) = 0 as i8; - debug!(" => file {}", CStr::from_ptr((dirp.add(pos + 19) as *const i8)).to_str().unwrap()); + debug!(" => file {}", CStr::from_ptr(dirp.add(pos + 19) as *const i8).to_str().unwrap()); } pos += offset; } diff --git a/lib/emscripten/src/unistd.rs b/lib/emscripten/src/unistd.rs index f127e7cc4e4..08c06ce50a2 100644 --- a/lib/emscripten/src/unistd.rs +++ b/lib/emscripten/src/unistd.rs @@ -1,6 +1,6 @@ use wasmer_runtime_core::vm::Ctx; -pub fn confstr(_ctx: &mut Ctx, _name: i32, _bufPointer: i32, _len: i32) -> i32 { - debug!("unistd::confstr({}, {}, {})", _name, _bufPointer, _len); +pub fn confstr(_ctx: &mut Ctx, _name: i32, _buf_pointer: i32, _len: i32) -> i32 { + debug!("unistd::confstr({}, {}, {})", _name, _buf_pointer, _len); 0 } From 109acd2fa3befdaf41f9fe73d820e53bd809d589 Mon Sep 17 00:00:00 2001 From: Syrus Date: Wed, 12 Jun 2019 01:01:47 +0200 Subject: [PATCH 05/16] Trying to fix ___syscall220 --- lib/emscripten/src/lib.rs | 5 +++++ lib/emscripten/src/syscalls/unix.rs | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index a96e263f609..ac5a4b28256 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -76,6 +76,8 @@ lazy_static! { const GLOBAL_BASE: u32 = 1024; const STATIC_BASE: u32 = GLOBAL_BASE; +use ::libc::DIR as libcDIR; + pub struct EmscriptenData<'a> { pub malloc: Func<'a, u32, u32>, pub free: Func<'a, u32>, @@ -83,6 +85,7 @@ pub struct EmscriptenData<'a> { pub memset: Func<'a, (u32, u32, u32), u32>, pub stack_alloc: Func<'a, u32, u32>, pub jumps: Vec>, + pub opened_dirs: HashMap>, pub dyn_call_i: Option>, pub dyn_call_ii: Option>, @@ -224,6 +227,8 @@ impl<'a> EmscriptenData<'a> { memset, stack_alloc, jumps: Vec::new(), + opened_dirs: HashMap::new(), + dyn_call_i, dyn_call_ii, dyn_call_iii, diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index 51f89233525..e6b2860c272 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -851,19 +851,25 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { // dirent structure is // i64, i64, u16 (280), i8, [i8; 256] pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { - debug!("emscripten::___syscall220"); + use super::super::env::get_emscripten_data; + let fd: i32 = varargs.get(ctx); let dirp_addr: i32 = varargs.get(ctx); let count: u32 = varargs.get(ctx); + debug!("emscripten::___syscall220 (getdents) {} {} {}", fd, dirp_addr, count); let dirp = emscripten_memory_pointer!(ctx.memory(0), dirp_addr) as *mut u8; + + let mut opened_dirs = &mut get_emscripten_data(ctx).opened_dirs; + // need to persist stream across calls? - let dir: *mut libc::DIR = unsafe { libc::fdopendir(fd) }; + // let dir: *mut libc::DIR = unsafe { libc::fdopendir(fd) }; + let mut dir = &*opened_dirs.entry(fd).or_insert_with(|| unsafe { Box::new(libc::fdopendir(fd)) }); let mut pos = 0; let offset = 280; while pos + offset <= count as usize { - let dirent = unsafe { readdir(dir) }; + let dirent = unsafe { readdir(**dir) }; if dirent.is_null() { break; } From 58d75868f4b3cee4ddc9cbf9c3175e981156d3e0 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 12:17:17 +0200 Subject: [PATCH 06/16] Fixed syscall220 alignment --- lib/emscripten/src/syscalls/unix.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index e6b2860c272..083adb1757c 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -867,7 +867,7 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let mut dir = &*opened_dirs.entry(fd).or_insert_with(|| unsafe { Box::new(libc::fdopendir(fd)) }); let mut pos = 0; - let offset = 280; + let offset = 256+12; while pos + offset <= count as usize { let dirent = unsafe { readdir(**dir) }; if dirent.is_null() { @@ -875,18 +875,19 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { } #[allow(clippy::cast_ptr_alignment)] unsafe { - *(dirp.add(pos) as *mut u64) = (*dirent).d_ino; - *(dirp.add(pos + 8) as *mut u64) = pos as u64 + offset as u64; - *(dirp.add(pos + 16) as *mut u16) = offset as u16; - *(dirp.add(pos + 18) as *mut u8) = (*dirent).d_type; - let upper_bound = std::cmp::min((*dirent).d_reclen, 254) as usize; + *(dirp.add(pos) as *mut u32) = (*dirent).d_ino as u32; + *(dirp.add(pos + 4) as *mut u32) = pos as u32; + *(dirp.add(pos + 8) as *mut u16) = offset as u16; + *(dirp.add(pos + 10) as *mut u8) = (*dirent).d_type; + let upper_bound = std::cmp::min((*dirent).d_reclen, 256) as usize; let mut i = 0; while i < upper_bound { - *(dirp.add(pos + 19 + i) as *mut i8) = (*dirent).d_name[i]; + *(dirp.add(pos + 11 + i) as *mut i8) = (*dirent).d_name[i]; i += 1; } - *(dirp.add(pos + 19 + i) as *mut i8) = 0 as i8; - debug!(" => file {}", CStr::from_ptr(dirp.add(pos + 19) as *const i8).to_str().unwrap()); + // We set the termination string char + *(dirp.add(pos + 11 + i) as *mut i8) = 0 as i8; + debug!(" => file {}", CStr::from_ptr(dirp.add(pos + 11) as *const i8).to_str().unwrap()); } pos += offset; } From 8829e1d90173f175113343f35a972f73e8b20fe7 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 14:05:57 +0200 Subject: [PATCH 07/16] =?UTF-8?q?Make=20Python=20running=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/emscripten/src/io/unix.rs | 40 +++++++++++++++++++++++++++--- lib/emscripten/src/syscalls/mod.rs | 8 ++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index d120e754d26..6ff711bda9f 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -1,4 +1,7 @@ -use libc::{chroot as _chroot, printf as _printf}; +use std::mem; +use libc::{chroot as _chroot, printf as _printf, getpwuid as _getpwuid}; +use super::super::utils::copy_cstr_into_wasm; +use super::super::env::call_malloc; use wasmer_runtime_core::vm::Ctx; @@ -24,7 +27,36 @@ pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 { } /// getpwuid -pub fn getpwuid(_ctx: &mut Ctx, _uid: i32) -> i32 { - debug!("emscripten::getpwuid"); - 0 +pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 { + debug!("emscripten::getpwuid {}", uid); + + #[repr(C)] + struct GuestPasswd { + pw_name: u32, + pw_passwd: u32, + pw_uid: u32, + pw_gid: u32, + pw_gecos: u32, + pw_dir: u32, + pw_shell: u32, + } + + unsafe { + let passwd = &*_getpwuid(uid as _); + let passwd_struct_offset = call_malloc(ctx, mem::size_of::() as _); + + let passwd_struct_ptr = + emscripten_memory_pointer!(ctx.memory(0), passwd_struct_offset) as *mut GuestPasswd; + (*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx, passwd.pw_name); + (*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(ctx, passwd.pw_passwd); + (*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx, passwd.pw_gecos); + (*passwd_struct_ptr).pw_dir = copy_cstr_into_wasm(ctx, passwd.pw_dir); + (*passwd_struct_ptr).pw_shell = copy_cstr_into_wasm(ctx, passwd.pw_shell); + (*passwd_struct_ptr).pw_uid = passwd.pw_uid; + (*passwd_struct_ptr).pw_gid = passwd.pw_gid; + + passwd_struct_offset as _ + } + // unsafe { _getpwuid(uid as _) as _} + // 0 } diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 88e38275089..99ec1afd322 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -39,6 +39,7 @@ use libc::{ // writev, stat, write, + getuid, // readlink, }; use wasmer_runtime_core::{ @@ -611,9 +612,12 @@ pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } +// getuid pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { - debug!("emscripten::___syscall199 - stub"); - -1 + debug!("emscripten::___syscall199 (getuid)"); + let uid = unsafe { getuid() as _ }; + debug!(" => {}", uid); + uid } pub fn ___syscall209(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { From 1560849e40528c6a6aa9384f724457860548343e Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 20:46:05 +0200 Subject: [PATCH 08/16] Fix lint errors and windows build --- lib/emscripten/src/emscripten_target.rs | 2 +- lib/emscripten/src/io/unix.rs | 6 +++--- lib/emscripten/src/lib.rs | 10 +++++++-- lib/emscripten/src/libc.rs | 9 +++++--- lib/emscripten/src/syscalls/mod.rs | 4 ++-- lib/emscripten/src/syscalls/unix.rs | 28 +++++++++++++++++++++---- lib/emscripten/src/syscalls/windows.rs | 6 ++++++ 7 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index dbbe4a094c4..7e0b81af29b 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -5,7 +5,7 @@ use crate::env::get_emscripten_data; use libc::getdtablesize; use wasmer_runtime_core::vm::Ctx; -pub fn asm_const_i(_ctx: &mut Ctx, _val: i32) -> i32{ +pub fn asm_const_i(_ctx: &mut Ctx, _val: i32) -> i32 { debug!("emscripten::asm_const_i: {}", _val); 0 } diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index 6ff711bda9f..16212c16486 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -1,7 +1,7 @@ -use std::mem; -use libc::{chroot as _chroot, printf as _printf, getpwuid as _getpwuid}; -use super::super::utils::copy_cstr_into_wasm; use super::super::env::call_malloc; +use super::super::utils::copy_cstr_into_wasm; +use libc::{chroot as _chroot, getpwuid as _getpwuid, printf as _printf}; +use std::mem; use wasmer_runtime_core::vm::Ctx; diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index ac5a4b28256..33e5f46d5bf 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -24,6 +24,14 @@ use wasmer_runtime_core::{ Func, Instance, IsExport, Module, }; +#[cfg(unix)] +use ::libc::DIR as libcDIR; + +// We use a placeholder for windows +#[cfg(not(unix))] +type libcDIR = u8; + + #[macro_use] mod macros; @@ -76,8 +84,6 @@ lazy_static! { const GLOBAL_BASE: u32 = 1024; const STATIC_BASE: u32 = GLOBAL_BASE; -use ::libc::DIR as libcDIR; - pub struct EmscriptenData<'a> { pub malloc: Func<'a, u32, u32>, pub free: Func<'a, u32>, diff --git a/lib/emscripten/src/libc.rs b/lib/emscripten/src/libc.rs index 4ef43f9920b..60767db1d3e 100644 --- a/lib/emscripten/src/libc.rs +++ b/lib/emscripten/src/libc.rs @@ -1,6 +1,7 @@ extern crate libc; extern crate wasmer_runtime_core; +#[cfg(unix)] use std::convert::TryInto; use wasmer_runtime_core::vm::Ctx; @@ -49,12 +50,14 @@ pub fn killpg(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { 0 } +#[cfg(unix)] pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; + unsafe { libc::pathconf(path, name).try_into().unwrap() } +} - unsafe { - libc::pathconf(path, name).try_into().unwrap() - } +#[cfg(not(unix))] +pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { } pub fn setpwent(_ctx: &mut Ctx) { diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 99ec1afd322..a5c7bb3839b 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -27,6 +27,8 @@ use libc::{ exit, fstat, getpid, + getuid, + // readlink, // iovec, lseek, off_t, @@ -39,8 +41,6 @@ use libc::{ // writev, stat, write, - getuid, - // readlink, }; use wasmer_runtime_core::{ memory::ptr::{Array, WasmPtr}, diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index 083adb1757c..20f1f905594 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -26,6 +26,7 @@ use libc::{ getrusage, getsockname, getsockopt, + getuid, gid_t, in_addr_t, in_port_t, @@ -74,6 +75,7 @@ use libc::{ SO_REUSEADDR, TIOCGWINSZ, }; + #[allow(unused_imports)] use std::ffi::CStr; use wasmer_runtime_core::vm::Ctx; @@ -847,6 +849,14 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { 0 } +// getuid +pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall199 (getuid)"); + let uid = unsafe { getuid() as _ }; + debug!(" => {}", uid); + uid +} + // getdents // dirent structure is // i64, i64, u16 (280), i8, [i8; 256] @@ -856,7 +866,10 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let fd: i32 = varargs.get(ctx); let dirp_addr: i32 = varargs.get(ctx); let count: u32 = varargs.get(ctx); - debug!("emscripten::___syscall220 (getdents) {} {} {}", fd, dirp_addr, count); + debug!( + "emscripten::___syscall220 (getdents) {} {} {}", + fd, dirp_addr, count + ); let dirp = emscripten_memory_pointer!(ctx.memory(0), dirp_addr) as *mut u8; @@ -864,10 +877,12 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { // need to persist stream across calls? // let dir: *mut libc::DIR = unsafe { libc::fdopendir(fd) }; - let mut dir = &*opened_dirs.entry(fd).or_insert_with(|| unsafe { Box::new(libc::fdopendir(fd)) }); + let mut dir = &*opened_dirs + .entry(fd) + .or_insert_with(|| unsafe { Box::new(libc::fdopendir(fd)) }); let mut pos = 0; - let offset = 256+12; + let offset = 256 + 12; while pos + offset <= count as usize { let dirent = unsafe { readdir(**dir) }; if dirent.is_null() { @@ -887,7 +902,12 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { } // We set the termination string char *(dirp.add(pos + 11 + i) as *mut i8) = 0 as i8; - debug!(" => file {}", CStr::from_ptr(dirp.add(pos + 11) as *const i8).to_str().unwrap()); + debug!( + " => file {}", + CStr::from_ptr(dirp.add(pos + 11) as *const i8) + .to_str() + .unwrap() + ); } pos += offset; } diff --git a/lib/emscripten/src/syscalls/windows.rs b/lib/emscripten/src/syscalls/windows.rs index b3f7b748fd7..5551dd6e12b 100644 --- a/lib/emscripten/src/syscalls/windows.rs +++ b/lib/emscripten/src/syscalls/windows.rs @@ -261,6 +261,12 @@ pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { -1 } +// getuid +pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { + debug!("emscripten::___syscall199 (getuid)"); + -1 +} + // getdents pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall220"); From 675caf042ca1b0d347e7b36ff05ff1b84af53fff Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 21:01:29 +0200 Subject: [PATCH 09/16] Various lint fixes --- lib/emscripten/src/lib.rs | 1 - lib/emscripten/src/libc.rs | 3 +++ lib/emscripten/src/syscalls/unix.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 33e5f46d5bf..e7b51a26a91 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -31,7 +31,6 @@ use ::libc::DIR as libcDIR; #[cfg(not(unix))] type libcDIR = u8; - #[macro_use] mod macros; diff --git a/lib/emscripten/src/libc.rs b/lib/emscripten/src/libc.rs index 60767db1d3e..1f5629ddfb0 100644 --- a/lib/emscripten/src/libc.rs +++ b/lib/emscripten/src/libc.rs @@ -52,12 +52,15 @@ pub fn killpg(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { #[cfg(unix)] pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { + debug!("emscripten::pathconf"); let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; unsafe { libc::pathconf(path, name).try_into().unwrap() } } #[cfg(not(unix))] pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { + debug!("emscripten::pathconf"); + 0 } pub fn setpwent(_ctx: &mut Ctx) { diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index 20f1f905594..743264bf2d3 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -894,7 +894,7 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { *(dirp.add(pos + 4) as *mut u32) = pos as u32; *(dirp.add(pos + 8) as *mut u16) = offset as u16; *(dirp.add(pos + 10) as *mut u8) = (*dirent).d_type; - let upper_bound = std::cmp::min((*dirent).d_reclen, 256) as usize; + let upper_bound = std::cmp::min((*dirent).d_reclen, 255) as usize; let mut i = 0; while i < upper_bound { *(dirp.add(pos + 11 + i) as *mut i8) = (*dirent).d_name[i]; From 7ebb90527c9256fad354821183ad885212417bb7 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 21:23:41 +0200 Subject: [PATCH 10/16] Fixes remaining clippy issues --- lib/emscripten/src/math.rs | 8 ++++---- lib/emscripten/src/syscalls/mod.rs | 9 --------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index 7e420caaed2..b9906a708ed 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -1,13 +1,13 @@ -use std::{f32, f64}; use wasmer_runtime_core::vm::Ctx; +#![allow(clippy::all)] pub fn _llvm_copysign_f32(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { - // f32::copysign(x, y) - f64::copysign(x, y) + x.copysign(y) } +#![allow(clippy::all)] pub fn _llvm_copysign_f64(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { - f64::copysign(x, y) + x.copysign(y) } /// emscripten: _llvm_log10_f64 diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index a5c7bb3839b..90c703d5826 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -27,7 +27,6 @@ use libc::{ exit, fstat, getpid, - getuid, // readlink, // iovec, lseek, @@ -612,14 +611,6 @@ pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } -// getuid -pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { - debug!("emscripten::___syscall199 (getuid)"); - let uid = unsafe { getuid() as _ }; - debug!(" => {}", uid); - uid -} - pub fn ___syscall209(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall209"); -1 From 583fdb5c4a8a0c34213af5da0ff8ee595e5b0911 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 21:24:39 +0200 Subject: [PATCH 11/16] Updated Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eac1767c3c..50d4f1549b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#471](https://github.com/wasmerio/wasmer/pull/471) Added missing functions to run Python. Improved Emscripten bindings - [#474](https://github.com/wasmerio/wasmer/pull/474) Set the install name of the dylib to `@rpath` - [#490](https://github.com/wasmerio/wasmer/pull/490) Add MiddlewareChain and StreamingCompiler to runtime - [#487](https://github.com/wasmerio/wasmer/pull/487) Fix stack offset check in singlepass backend From 86b78c6b14d3ed053c8f5b9289f1afbcd98ae26c Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 21:32:05 +0200 Subject: [PATCH 12/16] Fixed clippy issues --- lib/emscripten/src/math.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index b9906a708ed..5b1e2420600 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -1,11 +1,11 @@ use wasmer_runtime_core::vm::Ctx; -#![allow(clippy::all)] +#[allow(clippy::all)] pub fn _llvm_copysign_f32(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { x.copysign(y) } -#![allow(clippy::all)] +#[allow(clippy::all)] pub fn _llvm_copysign_f64(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { x.copysign(y) } From 4059562560c44125f60a31a5326f384912353552 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 21:37:55 +0200 Subject: [PATCH 13/16] Updated nightly version --- .circleci/config.yml | 4 ++-- Makefile | 2 +- lib/emscripten/src/math.rs | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index eead29af046..b608db640c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,9 +35,9 @@ jobs: name: Install lint deps command: | git config --global --unset url."ssh://git@github.com".insteadOf || true - rustup toolchain install nightly-2019-02-27 + rustup toolchain install nightly-2019-05-20 rustup component add rustfmt - rustup component add clippy --toolchain=nightly-2019-02-27 || cargo +nightly-2019-02-27 install --git https://github.com/rust-lang/rust-clippy/ --force clippy + rustup component add clippy --toolchain=nightly-2019-05-20 || cargo +nightly-2019-05-20 install --git https://github.com/rust-lang/rust-clippy/ --force clippy - run: name: Execute lints command: | diff --git a/Makefile b/Makefile index 463e7f8e168..a29af047b39 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ integration-tests: release lint: cargo fmt --all -- --check - cargo +nightly-2019-02-27 clippy --all + cargo +nightly-2019-05-20 clippy --all precommit: lint test diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index 5b1e2420600..3aea6f8b7a7 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -1,11 +1,9 @@ use wasmer_runtime_core::vm::Ctx; -#[allow(clippy::all)] pub fn _llvm_copysign_f32(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { x.copysign(y) } -#[allow(clippy::all)] pub fn _llvm_copysign_f64(_ctx: &mut Ctx, x: f64, y: f64) -> f64 { x.copysign(y) } From b9fa698a73dec3bb85b2c575ca27415822529f6b Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 13 Jun 2019 21:53:37 +0200 Subject: [PATCH 14/16] Assert alignment --- lib/emscripten/src/io/unix.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index 16212c16486..24ee38f4cb5 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -27,6 +27,7 @@ pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 { } /// getpwuid +#[allow(clippy::cast_ptr_alignment)] pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 { debug!("emscripten::getpwuid {}", uid); @@ -40,13 +41,13 @@ pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 { pw_dir: u32, pw_shell: u32, } - + unsafe { let passwd = &*_getpwuid(uid as _); let passwd_struct_offset = call_malloc(ctx, mem::size_of::() as _); - let passwd_struct_ptr = emscripten_memory_pointer!(ctx.memory(0), passwd_struct_offset) as *mut GuestPasswd; + assert_eq!(passwd_struct_ptr as usize % std::cmp::min(std::mem::size_of::(), std::mem::align_of::()), 0); (*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx, passwd.pw_name); (*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(ctx, passwd.pw_passwd); (*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx, passwd.pw_gecos); From 95f39cedec4a698e7143d47058e70088ec25f99b Mon Sep 17 00:00:00 2001 From: Syrus Date: Fri, 14 Jun 2019 09:53:07 +0200 Subject: [PATCH 15/16] Fixed last linting issues (hopefully) --- lib/emscripten/src/io/unix.rs | 8 ++++++-- lib/emscripten/src/libc.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index 24ee38f4cb5..e8f1a6fa526 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -41,13 +41,17 @@ pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 { pw_dir: u32, pw_shell: u32, } - + unsafe { let passwd = &*_getpwuid(uid as _); let passwd_struct_offset = call_malloc(ctx, mem::size_of::() as _); let passwd_struct_ptr = emscripten_memory_pointer!(ctx.memory(0), passwd_struct_offset) as *mut GuestPasswd; - assert_eq!(passwd_struct_ptr as usize % std::cmp::min(std::mem::size_of::(), std::mem::align_of::()), 0); + assert_eq!( + passwd_struct_ptr as usize + % std::cmp::min(std::mem::size_of::(), std::mem::align_of::()), + 0 + ); (*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx, passwd.pw_name); (*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(ctx, passwd.pw_passwd); (*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx, passwd.pw_gecos); diff --git a/lib/emscripten/src/libc.rs b/lib/emscripten/src/libc.rs index 1f5629ddfb0..988f9c11b36 100644 --- a/lib/emscripten/src/libc.rs +++ b/lib/emscripten/src/libc.rs @@ -58,7 +58,7 @@ pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { } #[cfg(not(unix))] -pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 { +pub fn pathconf(_ctx: &mut Ctx, _path_ptr: i32, _name: i32) -> i32 { debug!("emscripten::pathconf"); 0 } From 6467816ea8dc3057642256610f290ee977486f3f Mon Sep 17 00:00:00 2001 From: Syrus Date: Fri, 14 Jun 2019 10:26:39 +0200 Subject: [PATCH 16/16] Fixed asseertion of alignment --- lib/emscripten/src/io/unix.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index e8f1a6fa526..c9206b343f4 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -48,8 +48,7 @@ pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 { let passwd_struct_ptr = emscripten_memory_pointer!(ctx.memory(0), passwd_struct_offset) as *mut GuestPasswd; assert_eq!( - passwd_struct_ptr as usize - % std::cmp::min(std::mem::size_of::(), std::mem::align_of::()), + passwd_struct_ptr as usize % std::mem::align_of::(), 0 ); (*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx, passwd.pw_name);