diff --git a/lib/emscripten/src/memory.rs b/lib/emscripten/src/memory.rs index 16aece81d..9fccbdde4 100644 --- a/lib/emscripten/src/memory.rs +++ b/lib/emscripten/src/memory.rs @@ -17,10 +17,9 @@ pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u } /// emscripten: _emscripten_get_heap_size -pub fn _emscripten_get_heap_size(_ctx: &mut Ctx) -> u32 { +pub fn _emscripten_get_heap_size(ctx: &mut Ctx) -> u32 { debug!("emscripten::_emscripten_get_heap_size",); - // TODO: Fix implementation - 162_107_392 + ctx.memory(0).size().bytes().0 as u32 } /// emscripten: _emscripten_resize_heap diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index c8fa04101..32b63593f 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -57,6 +57,7 @@ use libc::{ sockaddr, socket, socklen_t, + stat, symlink, uid_t, uname, @@ -73,6 +74,7 @@ use libc::{ }; use wasmer_runtime_core::vm::Ctx; +use crate::utils; #[allow(unused_imports)] use std::io::Error; use std::mem; @@ -88,7 +90,7 @@ extern "C" { } #[cfg(not(target_os = "macos"))] -use libc::{fallocate, fdatasync, ftruncate64, lstat64, madvise, wait4}; +use libc::{fallocate, fdatasync, ftruncate64, lstat, madvise, wait4}; // Another conditional constant for name resolution: Macos et iOS use // SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket. @@ -763,19 +765,28 @@ pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall196 (lstat64) {}", _which); let path_ptr: c_int = varargs.get(ctx); - let buf_ptr: c_int = varargs.get(ctx); - let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const c_char; - let buf = emscripten_memory_pointer!(ctx.memory(0), buf_ptr) as *mut c_void; - let result = unsafe { lstat64(path, buf as _) }; - debug!( - "=> path: {}, buf: {} = fd: {}\npath: {}\nlast os error: {}", - path_ptr, - buf_ptr, - result, - unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() }, - Error::last_os_error(), - ); - result + let buf_ptr: u32 = varargs.get(ctx); + let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; + unsafe { + let mut stat: stat = std::mem::zeroed(); + + #[cfg(target_os = "macos")] + let stat_ptr = &mut stat as *mut stat as *mut c_void; + #[cfg(not(target_os = "macos"))] + let stat_ptr = &mut stat as *mut stat; + + #[cfg(target_os = "macos")] + let ret = lstat64(path, stat_ptr); + #[cfg(not(target_os = "macos"))] + let ret = lstat(path, stat_ptr); + + debug!("ret: {}", ret); + if ret != 0 { + return ret; + } + utils::copy_stat_into_wasm(ctx, buf_ptr, &stat); + } + 0 } /// fallocate diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index 5dcfd4e11..725f0ba94 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -125,7 +125,7 @@ pub struct GuestStat { st_atime: u64, st_mtime: u64, st_ctime: u64, - st_ino: u64, + st_ino: u32, } #[allow(clippy::cast_ptr_alignment)] diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 96a99a835..966bd4e39 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -1,5 +1,5 @@ use crate::{memory::MemoryType, module::ModuleInfo, structures::TypedIndex, units::Pages}; -use std::{borrow::Cow, mem}; +use std::borrow::Cow; /// Represents a WebAssembly type. #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]