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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use crateVmemError;
use cratemock;
use craterecommit_pages_impl;
use crate;
/// Recommit pages `[base + start, base + end)` previously passed to
/// [`decommit`](crate::api::decommit). On Windows this re-commits physical pages
/// (`VirtualAlloc(MEM_COMMIT)`); on Unix re-access is implicit so this is a
/// no-op. On the Darwin family (macOS/iOS/tvOS/watchOS) specifically, whether
/// re-access reads back zeroed pages or the pre-decommit contents is not
/// guaranteed either way — see [`decommit`](crate::api::decommit)'s Darwin caveat for why.
///
/// Returns `true` if the range is now committed (or the call was a
/// well-formed no-op — an empty PAGE-ALIGNED range, `start == end`), and
/// `false` if the OS refused to
/// commit the pages (commit-charge exhaustion / true OOM) OR the offsets
/// violated the contract below. On `false` the caller MUST NOT write into
/// `[base+start, base+end)`. Never panics. For the cause use [`try_recommit`].
///
/// # Safety
///
/// - `base` must be the [`as_ptr`](crate::Reservation::as_ptr) of a live
/// reservation whose `[base+start, base+end)` range was previously
/// decommitted.
/// - **`end <= reservation.len()`** (the reservation's usable span, in
/// bytes) — this is a MANDATORY precondition of the pointer arithmetic
/// this function performs internally (`base.add(start)` in the Windows
/// backend's `recommit_pages_impl`; the Unix and miri backends are no-ops
/// but the contract is stated platform-independently), not merely a
/// functional/behavioral preference. Before task #1229/F6 this function
/// was the only range-taking free function whose `# Safety` lacked the
/// bound: [`decommit`](crate::api::decommit)'s states it in full (task
/// #1213/L2, whose wording this matches), `try_decommit` and
/// `decommit_lazy` carry it (restated in prose / in full — the latter
/// since task #1235, which replaced `decommit_lazy`'s earlier bare
/// same-contract reference), and the
/// [`commit_range`](crate::api::commit_range) pair spells it out as
/// `end <= len`. For an `unsafe fn`, a
/// bounds requirement that determines whether pointer arithmetic is even
/// defined belongs inside `# Safety` itself, restated in full. Passing
/// `end > reservation.len()` is undefined behavior (with `start <= end`
/// the bound is what keeps the backend's `base.add(start)` offset
/// in-bounds and the OS call's span `[base+start, base+end)` inside the
/// reservation), distinct from — and a strictly worse violation than —
/// the `page_size()`-multiple contract below, which merely returns
/// `false` on violation, never UB. Callers through the safe
/// [`Reservation::recommit`](crate::Reservation::recommit) /
/// [`Reservation::try_recommit`](crate::Reservation::try_recommit)
/// methods are not exposed: both bounds-check `end <= self.len()` before
/// delegating here, so the gap reaches only callers of this free
/// function directly.
/// - `start`/`end` must be multiples of the runtime page size
/// ([`page_size()`](crate::page_size)) with `start <= end` — a violation
/// returns `false` (task #712: an earlier version of this function
/// clamped a contract violation to the WRITE-PERMITTING `true` sentinel,
/// which already caused a real crash — see
/// <https://github.com/PHPCraftdream/sefer-alloc/blob/main/docs/CORRECTNESS_OPEN_ITEMS.md>
/// item 6 for the incident this class of bug produces on Windows).
pub unsafe
/// Fallible [`recommit`]: `Ok(())` if the range is now committed (or was a
/// well-formed no-op), `Err(VmemError::invalid_argument())` if the offsets
/// violated the contract (misaligned, or `start > end`), `Err(VmemError)`
/// carrying the OS cause on genuine commit failure.
///
/// # Safety
///
/// Same contract as [`recommit`], with the bound restated here rather than
/// only referenced (task #1229/F6): this function is the one that actually
/// reaches the backend — its non-mock arm calls `recommit_pages_impl`
/// directly, and [`recommit`] forwards through here — so a caller auditing
/// only this section must see it. `base` must be the
/// [`as_ptr`](crate::Reservation::as_ptr) of a live reservation whose
/// `[base+start, base+end)` range was previously decommitted, and
/// **`end <= reservation.len()`** — passing a larger `end` is undefined
/// behavior (the backend computes `base.add(start)` and nothing from
/// `end`; with `start <= end` the bound is what keeps that offset
/// in-bounds and the OS call's span `[base+start, base+end)` inside the
/// reservation), a strictly worse violation than the
/// `page_size()`-multiple / `start <= end` contract, which merely returns
/// `Err(VmemError::invalid_argument())`, never UB.
pub unsafe