332: fix lstat64; heap size; and stat r=MarkMcCaskey a=MarkMcCaskey

- Get https://github.com/nikic/PHP-Parser working 🎉 
- fixes memory issue bug which looked like relative paths didn't work, but was really pointer aliasing corrupting data

Co-authored-by: Mark McCaskey <mark@wasmer.io>
This commit is contained in:
bors[bot] 2019-04-08 18:58:48 +00:00
commit 7f8b1ea521
4 changed files with 29 additions and 19 deletions

View File

@ -17,10 +17,9 @@ pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u
} }
/// emscripten: _emscripten_get_heap_size /// 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",); debug!("emscripten::_emscripten_get_heap_size",);
// TODO: Fix implementation ctx.memory(0).size().bytes().0 as u32
162_107_392
} }
/// emscripten: _emscripten_resize_heap /// emscripten: _emscripten_resize_heap

View File

@ -57,6 +57,7 @@ use libc::{
sockaddr, sockaddr,
socket, socket,
socklen_t, socklen_t,
stat,
symlink, symlink,
uid_t, uid_t,
uname, uname,
@ -73,6 +74,7 @@ use libc::{
}; };
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
use crate::utils;
#[allow(unused_imports)] #[allow(unused_imports)]
use std::io::Error; use std::io::Error;
use std::mem; use std::mem;
@ -88,7 +90,7 @@ extern "C" {
} }
#[cfg(not(target_os = "macos"))] #[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 // Another conditional constant for name resolution: Macos et iOS use
// SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket. // 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 { pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall196 (lstat64) {}", _which); debug!("emscripten::___syscall196 (lstat64) {}", _which);
let path_ptr: c_int = varargs.get(ctx); let path_ptr: c_int = varargs.get(ctx);
let buf_ptr: c_int = varargs.get(ctx); let buf_ptr: u32 = varargs.get(ctx);
let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const c_char; let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8;
let buf = emscripten_memory_pointer!(ctx.memory(0), buf_ptr) as *mut c_void; unsafe {
let result = unsafe { lstat64(path, buf as _) }; let mut stat: stat = std::mem::zeroed();
debug!(
"=> path: {}, buf: {} = fd: {}\npath: {}\nlast os error: {}", #[cfg(target_os = "macos")]
path_ptr, let stat_ptr = &mut stat as *mut stat as *mut c_void;
buf_ptr, #[cfg(not(target_os = "macos"))]
result, let stat_ptr = &mut stat as *mut stat;
unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() },
Error::last_os_error(), #[cfg(target_os = "macos")]
); let ret = lstat64(path, stat_ptr);
result #[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 /// fallocate

View File

@ -125,7 +125,7 @@ pub struct GuestStat {
st_atime: u64, st_atime: u64,
st_mtime: u64, st_mtime: u64,
st_ctime: u64, st_ctime: u64,
st_ino: u64, st_ino: u32,
} }
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]

View File

@ -1,5 +1,5 @@
use crate::{memory::MemoryType, module::ModuleInfo, structures::TypedIndex, units::Pages}; use crate::{memory::MemoryType, module::ModuleInfo, structures::TypedIndex, units::Pages};
use std::{borrow::Cow, mem}; use std::borrow::Cow;
/// Represents a WebAssembly type. /// Represents a WebAssembly type.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]