mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-21 04:31:33 +00:00
Run cargo fmt.
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
//! The error module contains the data structures and helper functions used to implement errors that
|
//! The error module contains the data structures and helper functions used to implement errors that
|
||||||
//! are produced and returned from the wasmer runtime core.
|
//! are produced and returned from the wasmer runtime core.
|
||||||
use crate::types::{FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type};
|
|
||||||
use crate::backend::ExceptionCode;
|
use crate::backend::ExceptionCode;
|
||||||
|
use crate::types::{FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type};
|
||||||
use core::borrow::Borrow;
|
use core::borrow::Borrow;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
|
@ -23,9 +23,8 @@ use std::{
|
|||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
backend::{
|
backend::{
|
||||||
sys::{Memory, Protect},
|
sys::{Memory, Protect},
|
||||||
Architecture, Backend, CacheGen, CompilerConfig, InlineBreakpoint, InlineBreakpointType,
|
Architecture, Backend, CacheGen, CompilerConfig, ExceptionCode, ExceptionTable,
|
||||||
MemoryBoundCheckMode, RunnableModule, Token,
|
InlineBreakpoint, InlineBreakpointType, MemoryBoundCheckMode, RunnableModule, Token,
|
||||||
ExceptionTable, ExceptionCode,
|
|
||||||
},
|
},
|
||||||
cache::{Artifact, Error as CacheError},
|
cache::{Artifact, Error as CacheError},
|
||||||
codegen::*,
|
codegen::*,
|
||||||
@ -673,20 +672,21 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
|
|||||||
&mut self,
|
&mut self,
|
||||||
_module_info: Arc<RwLock<ModuleInfo>>,
|
_module_info: Arc<RwLock<ModuleInfo>>,
|
||||||
) -> Result<&mut X64FunctionCode, CodegenError> {
|
) -> Result<&mut X64FunctionCode, CodegenError> {
|
||||||
let (mut assembler, mut function_labels, breakpoints, exception_table) = match self.functions.last_mut() {
|
let (mut assembler, mut function_labels, breakpoints, exception_table) =
|
||||||
Some(x) => (
|
match self.functions.last_mut() {
|
||||||
x.assembler.take().unwrap(),
|
Some(x) => (
|
||||||
x.function_labels.take().unwrap(),
|
x.assembler.take().unwrap(),
|
||||||
x.breakpoints.take().unwrap(),
|
x.function_labels.take().unwrap(),
|
||||||
x.exception_table.take().unwrap(),
|
x.breakpoints.take().unwrap(),
|
||||||
),
|
x.exception_table.take().unwrap(),
|
||||||
None => (
|
),
|
||||||
self.assembler.take().unwrap(),
|
None => (
|
||||||
self.function_labels.take().unwrap(),
|
self.assembler.take().unwrap(),
|
||||||
HashMap::new(),
|
self.function_labels.take().unwrap(),
|
||||||
ExceptionTable::new(),
|
HashMap::new(),
|
||||||
),
|
ExceptionTable::new(),
|
||||||
};
|
),
|
||||||
|
};
|
||||||
|
|
||||||
let begin_offset = assembler.offset();
|
let begin_offset = assembler.offset();
|
||||||
let begin_label_info = function_labels
|
let begin_label_info = function_labels
|
||||||
@ -730,20 +730,21 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
|
|||||||
mut self,
|
mut self,
|
||||||
_: &ModuleInfo,
|
_: &ModuleInfo,
|
||||||
) -> Result<(X64ExecutionContext, Box<dyn CacheGen>), CodegenError> {
|
) -> Result<(X64ExecutionContext, Box<dyn CacheGen>), CodegenError> {
|
||||||
let (assembler, function_labels, breakpoints, exception_table) = match self.functions.last_mut() {
|
let (assembler, function_labels, breakpoints, exception_table) =
|
||||||
Some(x) => (
|
match self.functions.last_mut() {
|
||||||
x.assembler.take().unwrap(),
|
Some(x) => (
|
||||||
x.function_labels.take().unwrap(),
|
x.assembler.take().unwrap(),
|
||||||
x.breakpoints.take().unwrap(),
|
x.function_labels.take().unwrap(),
|
||||||
x.exception_table.take().unwrap(),
|
x.breakpoints.take().unwrap(),
|
||||||
),
|
x.exception_table.take().unwrap(),
|
||||||
None => (
|
),
|
||||||
self.assembler.take().unwrap(),
|
None => (
|
||||||
self.function_labels.take().unwrap(),
|
self.assembler.take().unwrap(),
|
||||||
HashMap::new(),
|
self.function_labels.take().unwrap(),
|
||||||
ExceptionTable::new(),
|
HashMap::new(),
|
||||||
),
|
ExceptionTable::new(),
|
||||||
};
|
),
|
||||||
|
};
|
||||||
|
|
||||||
let total_size = assembler.get_offset().0;
|
let total_size = assembler.get_offset().0;
|
||||||
let _output = assembler.finalize().unwrap();
|
let _output = assembler.finalize().unwrap();
|
||||||
@ -967,7 +968,12 @@ impl X64FunctionCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Marks each address in the code range emitted by `f` with the exception code `code`.
|
/// Marks each address in the code range emitted by `f` with the exception code `code`.
|
||||||
fn mark_range_with_exception_code<F: FnOnce(&mut Assembler) -> R, R>(a: &mut Assembler, etable: &mut ExceptionTable, code: ExceptionCode, f: F) -> R {
|
fn mark_range_with_exception_code<F: FnOnce(&mut Assembler) -> R, R>(
|
||||||
|
a: &mut Assembler,
|
||||||
|
etable: &mut ExceptionTable,
|
||||||
|
code: ExceptionCode,
|
||||||
|
f: F,
|
||||||
|
) -> R {
|
||||||
let begin = a.get_offset().0;
|
let begin = a.get_offset().0;
|
||||||
let ret = f(a);
|
let ret = f(a);
|
||||||
let end = a.get_offset().0;
|
let end = a.get_offset().0;
|
||||||
@ -993,12 +999,16 @@ impl X64FunctionCode {
|
|||||||
Location::Imm64(_) | Location::Imm32(_) => {
|
Location::Imm64(_) | Location::Imm32(_) => {
|
||||||
a.emit_mov(sz, loc, Location::GPR(GPR::RCX)); // must not be used during div (rax, rdx)
|
a.emit_mov(sz, loc, Location::GPR(GPR::RCX)); // must not be used during div (rax, rdx)
|
||||||
Self::mark_trappable(a, m, fsm, control_stack);
|
Self::mark_trappable(a, m, fsm, control_stack);
|
||||||
etable.offset_to_code.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
etable
|
||||||
|
.offset_to_code
|
||||||
|
.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
||||||
op(a, sz, Location::GPR(GPR::RCX));
|
op(a, sz, Location::GPR(GPR::RCX));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Self::mark_trappable(a, m, fsm, control_stack);
|
Self::mark_trappable(a, m, fsm, control_stack);
|
||||||
etable.offset_to_code.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
etable
|
||||||
|
.offset_to_code
|
||||||
|
.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
||||||
op(a, sz, loc);
|
op(a, sz, loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1984,7 +1994,9 @@ impl X64FunctionCode {
|
|||||||
a.emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_addr));
|
a.emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_addr));
|
||||||
a.emit_cmp(Size::S64, Location::GPR(tmp_bound), Location::GPR(tmp_addr));
|
a.emit_cmp(Size::S64, Location::GPR(tmp_bound), Location::GPR(tmp_addr));
|
||||||
|
|
||||||
Self::mark_range_with_exception_code(a, etable, ExceptionCode::Memory, |a| a.emit_conditional_trap(Condition::Above));
|
Self::mark_range_with_exception_code(a, etable, ExceptionCode::Memory, |a| {
|
||||||
|
a.emit_conditional_trap(Condition::Above)
|
||||||
|
});
|
||||||
|
|
||||||
m.release_temp_gpr(tmp_bound);
|
m.release_temp_gpr(tmp_bound);
|
||||||
}
|
}
|
||||||
@ -2024,7 +2036,9 @@ impl X64FunctionCode {
|
|||||||
Location::Imm32(align - 1),
|
Location::Imm32(align - 1),
|
||||||
Location::GPR(tmp_aligncheck),
|
Location::GPR(tmp_aligncheck),
|
||||||
);
|
);
|
||||||
Self::mark_range_with_exception_code(a, etable, ExceptionCode::Memory, |a| a.emit_conditional_trap(Condition::NotEqual));
|
Self::mark_range_with_exception_code(a, etable, ExceptionCode::Memory, |a| {
|
||||||
|
a.emit_conditional_trap(Condition::NotEqual)
|
||||||
|
});
|
||||||
m.release_temp_gpr(tmp_aligncheck);
|
m.release_temp_gpr(tmp_aligncheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2157,7 +2171,9 @@ impl X64FunctionCode {
|
|||||||
|
|
||||||
Self::emit_f32_int_conv_check(a, m, reg, lower_bound, upper_bound, trap, trap, trap, end);
|
Self::emit_f32_int_conv_check(a, m, reg, lower_bound, upper_bound, trap, trap, trap, end);
|
||||||
a.emit_label(trap);
|
a.emit_label(trap);
|
||||||
etable.offset_to_code.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
etable
|
||||||
|
.offset_to_code
|
||||||
|
.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
||||||
a.emit_ud2();
|
a.emit_ud2();
|
||||||
a.emit_label(end);
|
a.emit_label(end);
|
||||||
}
|
}
|
||||||
@ -2283,7 +2299,9 @@ impl X64FunctionCode {
|
|||||||
|
|
||||||
Self::emit_f64_int_conv_check(a, m, reg, lower_bound, upper_bound, trap, trap, trap, end);
|
Self::emit_f64_int_conv_check(a, m, reg, lower_bound, upper_bound, trap, trap, trap, end);
|
||||||
a.emit_label(trap);
|
a.emit_label(trap);
|
||||||
etable.offset_to_code.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
etable
|
||||||
|
.offset_to_code
|
||||||
|
.insert(a.get_offset().0, ExceptionCode::Arithmetic);
|
||||||
a.emit_ud2();
|
a.emit_ud2();
|
||||||
a.emit_label(end);
|
a.emit_label(end);
|
||||||
}
|
}
|
||||||
@ -2408,7 +2426,12 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
|
|||||||
),
|
),
|
||||||
Location::GPR(GPR::RSP),
|
Location::GPR(GPR::RSP),
|
||||||
);
|
);
|
||||||
Self::mark_range_with_exception_code(a, self.exception_table.as_mut().unwrap(), ExceptionCode::Memory, |a| a.emit_conditional_trap(Condition::Below));
|
Self::mark_range_with_exception_code(
|
||||||
|
a,
|
||||||
|
self.exception_table.as_mut().unwrap(),
|
||||||
|
ExceptionCode::Memory,
|
||||||
|
|a| a.emit_conditional_trap(Condition::Below),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.locals = self
|
self.locals = self
|
||||||
@ -6269,7 +6292,12 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
|
|||||||
Location::GPR(table_base),
|
Location::GPR(table_base),
|
||||||
);
|
);
|
||||||
a.emit_cmp(Size::S32, func_index, Location::GPR(table_count));
|
a.emit_cmp(Size::S32, func_index, Location::GPR(table_count));
|
||||||
Self::mark_range_with_exception_code(a, self.exception_table.as_mut().unwrap(), ExceptionCode::Memory, |a| a.emit_conditional_trap(Condition::BelowEqual));
|
Self::mark_range_with_exception_code(
|
||||||
|
a,
|
||||||
|
self.exception_table.as_mut().unwrap(),
|
||||||
|
ExceptionCode::Memory,
|
||||||
|
|a| a.emit_conditional_trap(Condition::BelowEqual),
|
||||||
|
);
|
||||||
a.emit_mov(Size::S64, func_index, Location::GPR(table_count));
|
a.emit_mov(Size::S64, func_index, Location::GPR(table_count));
|
||||||
a.emit_imul_imm32_gpr64(vm::Anyfunc::size() as u32, table_count);
|
a.emit_imul_imm32_gpr64(vm::Anyfunc::size() as u32, table_count);
|
||||||
a.emit_add(
|
a.emit_add(
|
||||||
@ -6295,7 +6323,12 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
|
|||||||
Location::GPR(sigidx),
|
Location::GPR(sigidx),
|
||||||
Location::Memory(table_count, (vm::Anyfunc::offset_sig_id() as usize) as i32),
|
Location::Memory(table_count, (vm::Anyfunc::offset_sig_id() as usize) as i32),
|
||||||
);
|
);
|
||||||
Self::mark_range_with_exception_code(a, self.exception_table.as_mut().unwrap(), ExceptionCode::Memory, |a| a.emit_conditional_trap(Condition::NotEqual));
|
Self::mark_range_with_exception_code(
|
||||||
|
a,
|
||||||
|
self.exception_table.as_mut().unwrap(),
|
||||||
|
ExceptionCode::Memory,
|
||||||
|
|a| a.emit_conditional_trap(Condition::NotEqual),
|
||||||
|
);
|
||||||
|
|
||||||
self.machine.release_temp_gpr(sigidx);
|
self.machine.release_temp_gpr(sigidx);
|
||||||
self.machine.release_temp_gpr(table_count);
|
self.machine.release_temp_gpr(table_count);
|
||||||
@ -7380,7 +7413,11 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
|
|||||||
}
|
}
|
||||||
Operator::Unreachable => {
|
Operator::Unreachable => {
|
||||||
Self::mark_trappable(a, &self.machine, &mut self.fsm, &mut self.control_stack);
|
Self::mark_trappable(a, &self.machine, &mut self.fsm, &mut self.control_stack);
|
||||||
self.exception_table.as_mut().unwrap().offset_to_code.insert(a.get_offset().0, ExceptionCode::Unreachable);
|
self.exception_table
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.offset_to_code
|
||||||
|
.insert(a.get_offset().0, ExceptionCode::Unreachable);
|
||||||
a.emit_ud2();
|
a.emit_ud2();
|
||||||
self.unreachable_depth = 1;
|
self.unreachable_depth = 1;
|
||||||
}
|
}
|
||||||
|
@ -849,18 +849,19 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
let args = options.parse_args(&module, invoke_fn)?;
|
let args = options.parse_args(&module, invoke_fn)?;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
let cv_pushed = if let Some(msm) = instance.module.runnable_module.get_module_state_map() {
|
let cv_pushed =
|
||||||
push_code_version(CodeVersion {
|
if let Some(msm) = instance.module.runnable_module.get_module_state_map() {
|
||||||
baseline: true,
|
push_code_version(CodeVersion {
|
||||||
msm: msm,
|
baseline: true,
|
||||||
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
msm: msm,
|
||||||
backend: options.backend,
|
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
||||||
runnable_module: instance.module.runnable_module.clone(),
|
backend: options.backend,
|
||||||
});
|
runnable_module: instance.module.runnable_module.clone(),
|
||||||
true
|
});
|
||||||
} else {
|
true
|
||||||
false
|
} else {
|
||||||
};
|
false
|
||||||
|
};
|
||||||
|
|
||||||
let result = instance
|
let result = instance
|
||||||
.dyn_func(&invoke_fn)
|
.dyn_func(&invoke_fn)
|
||||||
|
Reference in New Issue
Block a user