Fix a few issues from PR comments.

This commit is contained in:
losfair
2019-08-21 14:53:33 -07:00
parent bf471fbc24
commit bf9d915635
6 changed files with 159 additions and 171 deletions

View File

@ -70,6 +70,8 @@ extern "C" {
) -> bool; ) -> bool;
} }
static SIGNAL_HANDLER_INSTALLED: Once = Once::new();
fn get_callbacks() -> Callbacks { fn get_callbacks() -> Callbacks {
extern "C" fn alloc_memory( extern "C" fn alloc_memory(
size: usize, size: usize,
@ -218,16 +220,6 @@ impl LLVMBackend {
) )
}; };
// Uncomment this to make spectests pass.
// TODO: fix this
/*
static SIGNAL_HANDLER_INSTALLED: Once = Once::new();
SIGNAL_HANDLER_INSTALLED.call_once(|| unsafe {
crate::platform::install_signal_handler();
});*/
if res != LLVMResult::OK { if res != LLVMResult::OK {
panic!("failed to load object") panic!("failed to load object")
} }
@ -235,7 +227,7 @@ impl LLVMBackend {
let buffer = Arc::new(Buffer::LlvmMemory(memory_buffer)); let buffer = Arc::new(Buffer::LlvmMemory(memory_buffer));
let raw_stackmap = unsafe { let raw_stackmap = unsafe {
::std::slice::from_raw_parts( std::slice::from_raw_parts(
llvm_backend_get_stack_map_ptr(module), llvm_backend_get_stack_map_ptr(module),
llvm_backend_get_stack_map_size(module), llvm_backend_get_stack_map_size(module),
) )
@ -281,8 +273,8 @@ impl LLVMBackend {
let mut map_records: BTreeMap<usize, &StkMapRecord> = BTreeMap::new(); let mut map_records: BTreeMap<usize, &StkMapRecord> = BTreeMap::new();
for r in &map.stk_map_records { for record in &map.stk_map_records {
map_records.insert(r.patchpoint_id as usize, r); map_records.insert(record.patchpoint_id as usize, record);
} }
for ((start_id, start_entry), (end_id, end_entry)) in stackmaps for ((start_id, start_entry), (end_id, end_entry)) in stackmaps
@ -314,7 +306,7 @@ impl LLVMBackend {
&mut msm, &mut msm,
); );
} else { } else {
// TODO: optimized out? // The record is optimized out.
} }
} }
@ -329,8 +321,6 @@ impl LLVMBackend {
}) })
.collect(); .collect();
//println!("MSM: {:?}", msm);
( (
Self { Self {
module, module,
@ -341,7 +331,7 @@ impl LLVMBackend {
LLVMCache { buffer }, LLVMCache { buffer },
) )
} else { } else {
eprintln!("WARNING: No stack map"); // This module contains no functions so no stackmaps.
( (
Self { Self {
module, module,
@ -366,8 +356,6 @@ impl LLVMBackend {
return Err("failed to load object".to_string()); return Err("failed to load object".to_string());
} }
static SIGNAL_HANDLER_INSTALLED: Once = Once::new();
SIGNAL_HANDLER_INSTALLED.call_once(|| { SIGNAL_HANDLER_INSTALLED.call_once(|| {
crate::platform::install_signal_handler(); crate::platform::install_signal_handler();
}); });
@ -431,12 +419,16 @@ impl RunnableModule for LLVMBackend {
mem::transmute(symbol) mem::transmute(symbol)
}; };
SIGNAL_HANDLER_INSTALLED.call_once(|| unsafe {
crate::platform::install_signal_handler();
});
Some(unsafe { Wasm::from_raw_parts(trampoline, invoke_trampoline, None) }) Some(unsafe { Wasm::from_raw_parts(trampoline, invoke_trampoline, None) })
} }
fn get_code(&self) -> Option<&[u8]> { fn get_code(&self) -> Option<&[u8]> {
Some(unsafe { Some(unsafe {
::std::slice::from_raw_parts( std::slice::from_raw_parts(
llvm_backend_get_code_ptr(self.module), llvm_backend_get_code_ptr(self.module),
llvm_backend_get_code_size(self.module), llvm_backend_get_code_size(self.module),
) )

View File

@ -185,12 +185,12 @@ impl Drop for CodeMemory {
impl Deref for CodeMemory { impl Deref for CodeMemory {
type Target = [u8]; type Target = [u8];
fn deref(&self) -> &[u8] { fn deref(&self) -> &[u8] {
unsafe { ::std::slice::from_raw_parts(self.ptr, self.size) } unsafe { std::slice::from_raw_parts(self.ptr, self.size) }
} }
} }
impl DerefMut for CodeMemory { impl DerefMut for CodeMemory {
fn deref_mut(&mut self) -> &mut [u8] { fn deref_mut(&mut self) -> &mut [u8] {
unsafe { ::std::slice::from_raw_parts_mut(self.ptr, self.size) } unsafe { std::slice::from_raw_parts_mut(self.ptr, self.size) }
} }
} }

View File

@ -154,7 +154,6 @@ impl ModuleStateMap {
self.lookup_ip(ip, base, |fsm| &fsm.call_offsets) self.lookup_ip(ip, base, |fsm| &fsm.call_offsets)
} }
#[warn(dead_code)]
pub fn lookup_trappable_ip( pub fn lookup_trappable_ip(
&self, &self,
ip: usize, ip: usize,
@ -163,7 +162,6 @@ impl ModuleStateMap {
self.lookup_ip(ip, base, |fsm| &fsm.trappable_offsets) self.lookup_ip(ip, base, |fsm| &fsm.trappable_offsets)
} }
#[warn(dead_code)]
pub fn lookup_loop_ip( pub fn lookup_loop_ip(
&self, &self,
ip: usize, ip: usize,
@ -535,30 +533,30 @@ pub mod x64 {
match inner.0 { match inner.0 {
MachineValue::WasmStack(x) => match state.wasm_stack[x] { MachineValue::WasmStack(x) => match state.wasm_stack[x] {
WasmAbstractValue::Const(x) => { WasmAbstractValue::Const(x) => {
assert!(x <= ::std::u32::MAX as u64); assert!(x <= std::u32::MAX as u64);
stack[stack_offset] |= x; stack[stack_offset] |= x;
} }
WasmAbstractValue::Runtime => { WasmAbstractValue::Runtime => {
let v = f.stack[x].unwrap(); let v = f.stack[x].unwrap();
assert!(v <= ::std::u32::MAX as u64); assert!(v <= std::u32::MAX as u64);
stack[stack_offset] |= v; stack[stack_offset] |= v;
} }
}, },
MachineValue::WasmLocal(x) => match fsm.locals[x] { MachineValue::WasmLocal(x) => match fsm.locals[x] {
WasmAbstractValue::Const(x) => { WasmAbstractValue::Const(x) => {
assert!(x <= ::std::u32::MAX as u64); assert!(x <= std::u32::MAX as u64);
stack[stack_offset] |= x; stack[stack_offset] |= x;
} }
WasmAbstractValue::Runtime => { WasmAbstractValue::Runtime => {
let v = f.locals[x].unwrap(); let v = f.locals[x].unwrap();
assert!(v <= ::std::u32::MAX as u64); assert!(v <= std::u32::MAX as u64);
stack[stack_offset] |= v; stack[stack_offset] |= v;
} }
}, },
MachineValue::VmctxDeref(ref seq) => { MachineValue::VmctxDeref(ref seq) => {
stack[stack_offset] |= stack[stack_offset] |=
compute_vmctx_deref(vmctx as *const Ctx, seq) compute_vmctx_deref(vmctx as *const Ctx, seq)
& (::std::u32::MAX as u64); & (std::u32::MAX as u64);
} }
MachineValue::Undefined => {} MachineValue::Undefined => {}
_ => unimplemented!("TwoHalves.0"), _ => unimplemented!("TwoHalves.0"),
@ -566,30 +564,30 @@ pub mod x64 {
match inner.1 { match inner.1 {
MachineValue::WasmStack(x) => match state.wasm_stack[x] { MachineValue::WasmStack(x) => match state.wasm_stack[x] {
WasmAbstractValue::Const(x) => { WasmAbstractValue::Const(x) => {
assert!(x <= ::std::u32::MAX as u64); assert!(x <= std::u32::MAX as u64);
stack[stack_offset] |= x << 32; stack[stack_offset] |= x << 32;
} }
WasmAbstractValue::Runtime => { WasmAbstractValue::Runtime => {
let v = f.stack[x].unwrap(); let v = f.stack[x].unwrap();
assert!(v <= ::std::u32::MAX as u64); assert!(v <= std::u32::MAX as u64);
stack[stack_offset] |= v << 32; stack[stack_offset] |= v << 32;
} }
}, },
MachineValue::WasmLocal(x) => match fsm.locals[x] { MachineValue::WasmLocal(x) => match fsm.locals[x] {
WasmAbstractValue::Const(x) => { WasmAbstractValue::Const(x) => {
assert!(x <= ::std::u32::MAX as u64); assert!(x <= std::u32::MAX as u64);
stack[stack_offset] |= x << 32; stack[stack_offset] |= x << 32;
} }
WasmAbstractValue::Runtime => { WasmAbstractValue::Runtime => {
let v = f.locals[x].unwrap(); let v = f.locals[x].unwrap();
assert!(v <= ::std::u32::MAX as u64); assert!(v <= std::u32::MAX as u64);
stack[stack_offset] |= v << 32; stack[stack_offset] |= v << 32;
} }
}, },
MachineValue::VmctxDeref(ref seq) => { MachineValue::VmctxDeref(ref seq) => {
stack[stack_offset] |= stack[stack_offset] |=
(compute_vmctx_deref(vmctx as *const Ctx, seq) (compute_vmctx_deref(vmctx as *const Ctx, seq)
& (::std::u32::MAX as u64)) & (std::u32::MAX as u64))
<< 32; << 32;
} }
MachineValue::Undefined => {} MachineValue::Undefined => {}
@ -728,7 +726,7 @@ pub mod x64 {
assert_eq!(vmctx.internal.memory_bound, memory.len()); assert_eq!(vmctx.internal.memory_bound, memory.len());
} }
::std::slice::from_raw_parts_mut( std::slice::from_raw_parts_mut(
vmctx.internal.memory_base, vmctx.internal.memory_base,
vmctx.internal.memory_bound, vmctx.internal.memory_bound,
) )
@ -763,7 +761,7 @@ pub mod x64 {
None None
} else { } else {
Some( Some(
::std::slice::from_raw_parts( std::slice::from_raw_parts(
vmctx.internal.memory_base, vmctx.internal.memory_base,
vmctx.internal.memory_bound, vmctx.internal.memory_bound,
) )

View File

@ -70,7 +70,7 @@ unsafe fn do_optimize(
} }
} }
pub fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>( pub unsafe fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
module_info: &ModuleInfo, module_info: &ModuleInfo,
wasm_binary: &[u8], wasm_binary: &[u8],
mut resume_image: Option<InstanceImage>, mut resume_image: Option<InstanceImage>,
@ -80,7 +80,6 @@ pub fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
optimized_backends: Vec<Box<dyn Fn() -> Box<dyn Compiler> + Send>>, optimized_backends: Vec<Box<dyn Fn() -> Box<dyn Compiler> + Send>>,
interactive_shell: F, interactive_shell: F,
) -> Result<(), String> { ) -> Result<(), String> {
unsafe {
ensure_sighandler(); ensure_sighandler();
let ctx_box = Arc::new(Mutex::new(CtxWrapper(baseline.context_mut() as *mut _))); let ctx_box = Arc::new(Mutex::new(CtxWrapper(baseline.context_mut() as *mut _)));
@ -233,4 +232,3 @@ pub fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
} }
} }
} }
}

View File

@ -277,7 +277,7 @@ impl RunnableModule for X64ExecutionContext {
let execution_context = let execution_context =
::std::mem::transmute_copy::<&dyn RunnableModule, &X64ExecutionContext>(&&**rm); ::std::mem::transmute_copy::<&dyn RunnableModule, &X64ExecutionContext>(&&**rm);
let args = ::std::slice::from_raw_parts( let args = std::slice::from_raw_parts(
args, args,
num_params_plus_one.unwrap().as_ptr() as usize - 1, num_params_plus_one.unwrap().as_ptr() as usize - 1,
); );
@ -1690,7 +1690,7 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
let start_label = a.get_label(); let start_label = a.get_label();
// skip the patchpoint during normal execution // skip the patchpoint during normal execution
a.emit_jmp(Condition::None, start_label); a.emit_jmp(Condition::None, start_label);
// patchpoint of 32 bytes // patchpoint of 32 1-byte nops
for _ in 0..32 { for _ in 0..32 {
a.emit_nop(); a.emit_nop();
} }

View File

@ -587,7 +587,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
let start_raw: extern "C" fn(&mut wasmer_runtime_core::vm::Ctx) = let start_raw: extern "C" fn(&mut wasmer_runtime_core::vm::Ctx) =
unsafe { ::std::mem::transmute(start.get_vm_func()) }; unsafe { ::std::mem::transmute(start.get_vm_func()) };
run_tiering( unsafe { run_tiering(
module.info(), module.info(),
&wasm_binary, &wasm_binary,
if let Some(ref path) = options.resume { if let Some(ref path) = options.resume {
@ -612,7 +612,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
}) })
.collect(), .collect(),
interactive_shell, interactive_shell,
)?; )? };
} }
#[cfg(not(feature = "managed"))] #[cfg(not(feature = "managed"))]