#[inline(always)]
pub const fn align_up(value: usize, align: usize) -> usize {
debug_assert!(align.is_power_of_two());
(value + align - 1) & !(align - 1)
}
#[inline(always)]
pub const fn align_down(value: usize, align: usize) -> usize {
debug_assert!(align.is_power_of_two());
value & !(align - 1)
}
#[allow(dead_code)]
#[inline(always)]
pub const fn is_aligned(value: usize, align: usize) -> bool {
value & (align - 1) == 0
}
pub const MIN_ALIGN: usize = 16;
static PAGE_SIZE_CACHED: core::sync::atomic::AtomicUsize =
core::sync::atomic::AtomicUsize::new(4096);
static PAGE_SHIFT_CACHED: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(12);
pub unsafe fn init_page_size() {
let ps = libc::sysconf(libc::_SC_PAGESIZE);
let ps = if ps > 0 { ps as usize } else { 4096 };
PAGE_SIZE_CACHED.store(ps, core::sync::atomic::Ordering::Release);
PAGE_SHIFT_CACHED.store(ps.trailing_zeros(), core::sync::atomic::Ordering::Release);
}
#[inline(always)]
pub fn page_size() -> usize {
PAGE_SIZE_CACHED.load(core::sync::atomic::Ordering::Relaxed)
}
#[inline(always)]
pub fn page_shift() -> u32 {
PAGE_SHIFT_CACHED.load(core::sync::atomic::Ordering::Relaxed)
}
pub const LARGE_THRESHOLD: usize = 16384;
pub const MAX_ARENAS: usize = 32;
#[allow(dead_code)]
pub const DEFAULT_QUARANTINE_BYTES: usize = 4 * 1024 * 1024;
#[allow(dead_code)]
#[inline(always)]
pub const fn largest_pow2_dividing(x: usize) -> usize {
if x == 0 {
return 1;
}
x & x.wrapping_neg()
}
#[allow(dead_code)]
pub const POISON_BYTE: u8 = 0xFE;
#[allow(dead_code)]
pub const JUNK_BYTE: u8 = 0xCD;