mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 16:20:49 +00:00
Merge #332
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:
commit
7f8b1ea521
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user