use mnemosyne_core::policy::AllocPolicy;
#[inline(always)]
pub(crate) unsafe fn init_bytes(
ptr: *mut u8,
size: usize,
zero_init: bool,
poison: bool,
poison_byte: u8,
) {
if zero_init {
unsafe { core::ptr::write_bytes(ptr, 0, size) };
} else if poison {
unsafe { core::ptr::write_bytes(ptr, poison_byte, size) };
}
}
#[inline(always)]
pub(crate) unsafe fn poison_bytes(ptr: *mut u8, size: usize, poison: bool, poison_byte: u8) {
if poison {
unsafe { core::ptr::write_bytes(ptr, poison_byte, size) };
}
}
#[inline(always)]
pub unsafe fn initialize_allocated_bytes<P: AllocPolicy>(ptr: *mut u8, size: usize) {
unsafe {
init_bytes(
ptr,
size,
P::ZERO_INITIALIZE,
P::ENABLE_POISONING,
P::POISON_ALLOC_BYTE,
)
}
}
#[inline(always)]
pub unsafe fn poison_freed_bytes<P: AllocPolicy>(ptr: *mut u8, size: usize) {
unsafe { poison_bytes(ptr, size, P::ENABLE_POISONING, P::POISON_FREE_BYTE) }
}