Fixed ioctl in Unix. Fixed provied main arguments

This commit is contained in:
Syrus
2019-05-05 13:55:30 -07:00
parent 789af39f9e
commit 8f345e9e8c
2 changed files with 40 additions and 40 deletions

View File

@ -339,14 +339,14 @@ fn store_module_arguments(ctx: &mut Ctx, args: Vec<&str>) -> (u32, u32) {
} }
let (argv_offset, argv_slice): (_, &mut [u32]) = let (argv_offset, argv_slice): (_, &mut [u32]) =
unsafe { allocate_on_stack(ctx, ((argc + 1) * 4) as u32) }; unsafe { allocate_on_stack(ctx, ((argc) * 4) as u32) };
assert!(!argv_slice.is_empty()); assert!(!argv_slice.is_empty());
for (slot, arg) in argv_slice[0..argc].iter_mut().zip(args_slice.iter()) { for (slot, arg) in argv_slice[0..argc].iter_mut().zip(args_slice.iter()) {
*slot = *arg *slot = *arg
} }
argv_slice[argc] = 0; argv_slice[argc] = 0;
(argc as u32, argv_offset) (argc as u32 - 1, argv_offset)
} }
pub fn emscripten_set_up_memory(memory: &Memory, globals: &EmscriptenGlobalsData) { pub fn emscripten_set_up_memory(memory: &Memory, globals: &EmscriptenGlobalsData) {

View File

@ -357,44 +357,44 @@ pub fn ___syscall54(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
let request: u32 = varargs.get(ctx); let request: u32 = varargs.get(ctx);
debug!("=> fd: {}, op: {}", fd, request); debug!("=> fd: {}, op: {}", fd, request);
// Got the equivalents here: https://code.woboq.org/linux/linux/include/uapi/asm-generic/ioctls.h.html // Got the equivalents here: https://code.woboq.org/linux/linux/include/uapi/asm-generic/ioctls.h.html
let argp: u32 = varargs.get(ctx); // let argp: u32 = varargs.get(ctx);
let argp_ptr = emscripten_memory_pointer!(ctx.memory(0), argp) as *mut c_void; // let argp_ptr = emscripten_memory_pointer!(ctx.memory(0), argp) as *mut c_void;
let ret = unsafe { ioctl(fd, request as _, argp_ptr) }; // let ret = unsafe { ioctl(fd, request as _, argp_ptr) };
debug!("=> {}", ret); // debug!("=> {}", ret);
ret // ret
// match request as _ { match request as _ {
// 21537 => { 21537 => {
// // FIONBIO // FIONBIO
// let argp: u32 = varargs.get(ctx); let argp: u32 = varargs.get(ctx);
// let argp_ptr = emscripten_memory_pointer!(ctx.memory(0), argp) as *mut c_void; let argp_ptr = emscripten_memory_pointer!(ctx.memory(0), argp) as *mut c_void;
// let ret = unsafe { ioctl(fd, FIONBIO, argp_ptr) }; let ret = unsafe { ioctl(fd, FIONBIO, argp_ptr) };
// debug!("ret(FIONBIO): {}", ret); debug!("ret(FIONBIO): {}", ret);
// ret ret
// // 0 // 0
// } }
// 21523 => { 21523 => {
// // TIOCGWINSZ // TIOCGWINSZ
// let argp: u32 = varargs.get(ctx); let argp: u32 = varargs.get(ctx);
// let argp_ptr = emscripten_memory_pointer!(ctx.memory(0), argp) as *mut c_void; let argp_ptr = emscripten_memory_pointer!(ctx.memory(0), argp) as *mut c_void;
// let ret = unsafe { ioctl(fd, TIOCGWINSZ, argp_ptr) }; let ret = unsafe { ioctl(fd, TIOCGWINSZ, argp_ptr) };
// debug!("ret(TIOCGWINSZ): {} (harcoded to 0)", ret); debug!("ret(TIOCGWINSZ): {} (harcoded to 0)", ret);
// // ret // ret
// // TODO: We hardcode the value to have emscripten tests pass, as for some reason // TODO: We hardcode the value to have emscripten tests pass, as for some reason
// // when the capturer is active, ioctl returns -1 instead of 0 // when the capturer is active, ioctl returns -1 instead of 0
// if ret == -1 { if ret == -1 {
// 0 0
// } else { } else {
// ret ret
// } }
// } }
// _ => { _ => {
// debug!( debug!(
// "emscripten::___syscall54 -> non implemented case {}", "emscripten::___syscall54 -> non implemented case {}",
// request request
// ); );
// 0 0
// } }
// } }
} }
// socketcall // socketcall