diff --git a/src/apis/emscripten/syscalls.rs b/src/apis/emscripten/syscalls.rs index 13a71cbcd..16ba60d8d 100644 --- a/src/apis/emscripten/syscalls.rs +++ b/src/apis/emscripten/syscalls.rs @@ -486,11 +486,55 @@ pub extern "C" fn ___syscall146( ) -> ssize_t { debug!("emscripten::___syscall146 (writev)"); let fd: i32 = varargs.get(instance); - let iov: u32 = varargs.get(instance); + let iov: i32 = varargs.get(instance); let iovcnt: i32 = varargs.get(instance); + + #[repr(C)] + struct GuestIovec { + iov_base: i32, + iov_len: i32, + } + debug!("=> fd: {}, iov: {}, iovcnt = {}", fd, iov, iovcnt); - let iov_addr = instance.memory_offset_addr(0, iov as usize) as *mut iovec; - unsafe { writev(fd, iov_addr, iovcnt) } + // let iov_addr = instance.memory_offset_addr(0, iov as usize) as *mut iovec; + let guest_iov_addr = instance.memory_offset_addr(0, iov as usize) as *mut GuestIovec; + // let mut ret: ssize_t = 0; + unsafe { + // let ioc_base = + let iov_addr = iovec { + iov_base: (*guest_iov_addr).iov_base as _, + iov_len: (*guest_iov_addr).iov_len as _, + }; + // let base = (*guest_iov_addr).iov_base; + // for i in 0..iovcnt { + // // debug!("HEY"); + // // let ptr_addr = (base + i*8) as usize as *const c_void; + // // let len = (base + i*8 + 4) as usize as *const usize; + // let ptr_addr = instance.memory_offset_addr(0, (base + i*8) as usize) as *const c_void; + // let len = instance.memory_offset_addr(0, (base + i*8 +4) as usize) as usize; + + // debug!("=> iov_addr: {:?}, {:?}", ptr_addr, len); + // // unsafe { + // let curr = write(fd, ptr_addr, len); + // if curr < 0 { + // return -1; + // } + // ret = ret + curr; + // // } + // } + // ret + // for (var i = 0; i < iovcnt; i++) { + // var ptr = HEAP32[(((iov)+(i*8))>>2)]; + // var len = HEAP32[(((iov)+(i*8 + 4))>>2)]; + + // let buf_addr = instance.memory_offset_addr(0, iov_addr.iov_base as usize) as *const c_void; + + // write(fd, buf_addr, count as usize) as i32 + + // debug!("=> iov_addr: {:?}, {:?}", iov_addr.iov_base, iov_addr.iov_len); + + writev(fd, &iov_addr, iovcnt) + } } // pread