Merge branch 'master' into feature/jq

This commit is contained in:
Syrus
2019-05-21 17:15:12 -07:00
83 changed files with 8739 additions and 83 deletions

View File

@ -52,6 +52,18 @@
- **\_pthread_key_create**     [:top:](#host-apis)
```rust
```
- **\_pthread_rwlock_destroy**     [:top:](#host-apis)
```rust
```
- **\_pthread_rwlock_init**     [:top:](#host-apis)
```rust
```
- **\_pthread_rwlock_wrlock**     [:top:](#host-apis)
```rust
```
- **\_pthread_setspecific**     [:top:](#host-apis)
```rust

View File

@ -15,6 +15,11 @@ pub fn getTempRet0(ctx: &mut Ctx) -> i32 {
get_emscripten_data(ctx).temp_ret_0
}
pub fn _alarm(_ctx: &mut Ctx, _seconds: u32) -> i32 {
debug!("emscripten::_alarm({})", _seconds);
0
}
pub fn _atexit(_ctx: &mut Ctx, _func: i32) -> i32 {
debug!("emscripten::_atexit");
// TODO: implement atexit properly
@ -105,6 +110,18 @@ pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_key_create");
0
}
pub fn _pthread_rwlock_destroy(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_destroy({})", _rwlock);
0
}
pub fn _pthread_rwlock_init(_ctx: &mut Ctx, _rwlock: i32, _attr: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr);
0
}
pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_wrlock({})", _rwlock);
0
}
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
debug!("emscripten::_pthread_create");
0
@ -185,6 +202,12 @@ pub fn ___gxx_personality_v0(
debug!("emscripten::___gxx_personality_v0");
0
}
pub fn _gai_strerror(_ctx: &mut Ctx, _ecode: i32) -> i32 {
debug!("emscripten::_gai_strerror({})", _ecode);
0
}
#[cfg(target_os = "linux")]
pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::getdtablesize");
@ -216,6 +239,22 @@ pub fn _getloadavg(_ctx: &mut Ctx, _loadavg: i32, _nelem: i32) -> i32 {
debug!("emscripten::getloadavg");
0
}
pub fn _getnameinfo(
_ctx: &mut Ctx,
_addr: i32,
_addrlen: i32,
_host: i32,
_hostlen: i32,
_serv: i32,
_servlen: i32,
_flags: i32,
) -> i32 {
debug!(
"emscripten::_getnameinfo({}, {}, {}, {}, {}, {}, {})",
_addr, _addrlen, _host, _hostlen, _serv, _servlen, _flags
);
0
}
// Invoke functions
// They save the stack to allow unwinding

View File

@ -1,25 +0,0 @@
use std::io;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Read;
pub struct FileDescriptor(libc::c_int);
impl FileDescriptor {
pub fn new(file_descriptor_number: libc::c_int) -> FileDescriptor {
FileDescriptor(file_descriptor_number)
}
}
impl Read for FileDescriptor {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let file_descriptor: libc::c_int = self.0;
let count =
unsafe { libc::read(file_descriptor, buf.as_mut_ptr() as *mut libc::c_void, 1) };
if count < 0 {
Err(Error::new(ErrorKind::Other, "read error"))
} else {
Ok(count as usize)
}
}
}

View File

@ -24,9 +24,6 @@ use wasmer_runtime_core::{
#[macro_use]
mod macros;
//#[cfg(test)]
mod file_descriptor;
pub mod stdio;
// EMSCRIPTEN APIS
mod bitwise;
@ -47,6 +44,7 @@ mod signal;
mod storage;
mod syscalls;
mod time;
mod ucontext;
mod utils;
mod varargs;
@ -729,6 +727,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_dlsym" => func!(crate::linking::_dlsym),
// wasm32-unknown-emscripten
"_alarm" => func!(crate::emscripten_target::_alarm),
"_atexit" => func!(crate::emscripten_target::_atexit),
"setTempRet0" => func!(crate::emscripten_target::setTempRet0),
"getTempRet0" => func!(crate::emscripten_target::getTempRet0),
@ -779,11 +778,16 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_pthread_setspecific" => func!(crate::emscripten_target::_pthread_setspecific),
"_pthread_once" => func!(crate::emscripten_target::_pthread_once),
"_pthread_key_create" => func!(crate::emscripten_target::_pthread_key_create),
"_pthread_rwlock_destroy" => func!(crate::emscripten_target::_pthread_rwlock_destroy),
"_pthread_rwlock_init" => func!(crate::emscripten_target::_pthread_rwlock_init),
"_pthread_rwlock_wrlock" => func!(crate::emscripten_target::_pthread_rwlock_wrlock),
"___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0),
"_gai_strerror" => func!(crate::emscripten_target::_gai_strerror),
"_getdtablesize" => func!(crate::emscripten_target::_getdtablesize),
"_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr),
"_gethostbyname_r" => func!(crate::emscripten_target::_gethostbyname_r),
"_getloadavg" => func!(crate::emscripten_target::_getloadavg),
"_getnameinfo" => func!(crate::emscripten_target::_getnameinfo),
"invoke_dii" => func!(crate::emscripten_target::invoke_dii),
"invoke_diiii" => func!(crate::emscripten_target::invoke_diiii),
"invoke_iiiii" => func!(crate::emscripten_target::invoke_iiiii),
@ -823,6 +827,12 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"invoke_viid" => func!(crate::emscripten_target::invoke_viid),
"invoke_viidii" => func!(crate::emscripten_target::invoke_viidii),
"invoke_viidddddddd" => func!(crate::emscripten_target::invoke_viidddddddd),
// ucontext
"_getcontext" => func!(crate::ucontext::_getcontext),
"_makecontext" => func!(crate::ucontext::_makecontext),
"_setcontext" => func!(crate::ucontext::_setcontext),
"_swapcontext" => func!(crate::ucontext::_swapcontext),
};
for null_func_name in globals.null_func_names.iter() {

View File

@ -1,85 +0,0 @@
use super::file_descriptor::FileDescriptor;
use libc;
use std::io::BufReader;
use std::io::Read;
// A struct to hold the references to the base stdout and the captured one
pub struct StdioCapturer {
stdout_backup: libc::c_int,
stderr_backup: libc::c_int,
stdout_reader: libc::c_int,
stderr_reader: libc::c_int,
}
#[cfg(not(target_os = "windows"))]
use libc::{STDERR_FILENO, STDOUT_FILENO};
#[cfg(target_os = "windows")]
const _STDIN_FILENO: libc::c_int = 0;
#[cfg(target_os = "windows")]
const STDOUT_FILENO: libc::c_int = 1;
#[cfg(target_os = "windows")]
const STDERR_FILENO: libc::c_int = 2;
// Implementation inspired in
// https://github.com/rust-lang/rust/blob/7d52cbce6db83e4fc2d8706b4e4b9c7da76cbcf8/src/test/run-pass/issues/issue-30490.rs
// Currently only works in Unix systems (Mac, Linux)
impl StdioCapturer {
fn pipe() -> (libc::c_int, libc::c_int) {
let mut fds = [0; 2];
#[cfg(not(target_os = "windows"))]
assert_eq!(unsafe { libc::pipe(fds.as_mut_ptr()) }, 0);
#[cfg(target_os = "windows")]
assert_eq!(
unsafe { libc::pipe(fds.as_mut_ptr(), 1000, libc::O_TEXT) },
0
);
(fds[0], fds[1])
}
pub fn new() -> Self {
let stdout_backup = unsafe { libc::dup(STDOUT_FILENO) };
let stderr_backup = unsafe { libc::dup(STDERR_FILENO) };
let (stdout_reader, stdout_writer) = Self::pipe();
let (stderr_reader, stderr_writer) = Self::pipe();
assert!(unsafe { libc::dup2(stdout_writer, STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(stderr_writer, STDERR_FILENO) } > -1);
// Make sure we close any duplicates of the writer end of the pipe,
// otherwise we can get stuck reading from the pipe which has open
// writers but no one supplying any input
assert_eq!(unsafe { libc::close(stdout_writer) }, 0);
assert_eq!(unsafe { libc::close(stderr_writer) }, 0);
StdioCapturer {
stdout_backup,
stderr_backup,
stdout_reader,
stderr_reader,
}
}
pub fn end(self) -> Result<(String, String), std::io::Error> {
// The Stdio passed into the Command took over (and closed) std{out, err}
// so we should restore them as they were.
assert!(unsafe { libc::dup2(self.stdout_backup, STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(self.stderr_backup, STDERR_FILENO) } > -1);
let fd = FileDescriptor::new(self.stdout_reader);
let mut reader = BufReader::new(fd);
let mut stdout_read = "".to_string();
let _ = reader.read_to_string(&mut stdout_read)?;
let fd = FileDescriptor::new(self.stderr_reader);
let mut reader = BufReader::new(fd);
let mut stderr_read = "".to_string();
let _ = reader.read_to_string(&mut stderr_read)?;
Ok((stdout_read, stderr_read))
}
}

View File

@ -0,0 +1,20 @@
use wasmer_runtime_core::vm::Ctx;
pub fn _getcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 {
debug!("emscripten::_getcontext({})", _ucp);
0
}
pub fn _makecontext(_ctx: &mut Ctx, _ucp: i32, _func: i32, _argc: i32, _argv: i32) {
debug!(
"emscripten::_makecontext({}, {}, {}, {})",
_ucp, _func, _argc, _argv
);
}
pub fn _setcontext(_ctx: &mut Ctx, _ucp: i32) -> i32 {
debug!("emscripten::_setcontext({})", _ucp);
0
}
pub fn _swapcontext(_ctx: &mut Ctx, _oucp: i32, _ucp: i32) -> i32 {
debug!("emscripten::_swapcontext({}, {})", _oucp, _ucp);
0
}