Merge branch 'master' into feature/vfs

This commit is contained in:
Mackenzie Clark
2019-03-16 13:38:02 -07:00
16 changed files with 75 additions and 50 deletions

View File

@ -66,6 +66,8 @@ pub fn _unsetenv(ctx: &mut Ctx, name: c_int) -> c_int {
#[allow(clippy::cast_ptr_alignment)]
pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getpwnam {}", name_ptr);
#[cfg(feature = "debug")]
let _ = name_ptr;
#[repr(C)]
struct GuestPasswd {

View File

@ -7,7 +7,6 @@ use std::os::raw::c_char;
use crate::env::call_malloc;
use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm};
use std::ffi::CStr;
use wasmer_runtime_core::vm::Ctx;
extern "C" {
@ -29,10 +28,8 @@ pub fn _getenv(ctx: &mut Ctx, name: u32) -> u32 {
}
/// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int);
pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, overwrite: u32) -> c_int {
pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, _overwrite: u32) -> c_int {
debug!("emscripten::_setenv");
let name_addr = emscripten_memory_pointer!(ctx.memory(0), name);
let value_addr = emscripten_memory_pointer!(ctx.memory(0), value);
// setenv does not exist on windows, so we hack it with _putenv
let name = read_string_from_wasm(ctx.memory(0), name);
let value = read_string_from_wasm(ctx.memory(0), value);
@ -47,17 +44,16 @@ pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, overwrite: u32) -> c_int {
/// emscripten: _putenv // (name: *const char);
pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int {
debug!("emscripten::_putenv");
let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char;
debug!("=> name({:?})", unsafe { CStr::from_ptr(name_addr) });
debug!("=> name({:?})", unsafe {
std::ffi::CStr::from_ptr(name_addr)
});
unsafe { putenv(name_addr) }
}
/// emscripten: _unsetenv // (name: *const char);
pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int {
debug!("emscripten::_unsetenv");
let name_addr = emscripten_memory_pointer!(ctx.memory(0), name);
let name = read_string_from_wasm(ctx.memory(0), name);
// no unsetenv on windows, so use putenv with an empty value
let unsetenv_string = format!("{}=", name);
@ -70,6 +66,8 @@ pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int {
#[allow(clippy::cast_ptr_alignment)]
pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getpwnam {}", name_ptr);
#[cfg(not(feature = "debug"))]
let _ = name_ptr;
#[repr(C)]
struct GuestPasswd {
@ -102,6 +100,8 @@ pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
#[allow(clippy::cast_ptr_alignment)]
pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getgrnam {}", name_ptr);
#[cfg(not(feature = "debug"))]
let _ = name_ptr;
#[repr(C)]
struct GuestGroup {
@ -126,6 +126,8 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> c_long {
debug!("emscripten::_sysconf {}", name);
#[cfg(not(feature = "debug"))]
let _ = name;
// stub because sysconf is not valid on windows
0
}

View File

@ -1,4 +1,3 @@
use libc::{c_char, c_int};
use wasmer_runtime_core::vm::Ctx;
// This may be problematic for msvc which uses inline functions for the printf family
@ -15,13 +14,18 @@ use wasmer_runtime_core::vm::Ctx;
//}
/// putchar
pub fn putchar(ctx: &mut Ctx, chr: i32) {
pub fn putchar(_ctx: &mut Ctx, chr: i32) {
unsafe { libc::putchar(chr) };
}
/// printf
pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
pub fn printf(_ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
debug!("emscripten::printf {}, {}", memory_offset, extra);
#[cfg(not(feature = "debug"))]
{
let _ = memory_offset;
let _ = extra;
}
// unsafe {
// let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
// _printf(addr, extra)

View File

@ -1,10 +1,9 @@
use libc::{abort, c_char, c_int, exit, EAGAIN};
#[cfg(not(target_os = "windows"))]
use libc::pid_t;
type PidT = libc::pid_t;
#[cfg(target_os = "windows")]
type pid_t = c_int;
type PidT = c_int;
use std::ffi::CStr;
use wasmer_runtime_core::vm::Ctx;
@ -22,7 +21,7 @@ pub fn _abort(_ctx: &mut Ctx) {
}
}
pub fn _fork(_ctx: &mut Ctx) -> pid_t {
pub fn _fork(_ctx: &mut Ctx) -> PidT {
debug!("emscripten::_fork");
// unsafe {
// fork()

View File

@ -15,7 +15,7 @@ pub struct StdioCapturer {
use libc::{STDERR_FILENO, STDOUT_FILENO};
#[cfg(target_os = "windows")]
const STDIN_FILENO: libc::c_int = 0;
const _STDIN_FILENO: libc::c_int = 0;
#[cfg(target_os = "windows")]
const STDOUT_FILENO: libc::c_int = 1;
#[cfg(target_os = "windows")]

View File

@ -5,19 +5,21 @@ use libc::mkdir;
use libc::open;
use rand::Rng;
use std::env;
use std::ffi::CStr;
use std::ffi::CString;
use std::fs::File;
use std::io::Write;
use std::os::raw::c_int;
use wasmer_runtime_core::vm::Ctx;
#[allow(non_camel_case_types)]
type pid_t = c_int;
/// open
#[cfg(not(feature = "vfs"))]
pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall5 (open) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
let pathname: u32 = varargs.get(ctx);
let flags: i32 = varargs.get(ctx);
let mode: u32 = varargs.get(ctx);
@ -35,7 +37,7 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
let mut urandom_file = File::create(tmp_dir).unwrap();
// create some random bytes and put them into the file
let random_bytes = rand::thread_rng().gen::<[u8; 32]>();
urandom_file.write_all(&random_bytes);
let _ = urandom_file.write_all(&random_bytes).unwrap();
// put the file path string into wasm memory
let urandom_file_offset = unsafe { copy_cstr_into_wasm(ctx, ptr) };
let raw_pointer_to_urandom_file =
@ -59,16 +61,19 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
}
// chown
pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}
// mkdir
pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall39 (mkdir) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
let pathname: u32 = varargs.get(ctx);
let mode: u32 = varargs.get(ctx);
let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8;
unsafe { mkdir(pathname_addr) }
}
@ -87,59 +92,73 @@ pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
}
/// dup3
pub fn ___syscall330(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t {
pub fn ___syscall330(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t {
debug!("emscripten::___syscall330 (dup3)");
-1
}
/// ioctl
pub fn ___syscall54(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall54(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall54 (ioctl) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}
// socketcall
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall102(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall102 (socketcall) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}
// pread
pub fn ___syscall180(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall180(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall180 (pread) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}
// pwrite
pub fn ___syscall181(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall181(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall181 (pwrite) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}
/// wait4
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall114(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t {
pub fn ___syscall114(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t {
debug!("emscripten::___syscall114 (wait4)");
-1
}
// select
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall142(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall142(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall142 (newselect) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}
// setpgid
pub fn ___syscall57(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall57(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall57 (setpgid) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}
/// uname
// NOTE: Wondering if we should return custom utsname, like Emscripten.
pub fn ___syscall122(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall122 (uname) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1
}

View File

@ -10,6 +10,7 @@ use libc::{clockid_t, time as libc_time};
use libc::time_t;
#[cfg(target_os = "windows")]
#[allow(non_camel_case_types)]
type clockid_t = c_int;
#[cfg(target_os = "windows")]

View File

@ -90,6 +90,7 @@ pub unsafe fn allocate_cstr_on_stack<'a>(ctx: &'a mut Ctx, s: &str) -> (u32, &'a
(offset, slice)
}
#[cfg(not(target_os = "windows"))]
pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_char) -> u32 {
let _total_num = {
let mut ptr = cstrs;