1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use NonNull;
use cratePAGE;
use reserve_aligned;
/// 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:
///
/// - `size` is rounded up to a multiple of [`PAGE`] internally (any non-zero
/// `size` is accepted; a zero `size` returns `None`). On some platforms
/// (e.g. macOS with 16 KiB pages, or 64 KiB Windows allocation granularity),
/// the OS may round further beyond `PAGE`, so the actual granularity
/// consumed can exceed `PAGE`.
/// - the span is guaranteed all-zero on every backend, INCLUDING the miri
/// fallback (`std::alloc` does 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).