Update bin/wasmer and run cargo fmt.

This commit is contained in:
losfair 2019-05-17 01:15:05 +08:00
parent e7297b9465
commit 14fcd78b30
6 changed files with 60 additions and 44 deletions

View File

@ -29,52 +29,58 @@ impl FunctionMiddleware for Metering {
match op {
Event::Internal(InternalEvent::FunctionBegin(_)) => {
self.current_block = 0;
},
}
Event::Wasm(&ref op) | Event::WasmOwned(ref op) => {
self.current_block += 1;
match *op {
Operator::Loop { .. }
| Operator::Block { .. }
| Operator::End
| Operator::If { .. }
| Operator::Else
| Operator::Unreachable
| Operator::Br { .. }
| Operator::BrTable { .. }
| Operator::BrIf { .. }
| Operator::Call { .. }
| Operator::CallIndirect { .. }
=> {
sink.push(Event::Internal(InternalEvent::GetInternal(0)));
sink.push(Event::WasmOwned(Operator::I64Const { value: self.current_block as i64 }));
sink.push(Event::WasmOwned(Operator::I64Add));
sink.push(Event::Internal(InternalEvent::SetInternal(0)));
self.current_block = 0;
},
| Operator::Block { .. }
| Operator::End
| Operator::If { .. }
| Operator::Else
| Operator::Unreachable
| Operator::Br { .. }
| Operator::BrTable { .. }
| Operator::BrIf { .. }
| Operator::Call { .. }
| Operator::CallIndirect { .. } => {
sink.push(Event::Internal(InternalEvent::GetInternal(0)));
sink.push(Event::WasmOwned(Operator::I64Const {
value: self.current_block as i64,
}));
sink.push(Event::WasmOwned(Operator::I64Add));
sink.push(Event::Internal(InternalEvent::SetInternal(0)));
self.current_block = 0;
}
_ => {}
}
match *op {
Operator::Br { .. }
| Operator::BrTable { .. }
| Operator::BrIf { .. }
| Operator::Call { .. }
| Operator::CallIndirect { .. }
=> {
sink.push(Event::Internal(InternalEvent::GetInternal(0)));
sink.push(Event::WasmOwned(Operator::I64Const { value: self.limit as i64 }));
sink.push(Event::WasmOwned(Operator::I64GeU));
sink.push(Event::WasmOwned(Operator::If { ty: WpType::EmptyBlockType }));
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(move |ctx| {
Operator::Br { .. }
| Operator::BrTable { .. }
| Operator::BrIf { .. }
| Operator::Call { .. }
| Operator::CallIndirect { .. } => {
sink.push(Event::Internal(InternalEvent::GetInternal(0)));
sink.push(Event::WasmOwned(Operator::I64Const {
value: self.limit as i64,
}));
sink.push(Event::WasmOwned(Operator::I64GeU));
sink.push(Event::WasmOwned(Operator::If {
ty: WpType::EmptyBlockType,
}));
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(
move |ctx| {
eprintln!("execution limit reached");
unsafe {
(ctx.throw)();
}
}))));
sink.push(Event::WasmOwned(Operator::End));
},
},
))));
sink.push(Event::WasmOwned(Operator::End));
}
_ => {}
}
},
}
_ => {}
}
sink.push(op);

View File

@ -15,10 +15,7 @@ use crate::{
},
vm,
};
use std::{
slice,
fmt::Debug,
};
use std::{fmt::Debug, slice};
pub const INTERNALS_SIZE: usize = 256;

View File

@ -41,7 +41,7 @@ impl fmt::Debug for InternalEvent {
}
pub struct BkptInfo {
pub throw: unsafe extern "C" fn () -> !,
pub throw: unsafe extern "C" fn() -> !,
}
pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, RM: RunnableModule, E: Debug> {

View File

@ -1494,7 +1494,6 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
let a = self.assembler.as_mut().unwrap();
let op = match ev {
Event::Wasm(x) => x,
Event::WasmOwned(ref x) => x,

View File

@ -35,9 +35,7 @@ extern "C" fn signal_trap_handler(
let bkpt_map = BKPT_MAP.with(|x| x.borrow().last().map(|x| x.clone()));
if let Some(bkpt_map) = bkpt_map {
if let Some(ref x) = bkpt_map.get(&(ip as usize)) {
(x)(BkptInfo {
throw: throw,
});
(x)(BkptInfo { throw: throw });
return;
}
}

View File

@ -17,18 +17,22 @@ use wasmer::*;
use wasmer_clif_backend::CraneliftCompiler;
#[cfg(feature = "backend:llvm")]
use wasmer_llvm_backend::LLVMCompiler;
#[cfg(feature = "backend:singlepass")]
use wasmer_middleware_common::metering::Metering;
use wasmer_runtime::{
cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH},
error::RuntimeError,
Func, Value,
};
#[cfg(feature = "backend:singlepass")]
use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
use wasmer_runtime_core::{
self,
backend::{Compiler, CompilerConfig, MemoryBoundCheckMode},
loader::{Instance as LoadedInstance, LocalLoader},
};
#[cfg(feature = "backend:singlepass")]
use wasmer_singlepass_backend::SinglePassCompiler;
use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG;
#[cfg(feature = "wasi")]
use wasmer_wasi;
@ -110,6 +114,9 @@ struct Run {
/// Application arguments
#[structopt(name = "--", raw(multiple = "true"))]
args: Vec<String>,
#[structopt(long = "inst-limit")]
instruction_limit: Option<u64>,
}
#[allow(dead_code)]
@ -286,7 +293,16 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
let compiler: Box<dyn Compiler> = match options.backend {
#[cfg(feature = "backend:singlepass")]
Backend::Singlepass => Box::new(SinglePassCompiler::new()),
Backend::Singlepass => {
let c: StreamingCompiler<SinglePassMCG, _, _, _, _> = StreamingCompiler::new(|| {
let mut chain = MiddlewareChain::new();
if let Some(limit) = options.instruction_limit {
chain.push(Metering::new(limit));
}
chain
});
Box::new(c)
}
#[cfg(not(feature = "backend:singlepass"))]
Backend::Singlepass => return Err("The singlepass backend is not enabled".to_string()),
Backend::Cranelift => Box::new(CraneliftCompiler::new()),