diff --git a/lib/emscripten/src/bitwise.rs b/lib/emscripten/src/bitwise.rs index aa7fbab3238..6868c402a55 100644 --- a/lib/emscripten/src/bitwise.rs +++ b/lib/emscripten/src/bitwise.rs @@ -1,8 +1,9 @@ +use crate::emscripten_target; use wasmer_runtime_core::vm::Ctx; ///emscripten: _llvm_bswap_i64 pub fn _llvm_bswap_i64(_ctx: &mut Ctx, _low: i32, high: i32) -> i32 { debug!("emscripten::_llvm_bswap_i64"); - // setTempRet0(low.swap_bytes) + emscripten_target::setTempRet0(_ctx, _low.swap_bytes()); high.swap_bytes() } diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 1877cbff1e5..1c575123b3d 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -5,8 +5,8 @@ use crate::env::get_emscripten_data; use libc::getdtablesize; use wasmer_runtime_core::vm::Ctx; -pub fn setTempRet0(_ctx: &mut Ctx, _a: i32) { - debug!("emscripten::setTempRet0"); +pub fn setTempRet0(_ctx: &mut Ctx, _val: i32) { + debug!("emscripten::setTempRet0: {}", _val); } pub fn getTempRet0(_ctx: &mut Ctx) -> i32 { debug!("emscripten::getTempRet0"); diff --git a/lib/emscripten/src/io/mod.rs b/lib/emscripten/src/io/mod.rs index ceee3bdc18d..6666cd5afbb 100644 --- a/lib/emscripten/src/io/mod.rs +++ b/lib/emscripten/src/io/mod.rs @@ -25,21 +25,35 @@ pub fn getprotobynumber(_ctx: &mut Ctx, _one: i32) -> i32 { } /// sigdelset -pub fn sigdelset(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { +pub fn sigdelset(ctx: &mut Ctx, set: i32, signum: i32) -> i32 { debug!("emscripten::sigdelset"); - unimplemented!() + let memory = ctx.memory(0); + #[allow(clippy::cast_ptr_alignment)] + let ptr = emscripten_memory_pointer!(memory, set) as *mut i32; + + unsafe { *ptr = *ptr & !(1 << (signum - 1)) } + + 0 } /// sigfillset -pub fn sigfillset(_ctx: &mut Ctx, _one: i32) -> i32 { +pub fn sigfillset(ctx: &mut Ctx, set: i32) -> i32 { debug!("emscripten::sigfillset"); - unimplemented!() + let memory = ctx.memory(0); + #[allow(clippy::cast_ptr_alignment)] + let ptr = emscripten_memory_pointer!(memory, set) as *mut i32; + + unsafe { + *ptr = -1; + } + + 0 } /// tzset pub fn tzset(_ctx: &mut Ctx) { - debug!("emscripten::tzset"); - unimplemented!() + debug!("emscripten::tzset - stub"); + //unimplemented!() } /// strptime diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index b544bdc115d..958202c7a90 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -512,8 +512,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___syscall77" => func!(crate::syscalls::___syscall77), "___syscall83" => func!(crate::syscalls::___syscall83), "___syscall85" => func!(crate::syscalls::___syscall85), - "___syscall91" => func!(crate::syscalls::___syscall191), - "___syscall94" => func!(crate::syscalls::___syscall194), + "___syscall91" => func!(crate::syscalls::___syscall91), + "___syscall94" => func!(crate::syscalls::___syscall94), "___syscall97" => func!(crate::syscalls::___syscall97), "___syscall102" => func!(crate::syscalls::___syscall102), "___syscall110" => func!(crate::syscalls::___syscall110), diff --git a/lib/emscripten/src/memory.rs b/lib/emscripten/src/memory.rs index 02877a011d9..16aece81d27 100644 --- a/lib/emscripten/src/memory.rs +++ b/lib/emscripten/src/memory.rs @@ -20,7 +20,7 @@ pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u pub fn _emscripten_get_heap_size(_ctx: &mut Ctx) -> u32 { debug!("emscripten::_emscripten_get_heap_size",); // TODO: Fix implementation - 16_777_216 + 162_107_392 } /// emscripten: _emscripten_resize_heap @@ -35,7 +35,7 @@ pub fn get_total_memory(_ctx: &mut Ctx) -> u32 { debug!("emscripten::get_total_memory"); // instance.memories[0].current_pages() // TODO: Fix implementation - 16_777_216 + _ctx.memory(0).size().bytes().0 as u32 } /// emscripten: enlargeMemory