diff --git a/cranelift/jit/src/backend.rs b/cranelift/jit/src/backend.rs index ed45734136..a1f63e694d 100644 --- a/cranelift/jit/src/backend.rs +++ b/cranelift/jit/src/backend.rs @@ -874,7 +874,7 @@ fn lookup_with_dlsym(name: &str) -> Option<*const u8> { // try to find the searched symbol in the currently running executable ptr::null_mut(), // try to find the searched symbol in local c runtime - winapi::um::libloaderapi::GetModuleHandleA(MSVCRT_DLL.as_ptr() as *const i8), + winapi::um::libloaderapi::GetModuleHandleA(MSVCRT_DLL.as_ptr().cast::()), ]; for handle in &handles { diff --git a/crates/jit/src/code_memory.rs b/crates/jit/src/code_memory.rs index f5bd837dfe..9ad8e036ff 100644 --- a/crates/jit/src/code_memory.rs +++ b/crates/jit/src/code_memory.rs @@ -200,11 +200,7 @@ unsafe fn register_unwind_info(obj: &File, text: &[u8]) -> Result impl ExactSizeIterator + '_ { + ) -> impl ExactSizeIterator + '_ { let code = self.code(); self.funcs.iter().map(move |(i, info)| { let func = &code[info.start as usize..][..info.length as usize]; ( i, - std::ptr::slice_from_raw_parts_mut( - func.as_ptr() as *mut VMFunctionBody, - func.len(), - ), + std::ptr::slice_from_raw_parts(func.as_ptr().cast::(), func.len()), ) }) } @@ -423,7 +420,7 @@ impl CompiledModule { /// memory with the stack maps associated with those bytes. pub fn stack_maps( &self, - ) -> impl Iterator { + ) -> impl Iterator { self.finished_functions() .map(|(_, f)| f) .zip(self.funcs.values().map(|f| f.stack_maps.as_slice())) diff --git a/crates/jit/src/profiling/jitdump_linux.rs b/crates/jit/src/profiling/jitdump_linux.rs index 50cb7487dd..374b21b503 100644 --- a/crates/jit/src/profiling/jitdump_linux.rs +++ b/crates/jit/src/profiling/jitdump_linux.rs @@ -292,7 +292,7 @@ impl State { let tid = pid; // ThreadId does appear to track underlying thread. Using PID. for (idx, func) in module.finished_functions() { - let (addr, len) = unsafe { ((*func).as_ptr() as *const u8, (*func).len()) }; + let (addr, len) = unsafe { ((*func).as_ptr().cast::(), (*func).len()) }; if let Some(img) = &dbg_image { if let Err(err) = self.dump_from_debug_image(img, "wasm", addr, len, pid, tid) { println!( diff --git a/crates/jit/src/profiling/vtune_linux.rs b/crates/jit/src/profiling/vtune_linux.rs index 9b52ef3aac..9730e2e5ab 100644 --- a/crates/jit/src/profiling/vtune_linux.rs +++ b/crates/jit/src/profiling/vtune_linux.rs @@ -130,7 +130,7 @@ impl State { .unwrap_or_else(|| format!("wasm_module_{}", global_module_id)); for (idx, func) in module.finished_functions() { - let (addr, len) = unsafe { ((*func).as_ptr() as *const u8, (*func).len()) }; + let (addr, len) = unsafe { ((*func).as_ptr().cast::(), (*func).len()) }; let method_name = super::debug_name(module.module(), idx); let method_id = self.get_method_id(); log::trace!( diff --git a/crates/jit/src/unwind/systemv.rs b/crates/jit/src/unwind/systemv.rs index 6db1af5320..6dc519d0c6 100644 --- a/crates/jit/src/unwind/systemv.rs +++ b/crates/jit/src/unwind/systemv.rs @@ -21,8 +21,8 @@ impl UnwindRegistration { /// describe an in-memory representation of a `.eh_frame` section. This is /// typically arranged for by the `wasmtime-obj` crate. pub unsafe fn new( - _base_address: *mut u8, - unwind_info: *mut u8, + _base_address: *const u8, + unwind_info: *const u8, unwind_len: usize, ) -> Result { debug_assert_eq!( diff --git a/crates/jit/src/unwind/winx64.rs b/crates/jit/src/unwind/winx64.rs index b011fadb80..63c6858048 100644 --- a/crates/jit/src/unwind/winx64.rs +++ b/crates/jit/src/unwind/winx64.rs @@ -11,8 +11,8 @@ pub struct UnwindRegistration { impl UnwindRegistration { pub unsafe fn new( - base_address: *mut u8, - unwind_info: *mut u8, + base_address: *const u8, + unwind_info: *const u8, unwind_len: usize, ) -> Result { assert!(unwind_info as usize % 4 == 0); diff --git a/crates/runtime/src/externref.rs b/crates/runtime/src/externref.rs index 7d110a87ad..9677b39afa 100644 --- a/crates/runtime/src/externref.rs +++ b/crates/runtime/src/externref.rs @@ -422,7 +422,7 @@ impl VMExternRef { /// or `PartialEq` implementation of the pointed-to values. #[inline] pub fn eq(a: &Self, b: &Self) -> bool { - ptr::eq(a.0.as_ptr() as *const _, b.0.as_ptr() as *const _) + ptr::eq(a.0.as_ptr(), b.0.as_ptr()) } /// Hash a given `VMExternRef`. @@ -434,7 +434,7 @@ impl VMExternRef { where H: Hasher, { - ptr::hash(externref.0.as_ptr() as *const _, hasher); + ptr::hash(externref.0.as_ptr(), hasher); } /// Compare two `VMExternRef`s. @@ -566,8 +566,8 @@ impl VMExternRefActivationsTable { /// Create a new `VMExternRefActivationsTable`. pub fn new() -> Self { - let chunk = Self::new_chunk(Self::CHUNK_SIZE); - let next = chunk.as_ptr() as *mut TableElem; + let mut chunk = Self::new_chunk(Self::CHUNK_SIZE); + let next = chunk.as_mut_ptr().cast::(); let end = unsafe { next.add(chunk.len()) }; VMExternRefActivationsTable { @@ -703,7 +703,7 @@ impl VMExternRefActivationsTable { precise_stack_roots: &mut HashSet, root: NonNull, ) { - let root = unsafe { VMExternRef::clone_from_raw(root.as_ptr() as *mut _) }; + let root = unsafe { VMExternRef::clone_from_raw(root.as_ptr().cast()) }; precise_stack_roots.insert(VMExternRefWithTraits(root)); } @@ -730,7 +730,7 @@ impl VMExternRefActivationsTable { // Reset our `next` finger to the start of the bump allocation chunk. unsafe { - let next = self.alloc.chunk.as_ptr() as *mut TableElem; + let next = self.alloc.chunk.as_mut_ptr().cast::(); debug_assert!(!next.is_null()); *self.alloc.next.get() = NonNull::new_unchecked(next); } diff --git a/crates/runtime/src/instance.rs b/crates/runtime/src/instance.rs index 2c9487d75e..5221dc4a0f 100644 --- a/crates/runtime/src/instance.rs +++ b/crates/runtime/src/instance.rs @@ -100,7 +100,7 @@ impl Instance { /// Helper function to access various locations offset from our `*mut /// VMContext` object. unsafe fn vmctx_plus_offset(&self, offset: u32) -> *mut T { - (self.vmctx_ptr() as *mut u8) + (self.vmctx_ptr().cast::()) .add(usize::try_from(offset).unwrap()) .cast() } @@ -420,7 +420,8 @@ impl Instance { // Keep the `VMContext` pointers used by compiled Wasm code up to // date. - self.set_table(table_index, self.tables[table_index].vmtable()); + let element = self.tables[table_index].vmtable(); + self.set_table(table_index, element); result } diff --git a/crates/runtime/src/memory.rs b/crates/runtime/src/memory.rs index 07c0c619cc..ae68e90344 100644 --- a/crates/runtime/src/memory.rs +++ b/crates/runtime/src/memory.rs @@ -476,10 +476,10 @@ impl Memory { } /// Return a `VMMemoryDefinition` for exposing the memory to compiled wasm code. - pub fn vmmemory(&self) -> VMMemoryDefinition { + pub fn vmmemory(&mut self) -> VMMemoryDefinition { match self { Memory::Static { base, size, .. } => VMMemoryDefinition { - base: base.as_ptr() as *mut _, + base: base.as_mut_ptr().cast(), current_length: *size, }, Memory::Dynamic(mem) => mem.vmmemory(), diff --git a/crates/runtime/src/table.rs b/crates/runtime/src/table.rs index 5aed2333a6..53f5f2dd37 100644 --- a/crates/runtime/src/table.rs +++ b/crates/runtime/src/table.rs @@ -398,14 +398,14 @@ impl Table { } /// Return a `VMTableDefinition` for exposing the table to compiled wasm code. - pub fn vmtable(&self) -> VMTableDefinition { + pub fn vmtable(&mut self) -> VMTableDefinition { match self { Table::Static { data, size, .. } => VMTableDefinition { - base: data.as_ptr() as *mut _, + base: data.as_mut_ptr().cast(), current_elements: *size, }, Table::Dynamic { elements, .. } => VMTableDefinition { - base: elements.as_ptr() as _, + base: elements.as_mut_ptr().cast(), current_elements: elements.len().try_into().unwrap(), }, } diff --git a/crates/runtime/src/vmcontext.rs b/crates/runtime/src/vmcontext.rs index d2832eb6ce..2441e78d64 100644 --- a/crates/runtime/src/vmcontext.rs +++ b/crates/runtime/src/vmcontext.rs @@ -340,145 +340,157 @@ impl VMGlobalDefinition { /// Return a reference to the value as an i32. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_i32(&self) -> &i32 { - &*(self.storage.as_ref().as_ptr() as *const i32) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as an i32. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_i32_mut(&mut self) -> &mut i32 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut i32) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as a u32. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u32(&self) -> &u32 { - &*(self.storage.as_ref().as_ptr() as *const u32) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as an u32. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u32_mut(&mut self) -> &mut u32 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut u32) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as an i64. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_i64(&self) -> &i64 { - &*(self.storage.as_ref().as_ptr() as *const i64) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as an i64. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_i64_mut(&mut self) -> &mut i64 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut i64) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as an u64. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u64(&self) -> &u64 { - &*(self.storage.as_ref().as_ptr() as *const u64) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as an u64. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u64_mut(&mut self) -> &mut u64 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut u64) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as an f32. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f32(&self) -> &f32 { - &*(self.storage.as_ref().as_ptr() as *const f32) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as an f32. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f32_mut(&mut self) -> &mut f32 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut f32) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as f32 bits. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f32_bits(&self) -> &u32 { - &*(self.storage.as_ref().as_ptr() as *const u32) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as f32 bits. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f32_bits_mut(&mut self) -> &mut u32 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut u32) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as an f64. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f64(&self) -> &f64 { - &*(self.storage.as_ref().as_ptr() as *const f64) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as an f64. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f64_mut(&mut self) -> &mut f64 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut f64) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as f64 bits. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f64_bits(&self) -> &u64 { - &*(self.storage.as_ref().as_ptr() as *const u64) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as f64 bits. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_f64_bits_mut(&mut self) -> &mut u64 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut u64) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as an u128. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u128(&self) -> &u128 { - &*(self.storage.as_ref().as_ptr() as *const u128) + &*(self.storage.as_ref().as_ptr().cast::()) } /// Return a mutable reference to the value as an u128. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u128_mut(&mut self) -> &mut u128 { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut u128) + &mut *(self.storage.as_mut().as_mut_ptr().cast::()) } /// Return a reference to the value as u128 bits. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u128_bits(&self) -> &[u8; 16] { - &*(self.storage.as_ref().as_ptr() as *const [u8; 16]) + &*(self.storage.as_ref().as_ptr().cast::<[u8; 16]>()) } /// Return a mutable reference to the value as u128 bits. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_u128_bits_mut(&mut self) -> &mut [u8; 16] { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut [u8; 16]) + &mut *(self.storage.as_mut().as_mut_ptr().cast::<[u8; 16]>()) } /// Return a reference to the value as an externref. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_externref(&self) -> &Option { - &*(self.storage.as_ref().as_ptr() as *const Option) + &*(self.storage.as_ref().as_ptr().cast::>()) } /// Return a mutable reference to the value as an externref. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_externref_mut(&mut self) -> &mut Option { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut Option) + &mut *(self + .storage + .as_mut() + .as_mut_ptr() + .cast::>()) } /// Return a reference to the value as an anyfunc. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_anyfunc(&self) -> *const VMCallerCheckedAnyfunc { - *(self.storage.as_ref().as_ptr() as *const *const VMCallerCheckedAnyfunc) + *(self + .storage + .as_ref() + .as_ptr() + .cast::<*const VMCallerCheckedAnyfunc>()) } /// Return a mutable reference to the value as an anyfunc. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn as_anyfunc_mut(&mut self) -> &mut *const VMCallerCheckedAnyfunc { - &mut *(self.storage.as_mut().as_mut_ptr() as *mut *const VMCallerCheckedAnyfunc) + &mut *(self + .storage + .as_mut() + .as_mut_ptr() + .cast::<*const VMCallerCheckedAnyfunc>()) } } diff --git a/crates/wasi-common/src/snapshots/preview_1.rs b/crates/wasi-common/src/snapshots/preview_1.rs index d427ff23d6..5491a8d900 100644 --- a/crates/wasi-common/src/snapshots/preview_1.rs +++ b/crates/wasi-common/src/snapshots/preview_1.rs @@ -1553,7 +1553,7 @@ fn dirent_bytes(dirent: types::Dirent) -> Vec { .expect("Dirent is smaller than 2^32"); let mut bytes = Vec::with_capacity(size); bytes.resize(size, 0); - let ptr = bytes.as_mut_ptr() as *mut types::Dirent; + let ptr = bytes.as_mut_ptr().cast::(); let guest_dirent = types::Dirent { d_ino: dirent.d_ino.to_le(), d_namlen: dirent.d_namlen.to_le(), diff --git a/crates/wasmtime/src/externals.rs b/crates/wasmtime/src/externals.rs index 047291ba34..c947038497 100644 --- a/crates/wasmtime/src/externals.rs +++ b/crates/wasmtime/src/externals.rs @@ -346,7 +346,7 @@ impl Global { Val::F64(f) => *definition.as_u64_mut() = f, Val::FuncRef(f) => { *definition.as_anyfunc_mut() = f.map_or(ptr::null(), |f| { - f.caller_checked_anyfunc(store).as_ptr() as *const _ + f.caller_checked_anyfunc(store).as_ptr().cast() }); } Val::ExternRef(x) => {