From 40deb3e6edbd28107e7b554524332200befc2f65 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 5 Apr 2019 16:50:50 -0700 Subject: [PATCH 1/7] fix lstat64; increase num returned by heap size --- lib/emscripten/src/memory.rs | 2 +- lib/emscripten/src/syscalls/mod.rs | 18 ++++++++++++++++++ lib/emscripten/src/syscalls/unix.rs | 19 ------------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/emscripten/src/memory.rs b/lib/emscripten/src/memory.rs index 16aece81d..deeca7ddb 100644 --- a/lib/emscripten/src/memory.rs +++ b/lib/emscripten/src/memory.rs @@ -20,7 +20,7 @@ pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u pub fn _emscripten_get_heap_size(_ctx: &mut Ctx) -> u32 { debug!("emscripten::_emscripten_get_heap_size",); // TODO: Fix implementation - 162_107_392 + 162_107_392 * 2 } /// emscripten: _emscripten_resize_heap diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 37f6e2f51..645b48a81 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -418,6 +418,24 @@ pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } +/// lstat64 +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: 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 ret = lstat64(path, &mut stat as *mut stat as *mut c_void); + debug!("ret: {}", ret); + if ret != 0 { + return ret; + } + copy_stat_into_wasm(ctx, buf_ptr, &stat); + } + 0 +} + pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall220"); -1 diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index c8fa04101..a4bac74c6 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -759,25 +759,6 @@ pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in unsafe { uname(buf_addr) } } -/// lstat64 -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 -} - /// fallocate pub fn ___syscall324(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall324 (fallocate) {}", _which); From 09a207364bc59f8e4e700ebd84647b5b8115c8a6 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 5 Apr 2019 17:21:40 -0700 Subject: [PATCH 2/7] return total memory size for get_heap_size --- lib/emscripten/src/memory.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/emscripten/src/memory.rs b/lib/emscripten/src/memory.rs index deeca7ddb..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 * 2 + ctx.memory(0).size().bytes().0 as u32 } /// emscripten: _emscripten_resize_heap From b3a765446ac2f91d67ec10c93124106764dd9742 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 8 Apr 2019 11:26:25 -0700 Subject: [PATCH 3/7] fix bug in stat, move lstat64 back to unix --- lib/emscripten/src/syscalls/mod.rs | 18 ------------------ lib/emscripten/src/syscalls/unix.rs | 20 ++++++++++++++++++++ lib/emscripten/src/utils.rs | 2 +- lib/runtime-core/src/types.rs | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 645b48a81..37f6e2f51 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -418,24 +418,6 @@ pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in 0 } -/// lstat64 -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: 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 ret = lstat64(path, &mut stat as *mut stat as *mut c_void); - debug!("ret: {}", ret); - if ret != 0 { - return ret; - } - copy_stat_into_wasm(ctx, buf_ptr, &stat); - } - 0 -} - pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::___syscall220"); -1 diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index a4bac74c6..ad7f65909 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; @@ -775,3 +777,21 @@ pub fn ___syscall324(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in unimplemented!() } } + +/// lstat64 +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: 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 ret = lstat64(path, &mut stat as *mut stat as *mut c_void); + debug!("ret: {}", ret); + if ret != 0 { + return ret; + } + utils::copy_stat_into_wasm(ctx, buf_ptr, &stat); + } + 0 +} 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)] From 134ee3c5117c5e8c8f9b58c0c7779aece20b450c Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 8 Apr 2019 11:29:55 -0700 Subject: [PATCH 4/7] revert location of lstat64 --- lib/emscripten/src/syscalls/unix.rs | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index ad7f65909..82b7182fe 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -761,23 +761,6 @@ pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in unsafe { uname(buf_addr) } } -/// fallocate -pub fn ___syscall324(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall324 (fallocate) {}", _which); - let _fd: c_int = varargs.get(ctx); - let _mode: c_int = varargs.get(ctx); - let _offset: off_t = varargs.get(ctx); - let _len: off_t = varargs.get(ctx); - #[cfg(not(target_os = "macos"))] - unsafe { - fallocate(_fd, _mode, _offset, _len) - } - #[cfg(target_os = "macos")] - { - unimplemented!() - } -} - /// lstat64 pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { debug!("emscripten::___syscall196 (lstat64) {}", _which); @@ -795,3 +778,20 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { } 0 } + +/// fallocate +pub fn ___syscall324(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall324 (fallocate) {}", _which); + let _fd: c_int = varargs.get(ctx); + let _mode: c_int = varargs.get(ctx); + let _offset: off_t = varargs.get(ctx); + let _len: off_t = varargs.get(ctx); + #[cfg(not(target_os = "macos"))] + unsafe { + fallocate(_fd, _mode, _offset, _len) + } + #[cfg(target_os = "macos")] + { + unimplemented!() + } +} From 7cb2766292b0e2ae02b4b0d7ac454a57a3f0b21d Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 8 Apr 2019 11:36:54 -0700 Subject: [PATCH 5/7] fix type errors on Linux/OSX --- lib/emscripten/src/syscalls/unix.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index 82b7182fe..2d1db3a0c 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -90,7 +90,7 @@ extern "C" { } #[cfg(not(target_os = "macos"))] -use libc::{fallocate, fdatasync, ftruncate64, lstat64, madvise, wait4}; +use libc::{fallocate, fdatasync, ftruncate64, lstat64, madvise, stat64, wait4}; // Another conditional constant for name resolution: Macos et iOS use // SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket. @@ -768,8 +768,16 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let buf_ptr: u32 = varargs.get(ctx); let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; unsafe { + #[cfg(target_os = "macos")] let mut stat: stat = std::mem::zeroed(); - let ret = lstat64(path, &mut stat as *mut stat as *mut c_void); + #[cfg(not(target_os = "macos"))] + let mut stat: stat64 = 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 stat64 as *mut stat64; + let ret = lstat64(path, stat_ptr); debug!("ret: {}", ret); if ret != 0 { return ret; From b2a51b8fbdbd3812f52589bc936e7c4bf959193a Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 8 Apr 2019 11:48:04 -0700 Subject: [PATCH 6/7] try normal lstat on linux --- lib/emscripten/src/syscalls/unix.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index 2d1db3a0c..42c373ed5 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -90,7 +90,7 @@ extern "C" { } #[cfg(not(target_os = "macos"))] -use libc::{fallocate, fdatasync, ftruncate64, lstat64, madvise, stat64, 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. @@ -768,16 +768,14 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let buf_ptr: u32 = varargs.get(ctx); let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; unsafe { - #[cfg(target_os = "macos")] let mut stat: stat = std::mem::zeroed(); - #[cfg(not(target_os = "macos"))] - let mut stat: stat64 = 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 stat64 as *mut stat64; + #[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; From 03f0bf0c49a72dc2b722dbd6e4319216797d9a47 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 8 Apr 2019 11:53:15 -0700 Subject: [PATCH 7/7] change void* to stat* for lstat on linux --- lib/emscripten/src/syscalls/unix.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index 42c373ed5..32b63593f 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -770,7 +770,11 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { 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"))]