Cargo fmt

This commit is contained in:
losfair
2019-06-25 03:56:20 +08:00
parent 988b2c5748
commit 8303853227
4 changed files with 122 additions and 56 deletions

View File

@ -540,7 +540,12 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
}
impl X64FunctionCode {
fn mark_trappable(a: &mut Assembler, m: &Machine, fsm: &mut FunctionStateMap, control_stack: &mut [ControlFrame]) {
fn mark_trappable(
a: &mut Assembler,
m: &Machine,
fsm: &mut FunctionStateMap,
control_stack: &mut [ControlFrame],
) {
let state_diff_id = Self::get_state_diff(m, fsm, control_stack);
let offset = a.get_offset().0;
fsm.trappable_offsets.insert(offset, state_diff_id);
@ -1607,7 +1612,14 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
.machine
.init_locals(a, self.num_locals, self.num_params);
self.fsm = FunctionStateMap::new(new_machine_state(), self.local_function_id, 32, (0..self.locals.len()).map(|_| WasmAbstractValue::Runtime).collect());
self.fsm = FunctionStateMap::new(
new_machine_state(),
self.local_function_id,
32,
(0..self.locals.len())
.map(|_| WasmAbstractValue::Runtime)
.collect(),
);
let diff = self.machine.state.diff(&new_machine_state());
let state_diff_id = self.fsm.diffs.len();
@ -1869,7 +1881,10 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
let local_index = local_index as usize;
self.value_stack
.push((self.locals[local_index], LocalOrTemp::Local));
self.machine.state.wasm_stack.push(WasmAbstractValue::Runtime);
self.machine
.state
.wasm_stack
.push(WasmAbstractValue::Runtime);
}
Operator::SetLocal { local_index } => {
let local_index = local_index as usize;
@ -1899,11 +1914,13 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
);
}
Operator::I32Const { value } => {
self
.value_stack
.push((Location::Imm32(value as u32), LocalOrTemp::Temp));
self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value as u32 as u64));
},
self.value_stack
.push((Location::Imm32(value as u32), LocalOrTemp::Temp));
self.machine
.state
.wasm_stack
.push(WasmAbstractValue::Const(value as u32 as u64));
}
Operator::I32Add => Self::emit_binop_i32(
a,
&mut self.machine,
@ -2184,7 +2201,10 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
let value = value as u64;
self.value_stack
.push((Location::Imm64(value), LocalOrTemp::Temp));
self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value));
self.machine
.state
.wasm_stack
.push(WasmAbstractValue::Const(value));
}
Operator::I64Add => Self::emit_binop_i64(
a,
@ -2519,11 +2539,13 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
}
Operator::F32Const { value } => {
self
.value_stack
.push((Location::Imm32(value.bits()), LocalOrTemp::Temp));
self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value.bits() as u64));
},
self.value_stack
.push((Location::Imm32(value.bits()), LocalOrTemp::Temp));
self.machine
.state
.wasm_stack
.push(WasmAbstractValue::Const(value.bits() as u64));
}
Operator::F32Add => Self::emit_fp_binop_avx(
a,
&mut self.machine,
@ -2696,11 +2718,13 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
}
Operator::F64Const { value } => {
self
.value_stack
.push((Location::Imm64(value.bits()), LocalOrTemp::Temp));
self.machine.state.wasm_stack.push(WasmAbstractValue::Const(value.bits()));
},
self.value_stack
.push((Location::Imm64(value.bits()), LocalOrTemp::Temp));
self.machine
.state
.wasm_stack
.push(WasmAbstractValue::Const(value.bits()));
}
Operator::F64Add => Self::emit_fp_binop_avx(
a,
&mut self.machine,
@ -4591,7 +4615,8 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
);
}
Operator::Unreachable => {
let state_diff_id = Self::get_state_diff(&self.machine, &mut self.fsm, &mut self.control_stack);
let state_diff_id =
Self::get_state_diff(&self.machine, &mut self.fsm, &mut self.control_stack);
let offset = a.get_offset().0;
self.fsm.trappable_offsets.insert(offset, state_diff_id);

View File

@ -277,10 +277,7 @@ impl Machine {
}
}
pub fn release_locations_only_osr_state(
&mut self,
n: usize,
) {
pub fn release_locations_only_osr_state(&mut self, n: usize) {
for _ in 0..n {
self.state.wasm_stack.pop().unwrap();
}

View File

@ -21,8 +21,8 @@ use std::ptr;
use std::sync::Arc;
use std::sync::Once;
use wasmer_runtime_core::codegen::BkptInfo;
use wasmer_runtime_core::state::x64::{read_stack, X64Register, GPR};
use wasmer_runtime_core::typed_func::WasmTrapInfo;
use wasmer_runtime_core::state::x64::{X64Register, GPR, read_stack};
use wasmer_runtime_core::vm;
fn join_strings(x: impl Iterator<Item = String>, sep: &str) -> String {
@ -47,12 +47,19 @@ fn format_optional_u64_sequence(x: &[Option<u64>]) -> String {
if x.len() == 0 {
"(empty)".into()
} else {
join_strings(x.iter()
.enumerate()
.map(|(i, x)| {
format!("[{}] = {}", i, x.map(|x| format!("{}", x)).unwrap_or_else(|| "?".to_string()).bold().cyan())
})
, ", ")
join_strings(
x.iter().enumerate().map(|(i, x)| {
format!(
"[{}] = {}",
i,
x.map(|x| format!("{}", x))
.unwrap_or_else(|| "?".to_string())
.bold()
.cyan()
)
}),
", ",
)
}
}
@ -78,7 +85,8 @@ extern "C" fn signal_trap_handler(
}
// TODO: make this safer
let ctx = &*(fault.known_registers[X64Register::GPR(GPR::R15).to_index().0].unwrap() as *mut vm::Ctx);
let ctx = &*(fault.known_registers[X64Register::GPR(GPR::R15).to_index().0].unwrap()
as *mut vm::Ctx);
let rsp = fault.known_registers[X64Register::GPR(GPR::RSP).to_index().0].unwrap();
let msm = (*ctx.module)
@ -86,19 +94,41 @@ extern "C" fn signal_trap_handler(
.get_module_state_map()
.unwrap();
let code_base = (*ctx.module).runnable_module.get_code().unwrap().as_ptr() as usize;
let frames = self::read_stack(&msm, code_base, rsp as usize as *const u64, fault.known_registers, Some(fault.ip as usize as u64));
let frames = self::read_stack(
&msm,
code_base,
rsp as usize as *const u64,
fault.known_registers,
Some(fault.ip as usize as u64),
);
use colored::*;
eprintln!("\n{}\n", "Wasmer encountered an error while running your WebAssembly program.".bold().red());
eprintln!(
"\n{}\n",
"Wasmer encountered an error while running your WebAssembly program."
.bold()
.red()
);
if frames.len() == 0 {
eprintln!("{}", "Unknown fault address, cannot read stack.".yellow());
} else {
use colored::*;
eprintln!("{}\n", "Backtrace:".bold());
for (i, f) in frames.iter().enumerate() {
eprintln!("{}", format!("* Frame {} @ Local function {}", i, f.local_function_id).bold());
eprintln!(" {} {}", "Locals:".bold().yellow(), format_optional_u64_sequence(&f.locals));
eprintln!(" {} {}", "Stack:".bold().yellow(), format_optional_u64_sequence(&f.stack));
eprintln!(
"{}",
format!("* Frame {} @ Local function {}", i, f.local_function_id).bold()
);
eprintln!(
" {} {}",
"Locals:".bold().yellow(),
format_optional_u64_sequence(&f.locals)
);
eprintln!(
" {} {}",
"Stack:".bold().yellow(),
format_optional_u64_sequence(&f.stack)
);
eprintln!("");
}
}
@ -246,10 +276,7 @@ unsafe fn get_faulting_addr_and_ip(
}
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
unsafe fn get_fault_info(
siginfo: *const c_void,
ucontext: *const c_void,
) -> FaultInfo {
unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *const c_void) -> FaultInfo {
#[allow(dead_code)]
#[repr(C)]
struct ucontext_t {