Merge branch 'master' into self-update

# Conflicts:
#	src/bin/wasmer.rs
This commit is contained in:
Syrus Akbary
2018-11-27 21:53:33 -08:00
5 changed files with 64 additions and 65 deletions

View File

@ -1,19 +1,5 @@
#[macro_use]
extern crate error_chain;
extern crate cranelift_codegen;
extern crate cranelift_entity;
extern crate cranelift_native;
extern crate cranelift_wasm;
extern crate libc;
extern crate memmap;
extern crate region;
extern crate structopt;
extern crate wabt;
extern crate wasmparser;
#[macro_use]
extern crate target_lexicon;
extern crate nix;
extern crate rayon;
extern crate wasmer;
use std::fs::File;
use std::io;
@ -23,17 +9,7 @@ use std::process::exit;
use structopt::StructOpt;
#[macro_use]
mod macros;
#[macro_use]
mod recovery;
pub mod apis;
pub mod common;
mod update;
pub mod sighandler;
#[cfg(test)]
mod spectests;
pub mod webassembly;
use wasmer::*;
#[derive(Debug, StructOpt)]
#[structopt(name = "wasmer", about = "WASM execution runtime.")]

28
src/lib.rs Normal file
View File

@ -0,0 +1,28 @@
#[macro_use]
extern crate error_chain;
extern crate cranelift_codegen;
extern crate cranelift_entity;
extern crate cranelift_native;
extern crate cranelift_wasm;
extern crate libc;
extern crate memmap;
extern crate region;
extern crate structopt;
extern crate wabt;
extern crate wasmparser;
#[macro_use]
extern crate target_lexicon;
pub extern crate nix; // re-exported for usage in macros
extern crate rayon;
#[macro_use]
mod macros;
#[macro_use]
pub mod recovery;
pub mod apis;
pub mod common;
pub mod sighandler;
#[cfg(test)]
mod spectests;
pub mod webassembly;
pub mod update;

View File

@ -5,9 +5,7 @@
//! unless you have memory unsafety elsewhere in your code.
use std::cell::UnsafeCell;
use nix::sys::signal::{Signal, SIGFPE, SIGILL, SIGSEGV, SIGBUS};
use super::webassembly::ErrorKind;
use super::sighandler::install_sighandler;
use std::sync::Once;
extern "C" {
pub fn setjmp(env: *mut ::nix::libc::c_void) -> ::nix::libc::c_int;
@ -15,6 +13,7 @@ extern "C" {
}
const SETJMP_BUFFER_LEN: usize = 27;
pub static SIGHANDLER_INIT: Once = Once::new();
thread_local! {
pub static SETJMP_BUFFER: UnsafeCell<[::nix::libc::c_int; SETJMP_BUFFER_LEN]> = UnsafeCell::new([0; SETJMP_BUFFER_LEN]);
@ -29,17 +28,20 @@ thread_local! {
/// the behavior of call_protected is undefined.
#[macro_export]
macro_rules! call_protected {
($x:expr) => {unsafe {
use crate::webassembly::ErrorKind;
use crate::recovery::{SETJMP_BUFFER, setjmp};
($x:expr) => {
unsafe {
use crate::recovery::{setjmp, SETJMP_BUFFER, SIGHANDLER_INIT};
use crate::sighandler::install_sighandler;
use crate::webassembly::ErrorKind;
use nix::sys::signal::{Signal, SIGFPE, SIGILL, SIGSEGV, SIGBUS};
use crate::nix::sys::signal::{Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV};
let jmp_buf = SETJMP_BUFFER.with(|buf| buf.get());
let prev_jmp_buf = *jmp_buf;
SIGHANDLER_INIT.call_once(|| {
install_sighandler();
});
let signum = setjmp(jmp_buf as *mut ::nix::libc::c_void);
if signum != 0 {
@ -58,9 +60,9 @@ macro_rules! call_protected {
*jmp_buf = prev_jmp_buf;
Ok(ret)
}
}}
}
};
}
/// Unwinds to last protected_call.
pub unsafe fn do_unwind(signum: i32) -> ! {

View File

@ -12,7 +12,7 @@ use nix::sys::signal::{
pub unsafe fn install_sighandler() {
let sa = SigAction::new(
SigHandler::Handler(signal_trap_handler),
SaFlags::empty(),
SaFlags::SA_ONSTACK,
SigSet::empty(),
);
sigaction(SIGFPE, &sa).unwrap();

View File

@ -22,7 +22,6 @@ use std::slice;
use std::sync::Arc;
use super::super::common::slice::{BoundedSlice, UncheckedSlice};
use super::super::recovery;
use super::errors::ErrorKind;
use super::import_object::{ImportObject, ImportValue};
use super::math_intrinsics;
@ -481,12 +480,7 @@ impl Instance {
tables.iter().map(|table| table[..].into()).collect();
let memories_pointer: Vec<BoundedSlice<u8>> = memories
.iter()
.map(|mem| {
BoundedSlice::new(
&mem[..],
mem.current_size(),
)
})
.map(|mem| BoundedSlice::new(&mem[..], mem.current_size()))
.collect();
let globals_pointer: GlobalsSlice = globals[..].into();
@ -530,8 +524,7 @@ impl Instance {
if let Some(func_index) = self.start_func {
let func: fn(&Instance) = get_instance_function!(&self, func_index);
call_protected!(func(self))
}
else {
} else {
Ok(())
}
}