From cad4f9b5442f178858d3f566d88a1e24e28f6095 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 4 Apr 2019 13:58:05 -0700 Subject: [PATCH 1/4] get PHP kind of working... --- lib/emscripten/src/bitwise.rs | 3 ++- lib/emscripten/src/emscripten_target.rs | 4 ++-- lib/emscripten/src/env/unix/mod.rs | 5 ++++- lib/emscripten/src/io/mod.rs | 24 ++++++++++++++++++------ lib/emscripten/src/lib.rs | 2 +- lib/emscripten/src/memory.rs | 4 ++-- 6 files changed, 29 insertions(+), 13 deletions(-) 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/env/unix/mod.rs b/lib/emscripten/src/env/unix/mod.rs index 7c846150f32..4199aca475f 100644 --- a/lib/emscripten/src/env/unix/mod.rs +++ b/lib/emscripten/src/env/unix/mod.rs @@ -137,6 +137,9 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> i32 { debug!("emscripten::_sysconf {}", name); + match name { + 30 => 16384, // page size + _ => unsafe { sysconf(name) as i32 }, // TODO review i64 + } // TODO: Implement like emscripten expects regarding memory/page size - unsafe { sysconf(name) as i32 } // TODO review i64 } diff --git a/lib/emscripten/src/io/mod.rs b/lib/emscripten/src/io/mod.rs index ceee3bdc18d..2aee85fa66a 100644 --- a/lib/emscripten/src/io/mod.rs +++ b/lib/emscripten/src/io/mod.rs @@ -25,21 +25,33 @@ 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); + 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); + 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..6f15d96bea1 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -512,7 +512,7 @@ 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), + "___syscall91" => func!(crate::syscalls::___syscall91), "___syscall94" => func!(crate::syscalls::___syscall194), "___syscall97" => func!(crate::syscalls::___syscall97), "___syscall102" => func!(crate::syscalls::___syscall102), 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 From c307e7d37a381d2438612cefa182db89a62f973f Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 4 Apr 2019 14:01:56 -0700 Subject: [PATCH 2/4] revert changes to sysconf --- lib/emscripten/src/env/unix/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/emscripten/src/env/unix/mod.rs b/lib/emscripten/src/env/unix/mod.rs index 4199aca475f..7c846150f32 100644 --- a/lib/emscripten/src/env/unix/mod.rs +++ b/lib/emscripten/src/env/unix/mod.rs @@ -137,9 +137,6 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> i32 { debug!("emscripten::_sysconf {}", name); - match name { - 30 => 16384, // page size - _ => unsafe { sysconf(name) as i32 }, // TODO review i64 - } // TODO: Implement like emscripten expects regarding memory/page size + unsafe { sysconf(name) as i32 } // TODO review i64 } From f1fdb97d87f86e0f30105b92d1e485de9f7085a2 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 4 Apr 2019 14:06:53 -0700 Subject: [PATCH 3/4] allow cast_ptr_alignment --- lib/emscripten/src/io/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/emscripten/src/io/mod.rs b/lib/emscripten/src/io/mod.rs index 2aee85fa66a..6666cd5afbb 100644 --- a/lib/emscripten/src/io/mod.rs +++ b/lib/emscripten/src/io/mod.rs @@ -28,6 +28,7 @@ pub fn getprotobynumber(_ctx: &mut Ctx, _one: i32) -> i32 { pub fn sigdelset(ctx: &mut Ctx, set: i32, signum: i32) -> i32 { debug!("emscripten::sigdelset"); 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)) } @@ -39,6 +40,7 @@ pub fn sigdelset(ctx: &mut Ctx, set: i32, signum: i32) -> i32 { pub fn sigfillset(ctx: &mut Ctx, set: i32) -> i32 { debug!("emscripten::sigfillset"); let memory = ctx.memory(0); + #[allow(clippy::cast_ptr_alignment)] let ptr = emscripten_memory_pointer!(memory, set) as *mut i32; unsafe { From 974656c8b126b571043f45de2f1d8673b86b06e8 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 4 Apr 2019 14:12:39 -0700 Subject: [PATCH 4/4] fix this typo too --- lib/emscripten/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 6f15d96bea1..958202c7a90 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -513,7 +513,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___syscall83" => func!(crate::syscalls::___syscall83), "___syscall85" => func!(crate::syscalls::___syscall85), "___syscall91" => func!(crate::syscalls::___syscall91), - "___syscall94" => func!(crate::syscalls::___syscall194), + "___syscall94" => func!(crate::syscalls::___syscall94), "___syscall97" => func!(crate::syscalls::___syscall97), "___syscall102" => func!(crate::syscalls::___syscall102), "___syscall110" => func!(crate::syscalls::___syscall110),