Skip to content

Commit

Permalink
Merge #332
Browse files Browse the repository at this point in the history
332: fix lstat64; heap size; and stat r=syrusakbary 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>
  • Loading branch information
bors[bot] and Mark McCaskey committed Apr 8, 2019
2 parents e5fc3b4 + b2a51b8 commit d499590
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
5 changes: 2 additions & 3 deletions lib/emscripten/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 21 additions & 14 deletions lib/emscripten/src/syscalls/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use libc::{
sockaddr,
socket,
socklen_t,
stat,
symlink,
uid_t,
uname,
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -763,19 +765,24 @@ 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();

let stat_ptr = &mut stat as *mut stat as *mut c_void;
#[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
Expand Down
2 changes: 1 addition & 1 deletion lib/emscripten/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/types.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down

0 comments on commit d499590

Please sign in to comment.