merge upstream/master into wasmer-private/feature/llvm-backend

This commit is contained in:
Lachlan Sneff
2019-03-04 13:03:32 -08:00
60 changed files with 1827 additions and 2087 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "wasmer-emscripten"
version = "0.1.0"
version = "0.2.1"
description = "Wasmer runtime emscripten implementation library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@@ -9,9 +9,9 @@ edition = "2018"
build = "build/mod.rs"
[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.1.0" }
wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" }
lazy_static = "1.2.0"
libc = { git = "https://github.com/rust-lang/libc" }
libc = "0.2.49"
byteorder = "1"
time = "0.1.41"
@@ -19,7 +19,7 @@ time = "0.1.41"
rand = "0.6"
[dev-dependencies]
wasmer-clif-backend = { path = "../clif-backend", version = "0.1.0" }
wasmer-clif-backend = { path = "../clif-backend", version = "0.2.0" }
wabt = "0.7.2"
[build-dependencies]

10
lib/emscripten/emtests/test_getcwd.c vendored Normal file
View File

@@ -0,0 +1,10 @@
#include <stdio.h>
#include <unistd.h>
int main() {
const unsigned int size = 256;
char cwd[size] = {};
char* buf = getcwd(cwd, size);
printf("getcwd\n");
return 0;
}

View File

@@ -0,0 +1 @@
getcwd

BIN
lib/emscripten/emtests/test_getcwd.wasm vendored Normal file

Binary file not shown.

View File

@@ -502,6 +502,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___syscall168" => func!(crate::syscalls::___syscall168),
"___syscall180" => func!(crate::syscalls::___syscall180),
"___syscall181" => func!(crate::syscalls::___syscall181),
"___syscall183" => func!(crate::syscalls::___syscall183),
"___syscall191" => func!(crate::syscalls::___syscall191),
"___syscall192" => func!(crate::syscalls::___syscall192),
"___syscall194" => func!(crate::syscalls::___syscall194),

View File

@@ -46,8 +46,13 @@ use std::slice;
// Another conditional constant for name resolution: Macos et iOS use
// SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket.
// Other platforms do otherwise.
use crate::env::get_emscripten_data;
use crate::utils::copy_cstr_into_wasm;
use crate::utils::read_string_from_wasm;
#[cfg(target_os = "darwin")]
use libc::SO_NOSIGPIPE;
use std::ffi::CString;
#[cfg(not(target_os = "darwin"))]
const SO_NOSIGPIPE: c_int = 0;
@@ -66,10 +71,10 @@ pub fn ___syscall3(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall3 (read) {}", which);
let fd: i32 = varargs.get(ctx);
let buf: u32 = varargs.get(ctx);
let count = varargs.get(ctx);
let count: i32 = varargs.get(ctx);
debug!("=> fd: {}, buf_offset: {}, count: {}", fd, buf, count);
let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut c_void;
let ret = unsafe { read(fd, buf_addr, count) };
let ret = unsafe { read(fd, buf_addr, count as _) };
debug!("=> ret: {}", ret);
ret as _
}
@@ -79,10 +84,10 @@ pub fn ___syscall4(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall4 (write) {}", which);
let fd: i32 = varargs.get(ctx);
let buf: u32 = varargs.get(ctx);
let count = varargs.get(ctx);
let count: i32 = varargs.get(ctx);
debug!("=> fd: {}, buf: {}, count: {}", fd, buf, count);
let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *const c_void;
unsafe { write(fd, buf_addr, count) as i32 }
unsafe { write(fd, buf_addr, count as _) as i32 }
}
/// close
@@ -186,6 +191,25 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
// getcwd
pub fn ___syscall183(ctx: &mut Ctx, buf_offset: u32, _size: u32) -> u32 {
debug!("emscripten::___syscall183");
use std::env;
let path = env::current_dir();
let path_string = path.unwrap().display().to_string();
let len = path_string.len();
unsafe {
let pointer_to_buffer =
emscripten_memory_pointer!(ctx.memory(0), buf_offset) as *mut libc::c_char;
let slice = slice::from_raw_parts_mut(pointer_to_buffer, len.clone());
for (byte, loc) in path_string.bytes().zip(slice.iter_mut()) {
*loc = byte as _;
}
*pointer_to_buffer.add(len.clone()) = 0;
}
buf_offset
}
// mmap2
pub fn ___syscall192(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall192 (mmap2) {}", which);
@@ -217,10 +241,10 @@ pub fn ___syscall140(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 {
// -> c_int
debug!("emscripten::___syscall140 (lseek) {}", which);
let fd: i32 = varargs.get(ctx);
let offset = varargs.get(ctx);
let offset: i32 = varargs.get(ctx);
let whence: i32 = varargs.get(ctx);
debug!("=> fd: {}, offset: {}, whence = {}", fd, offset, whence);
unsafe { lseek(fd, offset, whence) as _ }
unsafe { lseek(fd, offset as _, whence) as _ }
}
/// readv

View File

@@ -54,6 +54,7 @@ mod test_funcptrfunc;
mod test_funcs;
mod test_functionpointer_libfunc_varargs;
mod test_fwrite_0;
mod test_getcwd;
mod test_getgep;
mod test_getloadavg;
mod test_getopt;

View File

@@ -0,0 +1,9 @@
#[test]
fn test_getcwd() {
assert_emscripten_output!(
"../../emtests/test_getcwd.wasm",
"getcwd",
vec![],
"../../emtests/test_getcwd.out"
);
}