pub fn leak_zeroed_pages(size: usize) -> Option<NonNull<u8>>Expand description
Reserve size bytes of zero-initialised anonymous virtual memory and
leak it for the process lifetime, returning the base pointer.
Folds the leaked-zeroed-sidecar pattern (used by allocators for pre-main bookkeeping structures that must not route through the very allocator they implement) into one helper:
sizeis rounded up to a multiple ofPAGEinternally (any non-zerosizeis accepted; a zerosizereturnsNone). On some platforms (e.g. macOS with 16 KiB pages, or 64 KiB Windows allocation granularity), the OS may round further beyondPAGE, so the actual granularity consumed can exceedPAGE.- the span is guaranteed all-zero on every backend, INCLUDING the miri
fallback (
std::allocdoes not zero; this helper zeroes explicitly under miri), so the returned memory is a valid all-zero initial state. - the reservation is
mem::forget-leaked: it lives for the process lifetime and is never released.
Returns None on OOM or a zero size. The returned pointer is non-null,
PAGE-aligned, and valid for the rounded-up size for the whole process
lifetime. Because the reservation is leaked, the returned pointer may be
safely turned into a &'static by the caller (subject to the caller’s own
aliasing discipline).