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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! NUMA OS-seam — thin wrapper over the `numa-shim` crate (`crates/numa`).
//!
//! Preserves the in-tree call sites' API for backward-compat inside the
//! `sefer-alloc` crate; the actual unsafe OS FFI (mbind, VirtualAllocExNuma,
//! sysfs cpumap reads) lives entirely in `numa-shim`. This file contains NO
//! platform-specific unsafe code.
//!
//! ## Gating
//!
//! Compiled only when `feature = "numa-aware"` is active (which implies
//! `dep:numa-shim` is enabled). Each function delegates straight to the shim.
//!
//! ## Backward compatibility
//!
//! The three public items — `NO_NODE`, `current_node`, `bind_segment`,
//! `reserve_aligned_on_node` — have identical signatures to the 742-line
//! in-tree implementation they replace; all callers in `alloc_core.rs` compile
//! without modification.
// `numa_shim` is the one crate that is allowed unsafe; we are safe here.
// needed only for the SAFETY-documented unsafe block in bind_segment
use NonNull;
/// Sentinel value: "no NUMA node / feature disabled / unsupported platform".
/// Re-exported from `numa_shim` to keep both values identical.
pub const NO_NODE: u32 = NO_NODE;
/// Return the NUMA node of the calling thread, or [`NO_NODE`] if unavailable.
///
/// Internally converts `Option<u32>` (the idiomatic shim API) to the sentinel
/// form used by the in-tree call sites.
/// Bind a memory range to a NUMA node.
///
/// Safe wrapper: `sefer-alloc` guarantees that `(base, len)` is its own OS
/// reservation. The shim's `bind_range` is `unsafe` only because external
/// callers may pass arbitrary pointers; inside this crate the invariant is
/// established by the callers (`reserve_small_segment` / `alloc_large_slow`).
///
/// No-op when `node == NO_NODE`, `len == 0`, or `base` is null.
// Currently exercised only by `tests/numa_seam.rs` (NO_NODE / zero-len no-op
// invariants) — `reserve_aligned_on_node` binds at reservation time. Kept
// pub so the seam stays callable, with the SAFETY proof intact.
// `not_unsafe_ptr_arg_deref` is conservative here: this function never
// dereferences `base`; it forwards it to `numa_shim::bind_range` (an unsafe
// fn) whose entire safety story is about an OS reservation existing, not
// about Rust-level UB.
/// Reserve a SEGMENT-aligned span of `usable` bytes with a NUMA preference for
/// `node`.
///
/// Delegates to `numa_shim::reserve_on_node` (requires the `vmem-integration`
/// feature, enabled in `Cargo.toml`). Returns the legacy
/// `(base, reservation_ptr, reservation_len)` triple that the in-tree call
/// sites expect, taking the allocation out of the RAII handle so
/// `sefer-alloc` can manage the lifetime through the segment header's
/// `(reservation, reservation_len)` pair.
///
/// Returns `None` on OOM (same contract as `os::Segment::reserve`).