Merge branch 'master' into feature/emscripten-refactor

This commit is contained in:
Syrus 2018-12-17 22:24:44 -08:00
commit bb298f1890
14 changed files with 94 additions and 109 deletions

View File

@ -7,12 +7,6 @@ jobs:
steps:
- checkout
- run:
name: Pull submodules
command: |
# git pull --recurse-submodules
git submodule sync --recursive
git submodule update --recursive --init
- restore_cache:
keys:
- v4-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}
@ -34,12 +28,6 @@ jobs:
steps:
- checkout
- run:
name: Pull submodules
command: |
# git pull --recurse-submodules
git submodule sync --recursive
git submodule update --recursive --init
- restore_cache:
keys:
- v4-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}
@ -82,12 +70,6 @@ jobs:
steps:
- checkout
- run:
name: Pull submodules
command: |
# git pull --recurse-submodules
git submodule sync --recursive
git submodule update --recursive --init
- restore_cache:
keys:
- v4-cargo-cache-darwin-{{ arch }}-{{ checksum "Cargo.lock" }}

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "cranelift"]
path = cranelift
url = https://github.com/wasmerio/cranelift.git
fetchrecursesubmodules = true

View File

@ -31,8 +31,8 @@ wasmer run examples/nginx/nginx.wasm -- -p examples/nginx -c nginx.conf
To build this project you will need Rust and Cargo.
```sh
# checkout code and associated submodules
git clone --recursive https://github.com/wasmerio/wasmer.git
# checkout code
git clone https://github.com/wasmerio/wasmer.git
cd wasmer
# install tools

@ -1 +0,0 @@
Subproject commit cb62a1ead2c5346ccb0f1224ecae5939ac064f87

View File

@ -1,7 +1,7 @@
// use std::collections::HashMap;
pub extern "C" fn ___seterrno(value: i32) -> i32 {
debug!("emscripten::___seterrno");
debug!("emscripten::___seterrno {}", value);
// TODO: Incomplete impl
eprintln!("failed to set errno!");
value

View File

@ -7,7 +7,7 @@ pub use libc::putchar;
/// printf
pub extern "C" fn printf(memory_offset: i32, extra: i32, instance: &Instance) -> i32 {
debug!("emscripten::printf");
debug!("emscripten::printf {}, {}", memory_offset, extra);
unsafe {
let addr = instance.memory_offset_addr(0, memory_offset as _) as _;
_printf(addr, extra)

View File

@ -2,11 +2,11 @@ use crate::webassembly::Instance;
use libc::c_int;
// NOTE: Not implemented by Emscripten
pub extern "C" fn ___lock(_which: c_int, _varargs: c_int, _instance: &mut Instance) {
debug!("emscripten::___lock");
pub extern "C" fn ___lock(which: c_int, varargs: c_int, _instance: &mut Instance) {
debug!("emscripten::___lock {}, {}", which, varargs);
}
// NOTE: Not implemented by Emscripten
pub extern "C" fn ___unlock(_which: c_int, _varargs: c_int, _instance: &mut Instance) {
debug!("emscripten::___unlock");
pub extern "C" fn ___unlock(which: c_int, varargs: c_int, _instance: &mut Instance) {
debug!("emscripten::___unlock {}, {}", which, varargs);
}

View File

@ -9,7 +9,10 @@ pub extern "C" fn _emscripten_memcpy_big(
len: u32,
instance: &mut Instance,
) -> u32 {
debug!("emscripten::_emscripten_memcpy_big");
debug!(
"emscripten::_emscripten_memcpy_big {}, {}, {}",
dest, src, len
);
let dest_addr = instance.memory_offset_addr(0, dest as usize) as *mut c_void;
let src_addr = instance.memory_offset_addr(0, src as usize) as *mut c_void;
unsafe {

View File

@ -355,6 +355,11 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
"nullFunc_iiiiii",
ImportValue::Func(nullfunc::nullfunc_iiiiii as _),
);
import_object.set(
"env",
"nullFunc_v",
ImportValue::Func(nullfunc::nullfunc_v as _),
);
import_object.set(
"env",
"nullFunc_vi",

View File

@ -1,47 +1,52 @@
use super::process::abort_with_message;
use crate::webassembly::Instance;
pub extern "C" fn nullfunc_ii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_ii");
pub extern "C" fn nullfunc_ii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_ii {}", x);
abort_with_message("Invalid function pointer called with signature 'ii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_iii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iii");
pub extern "C" fn nullfunc_iii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iii {}", x);
abort_with_message("Invalid function pointer called with signature 'iii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_iiii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iiii");
pub extern "C" fn nullfunc_iiii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iiii {}", x);
abort_with_message("Invalid function pointer called with signature 'iiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_iiiii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iiiii");
pub extern "C" fn nullfunc_iiiii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iiiii {}", x);
abort_with_message("Invalid function pointer called with signature 'iiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_iiiiii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iiiiii");
pub extern "C" fn nullfunc_iiiiii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_iiiiii {}", x);
abort_with_message("Invalid function pointer called with signature 'iiiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_vi(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_vi");
pub extern "C" fn nullfunc_v(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_v {}", x);
abort_with_message("Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_vi(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_vi {}", x);
abort_with_message("Invalid function pointer called with signature 'vi'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_vii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_vii");
pub extern "C" fn nullfunc_vii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_vii {}", x);
abort_with_message("Invalid function pointer called with signature 'vii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_viii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_viii");
pub extern "C" fn nullfunc_viii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_viii {}", x);
abort_with_message("Invalid function pointer called with signature 'viii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}
pub extern "C" fn nullfunc_viiii(_x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_viiii");
pub extern "C" fn nullfunc_viiii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_viiii {}", x);
abort_with_message("Invalid function pointer called with signature 'viiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)");
}

View File

@ -25,12 +25,12 @@ pub extern "C" fn _fork(_instance: &mut Instance) -> pid_t {
}
pub extern "C" fn _exit(status: c_int, _instance: &mut Instance) -> ! {
debug!("emscripten::_exit");
debug!("emscripten::_exit {}", status);
unsafe { exit(status) }
}
pub extern "C" fn em_abort(message: u32, instance: &mut Instance) {
debug!("emscripten::em_abort");
debug!("emscripten::em_abort {}", message);
let message_addr = instance.memory_offset_addr(0, message as usize) as *mut c_char;
unsafe {
let message = CStr::from_ptr(message_addr)

View File

@ -10,18 +10,13 @@ pub extern "C" fn _sigemptyset(set: u32, instance: &mut Instance) -> i32 {
0
}
pub extern "C" fn _sigaction(
_signum: u32,
_act: u32,
_oldact: u32,
_instance: &mut Instance,
) -> i32 {
debug!("emscripten::_sigaction");
pub extern "C" fn _sigaction(signum: u32, act: u32, oldact: u32, _instance: &mut Instance) -> i32 {
debug!("emscripten::_sigaction {}, {}, {}", signum, act, oldact);
0
}
pub extern "C" fn _sigaddset(set: u32, signum: u32, instance: &mut Instance) -> i32 {
debug!("emscripten::_sigaddset");
debug!("emscripten::_sigaddset {}, {}", set, signum);
let set_addr = instance.memory_offset_addr(0, set as _) as *mut u32;
unsafe {
*set_addr |= 1 << (signum - 1);

View File

@ -76,8 +76,8 @@ use libc::SO_NOSIGPIPE;
const SO_NOSIGPIPE: c_int = 0;
/// exit
pub extern "C" fn ___syscall1(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) {
debug!("emscripten::___syscall1 (exit)");
pub extern "C" fn ___syscall1(which: c_int, mut varargs: VarArgs, instance: &mut Instance) {
debug!("emscripten::___syscall1 (exit) {}", which);
let status: i32 = varargs.get(instance);
unsafe {
exit(status);
@ -86,11 +86,11 @@ pub extern "C" fn ___syscall1(_which: c_int, mut varargs: VarArgs, instance: &mu
/// read
pub extern "C" fn ___syscall3(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> ssize_t {
debug!("emscripten::___syscall3 (read)");
debug!("emscripten::___syscall3 (read) {}", which);
let fd: i32 = varargs.get(instance);
let buf: u32 = varargs.get(instance);
let count: usize = varargs.get(instance);
@ -103,11 +103,11 @@ pub extern "C" fn ___syscall3(
/// write
pub extern "C" fn ___syscall4(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall4 (write)");
debug!("emscripten::___syscall4 (write) {}", which);
let fd: i32 = varargs.get(instance);
let buf: u32 = varargs.get(instance);
let count: u32 = varargs.get(instance);
@ -118,11 +118,11 @@ pub extern "C" fn ___syscall4(
/// open
pub extern "C" fn ___syscall5(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall5 (open)");
debug!("emscripten::___syscall5 (open) {}", which);
let pathname: u32 = varargs.get(instance);
let flags: i32 = varargs.get(instance);
let mode: u32 = varargs.get(instance);
@ -138,11 +138,11 @@ pub extern "C" fn ___syscall5(
/// close
pub extern "C" fn ___syscall6(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall6 (close)");
debug!("emscripten::___syscall6 (close) {}", which);
let fd: i32 = varargs.get(instance);
debug!("fd: {}", fd);
unsafe { close(fd) }
@ -150,11 +150,11 @@ pub extern "C" fn ___syscall6(
// chdir
pub extern "C" fn ___syscall12(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall12 (chdir)");
debug!("emscripten::___syscall12 (chdir) {}", which);
let path_addr: i32 = varargs.get(instance);
unsafe {
let path_ptr = instance.memory_offset_addr(0, path_addr as usize) as *const i8;
@ -173,11 +173,11 @@ pub extern "C" fn ___syscall20() -> pid_t {
// mkdir
pub extern "C" fn ___syscall39(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall39 (mkdir)");
debug!("emscripten::___syscall39 (mkdir) {}", which);
let pathname: u32 = varargs.get(instance);
let mode: u32 = varargs.get(instance);
let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8;
@ -194,11 +194,11 @@ pub extern "C" fn ___syscall64() -> pid_t {
/// ioctl
pub extern "C" fn ___syscall54(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall54 (ioctl)");
debug!("emscripten::___syscall54 (ioctl) {}", which);
let fd: i32 = varargs.get(instance);
let request: u32 = varargs.get(instance);
debug!("fd: {}, op: {}", fd, request);
@ -240,11 +240,11 @@ pub extern "C" fn ___syscall54(
// socketcall
pub extern "C" fn ___syscall102(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall102 (socketcall)");
debug!("emscripten::___syscall102 (socketcall) {}", which);
let call: u32 = varargs.get(instance);
let mut socket_varargs: VarArgs = varargs.get(instance);
@ -518,11 +518,11 @@ pub extern "C" fn ___syscall102(
/// uname
// NOTE: Wondering if we should return custom utsname, like Emscripten.
pub extern "C" fn ___syscall122(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall122 (uname)");
debug!("emscripten::___syscall122 (uname) {}", which);
let buf: u32 = varargs.get(instance);
debug!("=> buf: {}", buf);
let buf_addr = instance.memory_offset_addr(0, buf as usize) as *mut utsname;
@ -531,11 +531,11 @@ pub extern "C" fn ___syscall122(
// mmap2
pub extern "C" fn ___syscall192(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall192 (mmap2)");
debug!("emscripten::___syscall192 (mmap2) {}", which);
let addr: i32 = varargs.get(instance);
let len: u32 = varargs.get(instance);
let prot: i32 = varargs.get(instance);
@ -566,11 +566,11 @@ pub extern "C" fn ___syscall192(
/// lseek
pub extern "C" fn ___syscall140(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> off_t {
debug!("emscripten::___syscall140 (lseek)");
debug!("emscripten::___syscall140 (lseek) {}", which);
let fd: i32 = varargs.get(instance);
let offset: i64 = varargs.get(instance);
let whence: i32 = varargs.get(instance);
@ -580,11 +580,11 @@ pub extern "C" fn ___syscall140(
/// readv
pub extern "C" fn ___syscall145(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> ssize_t {
debug!("emscripten::___syscall145 (readv)");
debug!("emscripten::___syscall145 (readv) {}", which);
// let fd: i32 = varargs.get(instance);
// let iov: u32 = varargs.get(instance);
// let iovcnt: i32 = varargs.get(instance);
@ -625,11 +625,11 @@ pub extern "C" fn ___syscall145(
// writev
pub extern "C" fn ___syscall146(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> ssize_t {
debug!("emscripten::___syscall146 (writev)");
debug!("emscripten::___syscall146 (writev) {}", which);
let fd: i32 = varargs.get(instance);
let iov: i32 = varargs.get(instance);
let iovcnt: i32 = varargs.get(instance);
@ -663,11 +663,11 @@ pub extern "C" fn ___syscall146(
// pread
pub extern "C" fn ___syscall180(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall180 (pread)");
debug!("emscripten::___syscall180 (pread) {}", which);
let fd: i32 = varargs.get(instance);
let buf: u32 = varargs.get(instance);
let count: u32 = varargs.get(instance);
@ -684,11 +684,11 @@ pub extern "C" fn ___syscall180(
// pwrite
pub extern "C" fn ___syscall181(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall181 (pwrite)");
debug!("emscripten::___syscall181 (pwrite) {}", which);
let fd: i32 = varargs.get(instance);
let buf: u32 = varargs.get(instance);
let count: u32 = varargs.get(instance);
@ -709,11 +709,11 @@ pub extern "C" fn ___syscall181(
// stat64
pub extern "C" fn ___syscall195(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall195 (stat64)");
debug!("emscripten::___syscall195 (stat64) {}", which);
let pathname: u32 = varargs.get(instance);
let buf: u32 = varargs.get(instance);
@ -733,11 +733,11 @@ pub extern "C" fn ___syscall195(
// fstat64
pub extern "C" fn ___syscall197(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall197 (fstat64)");
debug!("emscripten::___syscall197 (fstat64) {}", which);
let fd: c_int = varargs.get(instance);
let buf: u32 = varargs.get(instance);
@ -783,11 +783,11 @@ pub extern "C" fn ___syscall202() -> gid_t {
// chown
pub extern "C" fn ___syscall212(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall212 (chown)");
debug!("emscripten::___syscall212 (chown) {}", which);
let pathname: u32 = varargs.get(instance);
let owner: u32 = varargs.get(instance);
@ -800,11 +800,11 @@ pub extern "C" fn ___syscall212(
// fcntl64
pub extern "C" fn ___syscall221(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall221 (fcntl64)");
debug!("emscripten::___syscall221 (fcntl64) {}", which);
// fcntl64
let _fd: i32 = varargs.get(instance);
let cmd: u32 = varargs.get(instance);
@ -816,11 +816,11 @@ pub extern "C" fn ___syscall221(
// prlimit64
pub extern "C" fn ___syscall340(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall340 (prlimit64)");
debug!("emscripten::___syscall340 (prlimit64), {}", which);
// NOTE: Doesn't really matter. Wasm modules cannot exceed WASM_PAGE_SIZE anyway.
let _pid: i32 = varargs.get(instance);
let _resource: i32 = varargs.get(instance);
@ -843,11 +843,11 @@ pub extern "C" fn ___syscall340(
// dup2
pub extern "C" fn ___syscall63(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall63 (dup2)");
debug!("emscripten::___syscall63 (dup2) {}", which);
let src: i32 = varargs.get(instance);
let dst: i32 = varargs.get(instance);
@ -857,11 +857,11 @@ pub extern "C" fn ___syscall63(
// select
pub extern "C" fn ___syscall142(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall142 (newselect)");
debug!("emscripten::___syscall142 (newselect) {}", which);
let nfds: i32 = varargs.get(instance);
let readfds: u32 = varargs.get(instance);
@ -880,11 +880,11 @@ pub extern "C" fn ___syscall142(
// setpgid
pub extern "C" fn ___syscall57(
_which: c_int,
which: c_int,
mut varargs: VarArgs,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___syscall57 (setpgid)");
debug!("emscripten::___syscall57 (setpgid) {}", which);
let pid: i32 = varargs.get(instance);
let pgid: i32 = varargs.get(instance);
unsafe { setpgid(pid, pgid) }

View File

@ -119,7 +119,7 @@ pub extern "C" fn _asctime(time: u32, instance: &mut Instance) -> u32 {
/// emscripten: _asctime_r
pub extern "C" fn _asctime_r(time: u32, buf: u32, instance: &mut Instance) -> u32 {
debug!("emscripten::_asctime_r {}", time);
debug!("emscripten::_asctime_r {}, {}", time, buf);
unsafe {
// NOTE: asctime_r is specced to behave in an undefined manner if the algorithm would attempt