Fix lint errors and windows build

This commit is contained in:
Syrus
2019-06-13 20:46:05 +02:00
parent 8829e1d901
commit 1560849e40
7 changed files with 50 additions and 15 deletions

View File

@ -5,7 +5,7 @@ use crate::env::get_emscripten_data;
use libc::getdtablesize;
use wasmer_runtime_core::vm::Ctx;
pub fn asm_const_i(_ctx: &mut Ctx, _val: i32) -> i32{
pub fn asm_const_i(_ctx: &mut Ctx, _val: i32) -> i32 {
debug!("emscripten::asm_const_i: {}", _val);
0
}

View File

@ -1,7 +1,7 @@
use std::mem;
use libc::{chroot as _chroot, printf as _printf, getpwuid as _getpwuid};
use super::super::utils::copy_cstr_into_wasm;
use super::super::env::call_malloc;
use super::super::utils::copy_cstr_into_wasm;
use libc::{chroot as _chroot, getpwuid as _getpwuid, printf as _printf};
use std::mem;
use wasmer_runtime_core::vm::Ctx;

View File

@ -24,6 +24,14 @@ use wasmer_runtime_core::{
Func, Instance, IsExport, Module,
};
#[cfg(unix)]
use ::libc::DIR as libcDIR;
// We use a placeholder for windows
#[cfg(not(unix))]
type libcDIR = u8;
#[macro_use]
mod macros;
@ -76,8 +84,6 @@ lazy_static! {
const GLOBAL_BASE: u32 = 1024;
const STATIC_BASE: u32 = GLOBAL_BASE;
use ::libc::DIR as libcDIR;
pub struct EmscriptenData<'a> {
pub malloc: Func<'a, u32, u32>,
pub free: Func<'a, u32>,

View File

@ -1,6 +1,7 @@
extern crate libc;
extern crate wasmer_runtime_core;
#[cfg(unix)]
use std::convert::TryInto;
use wasmer_runtime_core::vm::Ctx;
@ -49,12 +50,14 @@ pub fn killpg(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
0
}
#[cfg(unix)]
pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 {
let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8;
unsafe { libc::pathconf(path, name).try_into().unwrap() }
}
unsafe {
libc::pathconf(path, name).try_into().unwrap()
}
#[cfg(not(unix))]
pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 {
}
pub fn setpwent(_ctx: &mut Ctx) {

View File

@ -27,6 +27,8 @@ use libc::{
exit,
fstat,
getpid,
getuid,
// readlink,
// iovec,
lseek,
off_t,
@ -39,8 +41,6 @@ use libc::{
// writev,
stat,
write,
getuid,
// readlink,
};
use wasmer_runtime_core::{
memory::ptr::{Array, WasmPtr},

View File

@ -26,6 +26,7 @@ use libc::{
getrusage,
getsockname,
getsockopt,
getuid,
gid_t,
in_addr_t,
in_port_t,
@ -74,6 +75,7 @@ use libc::{
SO_REUSEADDR,
TIOCGWINSZ,
};
#[allow(unused_imports)]
use std::ffi::CStr;
use wasmer_runtime_core::vm::Ctx;
@ -847,6 +849,14 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
0
}
// getuid
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall199 (getuid)");
let uid = unsafe { getuid() as _ };
debug!(" => {}", uid);
uid
}
// getdents
// dirent structure is
// i64, i64, u16 (280), i8, [i8; 256]
@ -856,7 +866,10 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
let fd: i32 = varargs.get(ctx);
let dirp_addr: i32 = varargs.get(ctx);
let count: u32 = varargs.get(ctx);
debug!("emscripten::___syscall220 (getdents) {} {} {}", fd, dirp_addr, count);
debug!(
"emscripten::___syscall220 (getdents) {} {} {}",
fd, dirp_addr, count
);
let dirp = emscripten_memory_pointer!(ctx.memory(0), dirp_addr) as *mut u8;
@ -864,10 +877,12 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
// need to persist stream across calls?
// let dir: *mut libc::DIR = unsafe { libc::fdopendir(fd) };
let mut dir = &*opened_dirs.entry(fd).or_insert_with(|| unsafe { Box::new(libc::fdopendir(fd)) });
let mut dir = &*opened_dirs
.entry(fd)
.or_insert_with(|| unsafe { Box::new(libc::fdopendir(fd)) });
let mut pos = 0;
let offset = 256+12;
let offset = 256 + 12;
while pos + offset <= count as usize {
let dirent = unsafe { readdir(**dir) };
if dirent.is_null() {
@ -887,7 +902,12 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
}
// We set the termination string char
*(dirp.add(pos + 11 + i) as *mut i8) = 0 as i8;
debug!(" => file {}", CStr::from_ptr(dirp.add(pos + 11) as *const i8).to_str().unwrap());
debug!(
" => file {}",
CStr::from_ptr(dirp.add(pos + 11) as *const i8)
.to_str()
.unwrap()
);
}
pos += offset;
}

View File

@ -261,6 +261,12 @@ pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
// getuid
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall199 (getuid)");
-1
}
// getdents
pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall220");