Rename `IsNull` trait to `PointerExt`

This allows for more pointer extension methods to be added in the future.
This commit is contained in:
a2x 2024-04-09 13:10:58 +10:00
parent 4cdfd6c4a6
commit 05656b4f0b
4 changed files with 13 additions and 13 deletions

View File

@ -1,13 +1,13 @@
use memflow::types::Pointer64; use memflow::types::{Pointer, PrimitiveAddress};
pub trait IsNull { pub trait PointerExt {
/// Returns `true` if the pointer is null.
fn is_null(&self) -> bool; fn is_null(&self) -> bool;
} }
impl<T> IsNull for Pointer64<T> { impl<U: PrimitiveAddress, T> PointerExt for Pointer<U, T> {
/// Returns `true` if the pointer is null.
#[inline] #[inline]
fn is_null(&self) -> bool { fn is_null(&self) -> bool {
self.inner == 0 self.inner.is_null()
} }
} }

View File

@ -19,7 +19,6 @@ impl<T: Pod> UtlMemory<T> {
/// Returns the element at the specified index. /// Returns the element at the specified index.
pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> { pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
// Check if the index is out of bounds.
if idx >= self.count() as usize { if idx >= self.count() as usize {
return Err(Error::Other("index out of bounds")); return Err(Error::Other("index out of bounds"));
} }
@ -27,7 +26,7 @@ impl<T: Pod> UtlMemory<T> {
self.mem.at(idx as _).read(process).map_err(Into::into) self.mem.at(idx as _).read(process).map_err(Into::into)
} }
/// Returns `true` if the memory is externally allocated. /// Returns `true` if the memory was externally allocated.
#[inline] #[inline]
pub fn is_externally_allocated(&self) -> bool { pub fn is_externally_allocated(&self) -> bool {
self.grow_size < 0 self.grow_size < 0

View File

@ -3,7 +3,7 @@ use memflow::prelude::v1::*;
use super::UtlMemoryPoolBase; use super::UtlMemoryPoolBase;
use crate::error::Result; use crate::error::Result;
use crate::mem::IsNull; use crate::mem::PointerExt;
#[repr(C)] #[repr(C)]
pub struct HashAllocatedBlob<D> { pub struct HashAllocatedBlob<D> {
@ -17,7 +17,7 @@ unsafe impl<D: 'static> Pod for HashAllocatedBlob<D> {}
#[repr(C)] #[repr(C)]
pub struct HashBucket<D, K> { pub struct HashBucket<D, K> {
pad_0000: [u8; 0x18], // 0x0000, pad_0000: [u8; 0x18], // 0x0000
pub first: Pointer64<HashFixedDataInternal<D, K>>, // 0x0018 pub first: Pointer64<HashFixedDataInternal<D, K>>, // 0x0018
pub first_uncommitted: Pointer64<HashFixedDataInternal<D, K>>, // 0x0020 pub first_uncommitted: Pointer64<HashFixedDataInternal<D, K>>, // 0x0020
} }
@ -40,7 +40,11 @@ pub struct UtlTsHash<D, const C: usize = 256, K = u64> {
pad_2881: [u8; 0xF], // 0x2881 pad_2881: [u8; 0xF], // 0x2881
} }
impl<D: Pod + IsNull, const C: usize, K: Pod> UtlTsHash<D, C, K> { impl<D, const C: usize, K> UtlTsHash<D, C, K>
where
D: Pod + PointerExt,
K: Pod,
{
/// Returns the number of allocated blocks. /// Returns the number of allocated blocks.
#[inline] #[inline]
pub fn blocks_alloc(&self) -> i32 { pub fn blocks_alloc(&self) -> i32 {
@ -77,7 +81,6 @@ impl<D: Pod + IsNull, const C: usize, K: Pod> UtlTsHash<D, C, K> {
unallocated_list.push(element.data); unallocated_list.push(element.data);
} }
// Check if we have too many elements.
if unallocated_list.len() >= blocks_alloc { if unallocated_list.len() >= blocks_alloc {
break; break;
} }
@ -96,7 +99,6 @@ impl<D: Pod + IsNull, const C: usize, K: Pod> UtlTsHash<D, C, K> {
allocated_list.push(blob.data); allocated_list.push(blob.data);
} }
// Check if we have too many elements.
if allocated_list.len() >= peak_alloc { if allocated_list.len() >= peak_alloc {
break; break;
} }

View File

@ -18,7 +18,6 @@ impl<T: Pod> UtlVector<T> {
/// Returns the element at the specified index. /// Returns the element at the specified index.
pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> { pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
// Check if the index is out of bounds.
if idx >= self.count() as usize { if idx >= self.count() as usize {
return Err(Error::Other("index out of bounds")); return Err(Error::Other("index out of bounds"));
} }