foundation: is_aligned

This commit is contained in:
janis 2026-08-11 13:01:31 +02:00
parent ef7f924143
commit 04be4cf73e
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8
2 changed files with 5 additions and 1 deletions

View file

@ -251,12 +251,12 @@ impl<A: Allocator + Clone> Slab<A> {
let addr = let addr =
unsafe { NonZero::new_unchecked(mem::align_down(slot.addr().get(), layout.align())) }; unsafe { NonZero::new_unchecked(mem::align_down(slot.addr().get(), layout.align())) };
let chunk_ptr: NonNull<SlabChunk<A>> = slot.with_addr(addr).cast();
// grab provenance exposed in alloc_chunk, since `slot` may be noalias restricted to its layout. // grab provenance exposed in alloc_chunk, since `slot` may be noalias restricted to its layout.
// let chunk_ptr: NonNull<SlabChunk<A>> = NonNull::with_exposed_provenance(addr); // let chunk_ptr: NonNull<SlabChunk<A>> = NonNull::with_exposed_provenance(addr);
let chunk_ptr: NonNull<SlabChunk<A>> = slot.with_addr(addr).cast();
#[cfg(test)] #[cfg(test)]
std::eprintln!("Slab::free_slot(chunk: {chunk_ptr:#?})"); std::eprintln!("Slab::free_slot(chunk: {chunk_ptr:#?})");

View file

@ -43,6 +43,10 @@ pub mod mem {
value & !(alignment - T::one()) value & !(alignment - T::one())
} }
pub fn is_aligned<T: PrimInt>(value: T, alignment: T) -> bool {
value & (alignment - T::one()) == T::zero()
}
/// # Safety /// # Safety
pub unsafe fn volatile_copy<T: Sized>(src: *const T, dst: *mut T, count: usize) { pub unsafe fn volatile_copy<T: Sized>(src: *const T, dst: *mut T, count: usize) {
unsafe { unsafe {