Repository navigation
Commit b5308ca
committed
0.16.0 --- the region a context stands on, measured rather than inferred
`kal_task_stack` reports the stack of the CALLING context. Every context this
implementation creates runs on a region it allocated, so the pair is recorded
when the context begins and returned as it stands; the context the program was
started on has no such record, and its region is measured.
RLIMIT_STACK ALONE IS NOT THE ANSWER, AND BELIEVING IT WAS WOULD BE THE DEFECT
THIS EXISTS TO REMOVE. The limit is a policy, and the floor the kernel enforces
is `mapping_end - RLIMIT_STACK` --- the end of the MAPPING, which is not the
address the program's first instruction sees. `setup_arg_pages` places the
arguments at the top of the mapping and moves the mapping's start down by a
random shift, so a bound computed from a stack pointer begins below the real
floor. Below the real floor is where this system puts the program's own
libraries, so the range would contain another mapping: a caller that laid a
guard at its base, or measured the room above it, would be measuring a region
the kernel will not grow the stack into.
So the mapping is measured with `mincore` --- an exponential-then-bisection
search outward from a local of the caller --- and the floor is the higher of the
two bounds the kernel itself applies: `mapping_end - RLIMIT_STACK`, read with
`prlimit64`, and one guard gap above the nearest mapping below.
BOTH BOUNDS WERE MEASURED ON 6.8.0 BEFORE BEING WRITTEN DOWN. A descending write
stopped at exactly `mapping_end - RLIMIT_STACK`, with one page below it
unwritable and one page above it writable; with one page mapped by the test
itself inside the reservation, the same write stopped at exactly that page's end
plus 256 pages.
THE GUARD GAP IS A KERNEL GLOBAL THIS IMPLEMENTATION CANNOT READ, and the
default is therefore what is applied. A kernel booted with a larger gap stops
the stack above the base reported here --- the region is reported larger than
the kernel will grow it, which is the direction a caller must not be wrong in,
and the reason the default is applied rather than a smaller number. A kernel
booted with a smaller gap is reported a region smaller than it could have, which
is the harmless direction. Both are stated at the code.
An environment that will not answer --- `mincore` refused by a filter, say ---
is reported as the kernel's condition rather than as a range, because a range
derived from a refusal is a range derived from nothing. It is not reported as
"unsupported": clause 6.1 forbids a provided interface to answer that way.
Where the program carries a runtime of its own, that runtime owns the stacks and
is asked instead (`pthread_getattr_np`), which is the same answer a program
above openkal would get for itself. That is the one arrangement in which this
implementation may take a C library's name, and the file says so.
The conformance suite observes containment --- the reported region contains a
local of the context that asked, for the first context and for a started one,
and the answer does not change while the context runs --- and this package's own
tests observe the same property, because it is the one both of the wrong answers
mcpplibs/openkal-musl#49 removed had violated.1 parent 3493ed4 commit b5308ca
5 files changed
Lines changed: 398 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 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 | + | |
48 | 88 | | |
49 | 89 | | |
50 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| |||
189 | 193 | | |
190 | 194 | | |
191 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
192 | 202 | | |
193 | 203 | | |
194 | 204 | | |
| |||
0 commit comments