Bkpt* -> Breakpoint*

This commit is contained in:
losfair
2019-07-04 01:45:06 +08:00
parent 7f28a4dbef
commit f32b22d571
6 changed files with 18 additions and 18 deletions

View File

@ -9,7 +9,7 @@ use crate::{
use crate::{ use crate::{
cache::{Artifact, Error as CacheError}, cache::{Artifact, Error as CacheError},
codegen::BkptMap, codegen::BreakpointMap,
module::ModuleInfo, module::ModuleInfo,
sys::Memory, sys::Memory,
}; };
@ -90,7 +90,7 @@ pub trait RunnableModule: Send + Sync {
None None
} }
fn get_breakpoints(&self) -> Option<BkptMap> { fn get_breakpoints(&self) -> Option<BreakpointMap> {
None None
} }

View File

@ -17,8 +17,8 @@ use std::sync::{Arc, RwLock};
use wasmparser::{self, WasmDecoder}; use wasmparser::{self, WasmDecoder};
use wasmparser::{Operator, Type as WpType}; use wasmparser::{Operator, Type as WpType};
pub type BkptHandler = Box<Fn(BkptInfo) -> Result<(), Box<dyn Any>> + Send + Sync + 'static>; pub type BreakpointHandler = Box<Fn(BreakpointInfo) -> Result<(), Box<dyn Any>> + Send + Sync + 'static>;
pub type BkptMap = Arc<HashMap<usize, BkptHandler>>; pub type BreakpointMap = Arc<HashMap<usize, BreakpointHandler>>;
#[derive(Debug)] #[derive(Debug)]
pub enum Event<'a, 'b> { pub enum Event<'a, 'b> {
@ -30,7 +30,7 @@ pub enum Event<'a, 'b> {
pub enum InternalEvent { pub enum InternalEvent {
FunctionBegin(u32), FunctionBegin(u32),
FunctionEnd, FunctionEnd,
Breakpoint(BkptHandler), Breakpoint(BreakpointHandler),
SetInternal(u32), SetInternal(u32),
GetInternal(u32), GetInternal(u32),
} }
@ -47,7 +47,7 @@ impl fmt::Debug for InternalEvent {
} }
} }
pub struct BkptInfo<'a> { pub struct BreakpointInfo<'a> {
pub fault: Option<&'a dyn Any>, pub fault: Option<&'a dyn Any>,
} }

View File

