Skip to content

Commit

Permalink
Update bin/wasmer and run cargo fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
losfair committed May 16, 2019
1 parent e7297b9 commit 14fcd78
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 44 deletions.
72 changes: 39 additions & 33 deletions lib/middleware-common/src/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions lib/runtime-core/src/backing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use crate::{
},
vm,
};
use std::{
slice,
fmt::Debug,
};
use std::{fmt::Debug, slice};

pub const INTERNALS_SIZE: usize = 256;

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
1 change: 0 additions & 1 deletion lib/singlepass-backend/src/codegen_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lib/singlepass-backend/src/protect_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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()),
Expand Down

0 comments on commit 14fcd78

Please sign in to comment.