From 0d3134c9fd7ef6bad4176fec9d28d4ec6248f908 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sat, 1 Dec 2018 12:12:04 -0800 Subject: [PATCH] Added emscripten _signal, improved chdir implementation --- src/apis/emscripten/mod.rs | 5 +++++ src/apis/emscripten/signal.rs | 5 +++++ src/apis/emscripten/syscalls.rs | 13 +++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/apis/emscripten/mod.rs b/src/apis/emscripten/mod.rs index d1b8a20c1..f816c2b15 100644 --- a/src/apis/emscripten/mod.rs +++ b/src/apis/emscripten/mod.rs @@ -306,6 +306,11 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { "_sigaction", ImportValue::Func(signal::_sigaction as _), ); + import_object.set( + "env", + "_signal", + ImportValue::Func(signal::_signal as _), + ); // Memory import_object.set( "env", diff --git a/src/apis/emscripten/signal.rs b/src/apis/emscripten/signal.rs index 71584db1e..a1519e2c9 100644 --- a/src/apis/emscripten/signal.rs +++ b/src/apis/emscripten/signal.rs @@ -28,3 +28,8 @@ pub extern "C" fn _sigprocmask() -> i32 { debug!("emscripten::_sigprocmask"); 0 } + +pub extern "C" fn _signal(sig: u32, _instance: &mut Instance) -> i32 { + debug!("emscripten::_signal ({})", sig); + 0 +} diff --git a/src/apis/emscripten/syscalls.rs b/src/apis/emscripten/syscalls.rs index 33d6498e0..b20efcbfe 100644 --- a/src/apis/emscripten/syscalls.rs +++ b/src/apis/emscripten/syscalls.rs @@ -53,6 +53,7 @@ use libc::{ select, FIONBIO, setpgid, + chdir }; /// exit @@ -134,13 +135,13 @@ pub extern "C" fn ___syscall12( ) -> c_int { debug!("emscripten::___syscall12 (chdir)"); let path_addr: i32 = varargs.get(instance); - let _path = unsafe { + unsafe { let path_ptr = instance.memory_offset_addr(0, path_addr as usize) as *const i8; - let path = std::ffi::CStr::from_ptr(path_ptr).to_str().unwrap(); - debug!("=> path: {}", path); - path - }; - 0 + let path = std::ffi::CStr::from_ptr(path_ptr); + let ret = chdir(path_ptr); + debug!("=> path: {:?}, ret: {}", path, ret); + ret + } } // getpid