mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-15 09:51:21 +00:00
Fix a few issues from PR comments.
This commit is contained in:
@ -70,6 +70,8 @@ extern "C" {
|
||||
) -> bool;
|
||||
}
|
||||
|
||||
static SIGNAL_HANDLER_INSTALLED: Once = Once::new();
|
||||
|
||||
fn get_callbacks() -> Callbacks {
|
||||
extern "C" fn alloc_memory(
|
||||
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 {
|
||||
panic!("failed to load object")
|
||||
}
|
||||
@ -235,7 +227,7 @@ impl LLVMBackend {
|
||||
let buffer = Arc::new(Buffer::LlvmMemory(memory_buffer));
|
||||
|
||||
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_size(module),
|
||||
)
|
||||
@ -281,8 +273,8 @@ impl LLVMBackend {
|
||||
|
||||
let mut map_records: BTreeMap<usize, &StkMapRecord> = BTreeMap::new();
|
||||
|
||||
for r in &map.stk_map_records {
|
||||
map_records.insert(r.patchpoint_id as usize, r);
|
||||
for record in &map.stk_map_records {
|
||||
map_records.insert(record.patchpoint_id as usize, record);
|
||||
}
|
||||
|
||||
for ((start_id, start_entry), (end_id, end_entry)) in stackmaps
|
||||
@ -314,7 +306,7 @@ impl LLVMBackend {
|
||||
&mut msm,
|
||||
);
|
||||
} else {
|
||||
// TODO: optimized out?
|
||||
// The record is optimized out.
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,8 +321,6 @@ impl LLVMBackend {
|
||||
})
|
||||
.collect();
|
||||
|
||||
//println!("MSM: {:?}", msm);
|
||||
|
||||
(
|
||||
Self {
|
||||
module,
|
||||
@ -341,7 +331,7 @@ impl LLVMBackend {
|
||||
LLVMCache { buffer },
|
||||
)
|
||||
} else {
|
||||
eprintln!("WARNING: No stack map");
|
||||
// This module contains no functions so no stackmaps.
|
||||
(
|
||||
Self {
|
||||
module,
|
||||
@ -366,8 +356,6 @@ impl LLVMBackend {
|
||||
return Err("failed to load object".to_string());
|
||||
}
|
||||
|
||||
static SIGNAL_HANDLER_INSTALLED: Once = Once::new();
|
||||
|
||||
SIGNAL_HANDLER_INSTALLED.call_once(|| {
|
||||
crate::platform::install_signal_handler();
|
||||
});
|
||||
@ -431,12 +419,16 @@ impl RunnableModule for LLVMBackend {
|
||||
mem::transmute(symbol)
|
||||
};
|
||||
|
||||
SIGNAL_HANDLER_INSTALLED.call_once(|| unsafe {
|
||||
crate::platform::install_signal_handler();
|
||||
});
|
||||
|
||||
Some(unsafe { Wasm::from_raw_parts(trampoline, invoke_trampoline, None) })
|
||||
}
|
||||
|
||||
fn get_code(&self) -> Option<&[u8]> {
|
||||
Some(unsafe {
|
||||
::std::slice::from_raw_parts(
|
||||
std::slice::from_raw_parts(
|
||||
llvm_backend_get_code_ptr(self.module),
|
||||
llvm_backend_get_code_size(self.module),
|
||||
)
|
||||
|
@ -185,12 +185,12 @@ impl Drop for CodeMemory {
|
||||
impl Deref for CodeMemory {
|
||||
type Target = [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 {
|
||||
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) }
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,6 @@ impl ModuleStateMap {
|
||||
self.lookup_ip(ip, base, |fsm| &fsm.call_offsets)
|
||||
}
|
||||
|
||||
#[warn(dead_code)]
|
||||
pub fn lookup_trappable_ip(
|
||||
&self,
|
||||
ip: usize,
|
||||
@ -163,7 +162,6 @@ impl ModuleStateMap {
|
||||
self.lookup_ip(ip, base, |fsm| &fsm.trappable_offsets)
|
||||
}
|
||||
|
||||
#[warn(dead_code)]
|
||||
pub fn lookup_loop_ip(
|
||||
&self,
|
||||
ip: usize,
|
||||
@ -535,30 +533,30 @@ pub mod x64 {
|
||||
match inner.0 {
|
||||
MachineValue::WasmStack(x) => match state.wasm_stack[x] {
|
||||
WasmAbstractValue::Const(x) => {
|
||||
assert!(x <= ::std::u32::MAX as u64);
|
||||
assert!(x <= std::u32::MAX as u64);
|
||||
stack[stack_offset] |= x;
|
||||
}
|
||||
WasmAbstractValue::Runtime => {
|
||||
let v = f.stack[x].unwrap();
|
||||
assert!(v <= ::std::u32::MAX as u64);
|
||||
assert!(v <= std::u32::MAX as u64);
|
||||
stack[stack_offset] |= v;
|
||||
}
|
||||
},
|
||||
MachineValue::WasmLocal(x) => match fsm.locals[x] {
|
||||
WasmAbstractValue::Const(x) => {
|
||||
assert!(x <= ::std::u32::MAX as u64);
|
||||
assert!(x <= std::u32::MAX as u64);
|
||||
stack[stack_offset] |= x;
|
||||
}
|
||||
WasmAbstractValue::Runtime => {
|
||||
let v = f.locals[x].unwrap();
|
||||
assert!(v <= ::std::u32::MAX as u64);
|
||||
assert!(v <= std::u32::MAX as u64);
|
||||
stack[stack_offset] |= v;
|
||||
}
|
||||
},
|
||||
MachineValue::VmctxDeref(ref seq) => {
|
||||
stack[stack_offset] |=
|
||||
compute_vmctx_deref(vmctx as *const Ctx, seq)
|
||||
& (::std::u32::MAX as u64);
|
||||
& (std::u32::MAX as u64);
|
||||
}
|
||||
MachineValue::Undefined => {}
|
||||
_ => unimplemented!("TwoHalves.0"),
|
||||
@ -566,30 +564,30 @@ pub mod x64 {
|
||||
match inner.1 {
|
||||
MachineValue::WasmStack(x) => match state.wasm_stack[x] {
|
||||
WasmAbstractValue::Const(x) => {
|
||||
assert!(x <= ::std::u32::MAX as u64);
|
||||
assert!(x <= std::u32::MAX as u64);
|
||||
stack[stack_offset] |= x << 32;
|
||||
}
|
||||
WasmAbstractValue::Runtime => {
|
||||
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;
|
||||
}
|
||||
},
|
||||
MachineValue::WasmLocal(x) => match fsm.locals[x] {
|
||||
WasmAbstractValue::Const(x) => {
|
||||
assert!(x <= ::std::u32::MAX as u64);
|
||||
assert!(x <= std::u32::MAX as u64);
|
||||
stack[stack_offset] |= x << 32;
|
||||
}
|
||||
WasmAbstractValue::Runtime => {
|
||||
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;
|
||||
}
|
||||
},
|
||||
MachineValue::VmctxDeref(ref seq) => {
|
||||
stack[stack_offset] |=
|
||||
(compute_vmctx_deref(vmctx as *const Ctx, seq)
|
||||
& (::std::u32::MAX as u64))
|
||||
& (std::u32::MAX as u64))
|
||||
<< 32;
|
||||
}
|
||||
MachineValue::Undefined => {}
|
||||
@ -728,7 +726,7 @@ pub mod x64 {
|
||||
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_bound,
|
||||
)
|
||||
@ -763,7 +761,7 @@ pub mod x64 {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
::std::slice::from_raw_parts(
|
||||
std::slice::from_raw_parts(
|
||||
vmctx.internal.memory_base,
|
||||
vmctx.internal.memory_bound,
|
||||
)
|
||||
|
@ -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,
|
||||
wasm_binary: &[u8],
|
||||
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>>,
|
||||
interactive_shell: F,
|
||||
) -> Result<(), String> {
|
||||
unsafe {
|
||||
ensure_sighandler();
|
||||
|
||||
let ctx_box = Arc::new(Mutex::new(CtxWrapper(baseline.context_mut() as *mut _)));
|
||||
@ -232,5 +231,4 @@ pub fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ impl RunnableModule for X64ExecutionContext {
|
||||
let execution_context =
|
||||
::std::mem::transmute_copy::<&dyn RunnableModule, &X64ExecutionContext>(&&**rm);
|
||||
|
||||
let args = ::std::slice::from_raw_parts(
|
||||
let args = std::slice::from_raw_parts(
|
||||
args,
|
||||
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();
|
||||
// skip the patchpoint during normal execution
|
||||
a.emit_jmp(Condition::None, start_label);
|
||||
// patchpoint of 32 bytes
|
||||
// patchpoint of 32 1-byte nops
|
||||
for _ in 0..32 {
|
||||
a.emit_nop();
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
||||
let start_raw: extern "C" fn(&mut wasmer_runtime_core::vm::Ctx) =
|
||||
unsafe { ::std::mem::transmute(start.get_vm_func()) };
|
||||
|
||||
run_tiering(
|
||||
unsafe { run_tiering(
|
||||
module.info(),
|
||||
&wasm_binary,
|
||||
if let Some(ref path) = options.resume {
|
||||
@ -612,7 +612,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
||||
})
|
||||
.collect(),
|
||||
interactive_shell,
|
||||
)?;
|
||||
)? };
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "managed"))]
|
||||
|
Reference in New Issue
Block a user