@ -8,7 +8,7 @@ mod raw {
} }
} }
use crate::codegen::{BkptInfo, BkptMap}; use crate::codegen::{BreakpointInfo, BreakpointMap};
use crate::state::x64::{build_instance_image, read_stack, X64Register, GPR, XMM}; use crate::state::x64::{build_instance_image, read_stack, X64Register, GPR, XMM};
use crate::vm; use crate::vm;
use libc::{mmap, mprotect, siginfo_t, MAP_ANON, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE}; use libc::{mmap, mprotect, siginfo_t, MAP_ANON, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE};
@ -34,7 +34,7 @@ type SetJmpBuffer = [i32; SETJMP_BUFFER_LEN];
struct UnwindInfo { struct UnwindInfo {
jmpbuf: SetJmpBuffer, // in jmpbuf: SetJmpBuffer, // in
breakpoints: Option<BkptMap>, breakpoints: Option<BreakpointMap>,
payload: Option<Box<Any>>, // out payload: Option<Box<Any>>, // out
} }
@ -88,7 +88,7 @@ pub unsafe fn clear_wasm_interrupt() {
pub unsafe fn catch_unsafe_unwind<R, F: FnOnce() -> R>( pub unsafe fn catch_unsafe_unwind<R, F: FnOnce() -> R>(
f: F, f: F,
breakpoints: Option<BkptMap>, breakpoints: Option<BreakpointMap>,
) -> Result<R, Box<Any>> { ) -> Result<R, Box<Any>> {
let unwind = UNWIND.with(|x| x.get()); let unwind = UNWIND.with(|x| x.get());
let old = (*unwind).take(); let old = (*unwind).take();
@ -120,7 +120,7 @@ pub unsafe fn begin_unsafe_unwind(e: Box<Any>) -> ! {
raw::longjmp(&mut inner.jmpbuf as *mut SetJmpBuffer as *mut _, 0xffff); raw::longjmp(&mut inner.jmpbuf as *mut SetJmpBuffer as *mut _, 0xffff);
} }
unsafe fn with_breakpoint_map<R, F: FnOnce(Option<&BkptMap>) -> R>(f: F) -> R { unsafe fn with_breakpoint_map<R, F: FnOnce(Option<&BreakpointMap>) -> R>(f: F) -> R {
let unwind = UNWIND.with(|x| x.get()); let unwind = UNWIND.with(|x| x.get());
let inner = (*unwind) let inner = (*unwind)
.as_mut() .as_mut()
@ -183,7 +183,7 @@ extern "C" fn signal_trap_handler(
// breakpoint // breakpoint
let out: Option<Result<(), Box<dyn Any>>> = with_breakpoint_map(|bkpt_map| { let out: Option<Result<(), Box<dyn Any>>> = with_breakpoint_map(|bkpt_map| {
bkpt_map.and_then(|x| x.get(&(fault.ip as usize))).map(|x| { bkpt_map.and_then(|x| x.get(&(fault.ip as usize))).map(|x| {
x(BkptInfo { x(BreakpointInfo {
fault: Some(&fault), fault: Some(&fault),
}) })
}) })

View File

@ -360,7 +360,7 @@ impl InstanceImage {
pub mod x64 { pub mod x64 {
use super::*; use super::*;
use crate::fault::{catch_unsafe_unwind, run_on_alternative_stack}; use crate::fault::{catch_unsafe_unwind, run_on_alternative_stack};
use crate::codegen::BkptMap; use crate::codegen::BreakpointMap;
use crate::structures::TypedIndex; use crate::structures::TypedIndex;
use crate::types::LocalGlobalIndex; use crate::types::LocalGlobalIndex;
use crate::vm::Ctx; use crate::vm::Ctx;
@ -382,7 +382,7 @@ pub mod x64 {
code_base: usize, code_base: usize,
image: InstanceImage, image: InstanceImage,
vmctx: &mut Ctx, vmctx: &mut Ctx,
breakpoints: Option<BkptMap>, breakpoints: Option<BreakpointMap>,
) -> Result<u64, Box<dyn Any>> { ) -> Result<u64, Box<dyn Any>> {
let mut stack: Vec<u64> = vec![0; 1048576 * 8 / 8]; // 8MB stack let mut stack: Vec<u64> = vec![0; 1048576 * 8 / 8]; // 8MB stack
let mut stack_offset: usize = stack.len(); let mut stack_offset: usize = stack.len();

View File

@ -148,7 +148,7 @@ pub struct X64FunctionCode {
breakpoints: Option< breakpoints: Option<
HashMap< HashMap<
AssemblyOffset, AssemblyOffset,
Box<Fn(BkptInfo) -> Result<(), Box<dyn Any>> + Send + Sync + 'static>, Box<Fn(BreakpointInfo) -> Result<(), Box<dyn Any>> + Send + Sync + 'static>,
>, >,
>, >,
returns: SmallVec<[WpType; 1]>, returns: SmallVec<[WpType; 1]>,
@ -178,7 +178,7 @@ pub struct X64ExecutionContext {
function_pointers: Vec<FuncPtr>, function_pointers: Vec<FuncPtr>,
function_offsets: Vec<AssemblyOffset>, function_offsets: Vec<AssemblyOffset>,
signatures: Arc<Map<SigIndex, FuncSig>>, signatures: Arc<Map<SigIndex, FuncSig>>,
breakpoints: BkptMap, breakpoints: BreakpointMap,
func_import_count: usize, func_import_count: usize,
msm: ModuleStateMap, msm: ModuleStateMap,
} }
@ -216,7 +216,7 @@ impl RunnableModule for X64ExecutionContext {
Some(self.msm.clone()) Some(self.msm.clone())
} }
fn get_breakpoints(&self) -> Option<BkptMap> { fn get_breakpoints(&self) -> Option<BreakpointMap> {
Some(self.breakpoints.clone()) Some(self.breakpoints.clone())
} }

View File

@ -14,7 +14,7 @@ use std::cell::Cell;
use wasmer_runtime_core::fault::{ use wasmer_runtime_core::fault::{
begin_unsafe_unwind, catch_unsafe_unwind, ensure_sighandler, begin_unsafe_unwind, catch_unsafe_unwind, ensure_sighandler,
}; };
use wasmer_runtime_core::codegen::BkptMap; use wasmer_runtime_core::codegen::BreakpointMap;
use wasmer_runtime_core::typed_func::WasmTrapInfo; use wasmer_runtime_core::typed_func::WasmTrapInfo;
thread_local! { thread_local! {
@ -32,7 +32,7 @@ pub enum CallProtError {
pub fn call_protected<T>( pub fn call_protected<T>(
f: impl FnOnce() -> T, f: impl FnOnce() -> T,
breakpoints: Option<BkptMap>, breakpoints: Option<BreakpointMap>,
) -> Result<T, CallProtError> { ) -> Result<T, CallProtError> {
ensure_sighandler(); ensure_sighandler();
unsafe { unsafe {