mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 08:31:21 +00:00
Clean up misc. bits of runtime-core
This commit is contained in:
@ -745,7 +745,7 @@ fn import_memories(
|
||||
}
|
||||
}
|
||||
|
||||
if link_errors.len() > 0 {
|
||||
if !link_errors.is_empty() {
|
||||
Err(link_errors)
|
||||
} else {
|
||||
Ok((memories.into_boxed_map(), vm_memories.into_boxed_map()))
|
||||
@ -886,7 +886,7 @@ fn import_globals(
|
||||
}
|
||||
}
|
||||
|
||||
if link_errors.len() > 0 {
|
||||
if !link_errors.is_empty() {
|
||||
Err(link_errors)
|
||||
} else {
|
||||
Ok((globals.into_boxed_map(), vm_globals.into_boxed_map()))
|
||||
|
@ -257,10 +257,8 @@ pub fn allocate_and_run<R, F: FnOnce() -> R>(size: usize, f: F) -> R {
|
||||
// NOTE: Keep this consistent with `image-loading-*.s`.
|
||||
stack[end_offset - 4 - 10] = &mut ctx as *mut Context<F, R> as usize as u64; // rdi
|
||||
const NUM_SAVED_REGISTERS: usize = 31;
|
||||
let stack_begin = stack
|
||||
.as_mut_ptr()
|
||||
.offset((end_offset - 4 - NUM_SAVED_REGISTERS) as isize);
|
||||
let stack_end = stack.as_mut_ptr().offset(end_offset as isize);
|
||||
let stack_begin = stack.as_mut_ptr().add(end_offset - 4 - NUM_SAVED_REGISTERS);
|
||||
let stack_end = stack.as_mut_ptr().add(end_offset);
|
||||
|
||||
raw::run_on_alternative_stack(stack_end, stack_begin);
|
||||
ctx.ret.take().unwrap()
|
||||
@ -392,7 +390,7 @@ extern "C" fn signal_trap_handler(
|
||||
unwind_result = Box::new(image);
|
||||
} else {
|
||||
// Otherwise, this is a real exception and we just throw it to the caller.
|
||||
if es_image.frames.len() > 0 {
|
||||
if !es_image.frames.is_empty() {
|
||||
eprintln!(
|
||||
"\n{}",
|
||||
"Wasmer encountered an error while running your WebAssembly program."
|
||||
|
@ -21,7 +21,7 @@ use smallvec::{smallvec, SmallVec};
|
||||
use std::{
|
||||
mem,
|
||||
pin::Pin,
|
||||
ptr::NonNull,
|
||||
ptr::{self, NonNull},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
@ -710,7 +710,7 @@ pub(crate) fn call_func_with_index_inner(
|
||||
|
||||
match signature.returns() {
|
||||
&[] => {
|
||||
run_wasm(0 as *mut u64)?;
|
||||
run_wasm(ptr::null_mut())?;
|
||||
Ok(())
|
||||
}
|
||||
&[Type::V128] => {
|
||||
@ -721,10 +721,8 @@ pub(crate) fn call_func_with_index_inner(
|
||||
let mut bytes = [0u8; 16];
|
||||
let lo = result[0].to_le_bytes();
|
||||
let hi = result[1].to_le_bytes();
|
||||
for i in 0..8 {
|
||||
bytes[i] = lo[i];
|
||||
bytes[i + 8] = hi[i];
|
||||
}
|
||||
bytes[..8].clone_from_slice(&lo);
|
||||
bytes[8..16].clone_from_slice(&hi);
|
||||
rets.push(Value::V128(u128::from_le_bytes(bytes)));
|
||||
Ok(())
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ impl<T: Copy + ValueType> WasmPtr<T, Item> {
|
||||
impl<T: Copy + ValueType> WasmPtr<T, Array> {
|
||||
/// Dereference this `WasmPtr`.
|
||||
#[inline]
|
||||
pub fn deref<'a>(self, memory: &'a Memory, index: u32, length: u32) -> Option<&'a [Cell<T>]> {
|
||||
pub fn deref(self, memory: &Memory, index: u32, length: u32) -> Option<&[Cell<T>]> {
|
||||
// gets the size of the item in the array with padding added such that
|
||||
// for any index, we will always result an aligned memory access
|
||||
let item_size = mem::size_of::<T>() + (mem::size_of::<T>() % mem::align_of::<T>());
|
||||
@ -104,12 +104,12 @@ impl<T: Copy + ValueType> WasmPtr<T, Array> {
|
||||
|
||||
/// Mutable dereference this `WasmPtr`.
|
||||
#[inline]
|
||||
pub unsafe fn deref_mut<'a>(
|
||||
pub unsafe fn deref_mut(
|
||||
self,
|
||||
memory: &'a Memory,
|
||||
memory: &Memory,
|
||||
index: u32,
|
||||
length: u32,
|
||||
) -> Option<&'a mut [Cell<T>]> {
|
||||
) -> Option<&mut [Cell<T>]> {
|
||||
// gets the size of the item in the array with padding added such that
|
||||
// for any index, we will always result an aligned memory access
|
||||
let item_size = mem::size_of::<T>() + (mem::size_of::<T>() % mem::align_of::<T>());
|
||||
@ -129,7 +129,7 @@ impl<T: Copy + ValueType> WasmPtr<T, Array> {
|
||||
}
|
||||
|
||||
/// Get a UTF-8 string representation of this `WasmPtr` with the given length.
|
||||
pub fn get_utf8_string<'a>(self, memory: &'a Memory, str_len: u32) -> Option<&'a str> {
|
||||
pub fn get_utf8_string(self, memory: &Memory, str_len: u32) -> Option<&str> {
|
||||
if self.offset as usize + str_len as usize > memory.size().bytes().0 {
|
||||
return None;
|
||||
}
|
||||
@ -141,7 +141,7 @@ impl<T: Copy + ValueType> WasmPtr<T, Array> {
|
||||
/// Get a UTF-8 string representation of this `WasmPtr`, where the string is nul-terminated.
|
||||
/// Note that this does not account for UTF-8 strings that _contain_ nul themselves,
|
||||
/// [`get_utf8_string`] has to be used for those.
|
||||
pub fn get_utf8_string_with_nul<'a>(self, memory: &'a Memory) -> Option<&'a str> {
|
||||
pub fn get_utf8_string_with_nul(self, memory: &Memory) -> Option<&str> {
|
||||
memory.view::<u8>()[(self.offset as usize)..]
|
||||
.iter()
|
||||
.map(|cell| cell.get())
|
||||
|
@ -145,7 +145,7 @@ pub fn read_module<
|
||||
ImportSectionEntryType::Memory(memory_ty) => {
|
||||
let mem_desc = MemoryDescriptor::new(
|
||||
Pages(memory_ty.limits.initial),
|
||||
memory_ty.limits.maximum.map(|max| Pages(max)),
|
||||
memory_ty.limits.maximum.map(Pages),
|
||||
memory_ty.shared,
|
||||
)
|
||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||
@ -183,7 +183,7 @@ pub fn read_module<
|
||||
ParserState::MemorySectionEntry(memory_ty) => {
|
||||
let mem_desc = MemoryDescriptor::new(
|
||||
Pages(memory_ty.limits.initial),
|
||||
memory_ty.limits.maximum.map(|max| Pages(max)),
|
||||
memory_ty.limits.maximum.map(Pages),
|
||||
memory_ty.shared,
|
||||
)
|
||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||
@ -271,11 +271,11 @@ pub fn read_module<
|
||||
Event::Internal(InternalEvent::FunctionBegin(id as u32)),
|
||||
&info.read().unwrap(),
|
||||
)
|
||||
.map_err(|x| LoadError::Codegen(x))?;
|
||||
.map_err(LoadError::Codegen)?;
|
||||
}
|
||||
middlewares
|
||||
.run(Some(fcg), Event::Wasm(op), &info.read().unwrap())
|
||||
.map_err(|x| LoadError::Codegen(x))?;
|
||||
.map_err(LoadError::Codegen)?;
|
||||
}
|
||||
ParserState::EndFunctionBody => break,
|
||||
_ => unreachable!(),
|
||||
@ -287,7 +287,7 @@ pub fn read_module<
|
||||
Event::Internal(InternalEvent::FunctionEnd),
|
||||
&info.read().unwrap(),
|
||||
)
|
||||
.map_err(|x| LoadError::Codegen(x))?;
|
||||
.map_err(LoadError::Codegen)?;
|
||||
fcg.finalize()
|
||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||
func_count = func_count.wrapping_add(1);
|
||||
|
@ -1,3 +1,4 @@
|
||||
//! A process-global registry for function signatures.
|
||||
use crate::{
|
||||
structures::Map,
|
||||
types::{FuncSig, SigIndex},
|
||||
|
@ -417,7 +417,7 @@ impl ExecutionStateImage {
|
||||
}
|
||||
|
||||
fn format_optional_u64_sequence(x: &[Option<u64>]) -> String {
|
||||
if x.len() == 0 {
|
||||
if x.is_empty() {
|
||||
"(empty)".into()
|
||||
} else {
|
||||
join_strings(
|
||||
@ -436,7 +436,7 @@ impl ExecutionStateImage {
|
||||
|
||||
let mut ret = String::new();
|
||||
|
||||
if self.frames.len() == 0 {
|
||||
if self.frames.is_empty() {
|
||||
ret += &"Unknown fault address, cannot read stack.";
|
||||
ret += "\n";
|
||||
} else {
|
||||
@ -632,7 +632,7 @@ pub mod x64 {
|
||||
let mut ptr = &vmctx as *const *const Ctx as *const u8;
|
||||
for x in seq {
|
||||
debug_assert!(ptr.align_offset(std::mem::align_of::<*const u8>()) == 0);
|
||||
ptr = (*(ptr as *const *const u8)).offset(*x as isize);
|
||||
ptr = (*(ptr as *const *const u8)).add(*x);
|
||||
}
|
||||
ptr as usize as u64
|
||||
}
|
||||
@ -679,7 +679,7 @@ pub mod x64 {
|
||||
} else {
|
||||
fsm.wasm_offset_to_target_offset
|
||||
.get(&f.wasm_inst_offset)
|
||||
.map(|x| *x)
|
||||
.copied()
|
||||
}
|
||||
.expect("instruction is not a critical point");
|
||||
|
||||
@ -994,8 +994,8 @@ pub mod x64 {
|
||||
catch_unsafe_unwind(
|
||||
|| {
|
||||
run_on_alternative_stack(
|
||||
stack.as_mut_ptr().offset(stack.len() as isize),
|
||||
stack.as_mut_ptr().offset(stack_offset as isize),
|
||||
stack.as_mut_ptr().add(stack.len()),
|
||||
stack.as_mut_ptr().add(stack_offset),
|
||||
)
|
||||
},
|
||||
breakpoints,
|
||||
@ -1157,24 +1157,18 @@ pub mod x64 {
|
||||
}
|
||||
}
|
||||
|
||||
let mut found_shadow = false;
|
||||
for v in state.stack_values.iter() {
|
||||
match *v {
|
||||
MachineValue::ExplicitShadow => {
|
||||
found_shadow = true;
|
||||
break;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let found_shadow = state
|
||||
.stack_values
|
||||
.iter()
|
||||
.any(|v| *v == MachineValue::ExplicitShadow);
|
||||
if !found_shadow {
|
||||
stack = stack.offset((fsm.shadow_size / 8) as isize);
|
||||
stack = stack.add(fsm.shadow_size / 8);
|
||||
}
|
||||
|
||||
for v in state.stack_values.iter().rev() {
|
||||
match *v {
|
||||
MachineValue::ExplicitShadow => {
|
||||
stack = stack.offset((fsm.shadow_size / 8) as isize);
|
||||
stack = stack.add(fsm.shadow_size / 8);
|
||||
}
|
||||
MachineValue::Undefined => {
|
||||
stack = stack.offset(1);
|
||||
|
@ -231,8 +231,8 @@ pub static INTRINSICS_IMPORTED_DYNAMIC_MEMORY: Intrinsics = Intrinsics {
|
||||
};
|
||||
|
||||
fn get_intrinsics_for_module(m: &ModuleInfo) -> *const Intrinsics {
|
||||
if m.memories.len() == 0 && m.imported_memories.len() == 0 {
|
||||
::std::ptr::null()
|
||||
if m.memories.is_empty() && m.imported_memories.is_empty() {
|
||||
ptr::null()
|
||||
} else {
|
||||
match MemoryIndex::new(0).local_or_import(m) {
|
||||
LocalOrImport::Local(local_mem_index) => {
|
||||
@ -274,7 +274,7 @@ impl Ctx {
|
||||
module: &ModuleInner,
|
||||
) -> Self {
|
||||
let (mem_base, mem_bound): (*mut u8, usize) =
|
||||
if module.info.memories.len() == 0 && module.info.imported_memories.len() == 0 {
|
||||
if module.info.memories.is_empty() && module.info.imported_memories.is_empty() {
|
||||
(::std::ptr::null_mut(), 0)
|
||||
} else {
|
||||
let mem = match MemoryIndex::new(0).local_or_import(&module.info) {
|
||||
@ -327,7 +327,7 @@ impl Ctx {
|
||||
data_finalizer: fn(*mut c_void),
|
||||
) -> Self {
|
||||
let (mem_base, mem_bound): (*mut u8, usize) =
|
||||
if module.info.memories.len() == 0 && module.info.imported_memories.len() == 0 {
|
||||
if module.info.memories.is_empty() && module.info.imported_memories.is_empty() {
|
||||
(::std::ptr::null_mut(), 0)
|
||||
} else {
|
||||
let mem = match MemoryIndex::new(0).local_or_import(&module.info) {
|
||||
@ -351,7 +351,7 @@ impl Ctx {
|
||||
|
||||
intrinsics: get_intrinsics_for_module(&module.info),
|
||||
|
||||
stack_lower_bound: ::std::ptr::null_mut(),
|
||||
stack_lower_bound: ptr::null_mut(),
|
||||
|
||||
memory_base: mem_base,
|
||||
memory_bound: mem_bound,
|
||||
|
Reference in New Issue
Block a user