From cf64cc8e0499dae527efe753f44cee41cf414809 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 26 Nov 2018 23:28:37 -0800 Subject: [PATCH] Added ___syscall12 and ___syscall192 implementations --- src/apis/emscripten/mod.rs | 10 +++++++++ src/apis/emscripten/syscalls.rs | 37 ++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/apis/emscripten/mod.rs b/src/apis/emscripten/mod.rs index 16f0dbab0..d2f8e3606 100644 --- a/src/apis/emscripten/mod.rs +++ b/src/apis/emscripten/mod.rs @@ -254,6 +254,16 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { "___syscall54", ImportValue::Func(syscalls::___syscall54 as _), ); + import_object.set( + "env", + "___syscall12", + ImportValue::Func(syscalls::___syscall12 as _), + ); + import_object.set( + "env", + "___syscall192", + ImportValue::Func(syscalls::___syscall192 as _), + ); // Process import_object.set( diff --git a/src/apis/emscripten/syscalls.rs b/src/apis/emscripten/syscalls.rs index 8848701cf..3308e5fc6 100644 --- a/src/apis/emscripten/syscalls.rs +++ b/src/apis/emscripten/syscalls.rs @@ -451,7 +451,8 @@ pub extern "C" fn ___syscall39( let mode: u32 = varargs.get(instance); let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8; - unsafe { mkdir(pathname_addr, mode as _) } + unsafe { mkdir(pathname_addr, mode as _) }; + 0 } // sys_stat64 @@ -508,3 +509,37 @@ pub extern "C" fn ___syscall221( _ => -1, } } + +// chdir +pub extern "C" fn ___syscall12( + _which: c_int, + mut varargs: VarArgs, + instance: &mut Instance, +) -> c_int { + debug!("emscripten::___syscall12"); + let path_addr: i32 = varargs.get(instance); + let path = 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 +} + +// mmap2 +pub extern "C" fn ___syscall192( + _which: c_int, + mut varargs: VarArgs, + instance: &mut Instance, +) -> c_int { + debug!("emscripten::___syscall192"); + let addr: i32 = varargs.get(instance); + let len: i32 = varargs.get(instance); + let prot: i32 = varargs.get(instance); + let flags: i32 = varargs.get(instance); + let fd: i32 = varargs.get(instance); + let off: i32 = varargs.get(instance); + debug!("{} {} {} {} {} {}", addr, len, prot, flags, fd, off); + 0 +}