Commit 662dafc
committed
drop validate fast/full fork; memoize structural body via MSB of __magic
VALIDATION (the headline change)
================================
Drop the heap_validate_self_fast / heap_validate_self split entirely.
The meson option -Dheap_validate_full and the FEATURE_HEAP_VALIDATE_FULL
Config macro go with it. Every dispatch now runs the full structural
validator -- no opt-in for "the safe one".
To keep that fast, the MSB of every magic-bearing object's __magic field
becomes a "structural invariants need re-checking" memo bit shared
across all 11 magic-bearing types (5 allocators: Heap, Slab, Arena,
Page, Budget, Debug; 5 containers: Vec, List, BitVec, Map, Graph; plus
the Graph mutation-epoch path).
Pattern in <Misra/Types.h>:
MAGIC_VALIDATED_BIT (1ULL << 63)
MAGIC_MATCHES(actual, expected) -- bit-stripped comparison
MAGIC_MARK_DIRTY(obj_ptr) -- mutator-side OR-in
MAKE_NEW_MAGIC_VALUE now ANDs against ~MAGIC_VALIDATED_BIT so the
identity payload can NEVER collide with the memo bit regardless of
what string the caller supplies (structural guarantee, not just
a "magic strings start with lowercase" convention).
Per-type validators split: precheck (NULL + magic + memo gate) +
structural body. Memo bit clear -> body skipped. Mutators that change
validator-read fields (data/capacity/allocator/grow paths) MARK_DIRTY;
ones that preserve every invariant by construction (push, pop, single-
element insert/remove without growth, length-only writes that stay
<= capacity) do not. Init macros pre-set the bit so the first call
after init always runs the body.
Tests that planted invalid values directly into struct fields to
trigger deadend assertions are themselves mutators and now call
MAGIC_MARK_DIRTY after the bypass (Str.Type.c x2, List.Deadend.c x5,
BitVec.Foreach.Deadend.c x1). List.Type.c layout test routes its
__magic comparison through MAGIC_MATCHES instead of bare ==.
Benchmark plumbing trimmed to a single tier: README + template + run.py
+ meson all drop the validate-full / validate-fast columns and the
two-tier build steps; Benchmark/meson.build collapses the four
bench-misra-* executables into one foreach.
CONVENTION REVIEW SWEEP
=======================
An 8-subsystem independent review against CODING-CONVENTIONS.md drove
the following cleanups. Findings the reviewer flagged that turned out
to be false positives or stylistic equivalents were left alone with
rationale documented in the commit prose.
Bugs / hardening
----------------
- Http.c: header-count cap (HTTP_REQUEST_HEADERS_MAX = 100) so a
malformed stream cannot grow req->headers without bound. Public
HttpHeaderDeinit / HttpRequestDeinit / HttpResponseDeinit docs aligned
with the LOG_FATAL-on-NULL code. The http_header_deinit callback's
dead NULL guard removed (containers guarantee non-NULL).
- DwarfUnwind.c: CfiVm.code_align retyped from i64 to u64 (CIE ULEB128
cannot be signed) and rejected when source value is non-positive;
every advance_loc multiplication/addition now goes through
MulOverflow64 + AddOverflow64 with UINT64_MAX saturation, so a
crafted CIE that ships a huge ULEB128 can no longer wrap into an
unbounded location advance.
- JSON.h JW_STR: single-evaluation of `s` via UNPL(jw_s) + cache
StrLen result into UNPL(jw_len) so the source expression is only
expanded once and the length is only computed once.
- Map.c map_insert_entry: `(Zstr)entry + offset` byte arithmetic over
opaque entry bytes retyped to `(const u8 *)`.
Architectural
-------------
- KvConfig.c stops reaching into <Misra/Std/Container/Map/Private.h>;
uses the public MapGetFirstPtr macro instead.
- All 9 parsers (Elf, Pe, Pdb, MachO, Dwarf, Http, KvConfig, Dns, JSON)
now declare their snake_case backends in Include/Misra/Parsers/<X>/
Private.h. Public headers expose only PascalCase macros + types.
- Sys helpers path_exists / basename_of / append_dirname deduped from
4 separate copies into Source/Misra/Sys/_Helpers.h.
- parse_ipv4 / parse_ipv6 / hex_nibble_value deduped from Socket.c +
Dns.c into Source/Misra/Sys/_IpParse.h.
- fp_walk + BACKTRACE_MAX_WALK lifted out of the Darwin / Linux arms
of Backtrace.c into a single shared block gated on !PLATFORM_WINDOWS
&& (gcc||clang).
- Sys/Dns.c random_query_id drops the file-local LCG global; the
non-direct-syscall fallback now defers to the project's existing
Prng16() (the documented process-lifetime random singleton).
Naming / drift
--------------
- SYS_DIR_ENTRY_TYPE_* / SYS_PROC_STATUS_* / SYS_ERROR_STR_MAX_LENGTH:
dropped the SYS_ prefix (convention reserves SYS_ for syscall-number
constants in _Syscall.h).
- All freestanding / start / syscall internal helpers lose the misra_
prefix: misra_sysN -> direct_sysN, misra_envp -> envp_global,
misra_start_c -> linux_start_c, misra_start -> windows_start
(meson /ENTRY: updated to match), g_misra_start_cmdline ->
g_start_cmdline, g_misra_start_argv -> g_start_argv,
misra_freestanding_size_t -> freestanding_size_t,
misra_security_failure -> security_failure,
misra_stdio_common_vsprintf_stub -> stdio_common_vsprintf_stub,
misra_getenv_stub -> getenv_stub, MISRA_DARWIN_SC -> DARWIN_SC.
Bin/Beam.c updated to match the renames.
- Pdb.c kMsfMagic7 (foreign k-prefix) -> MSF_MAGIC_7; also retyped
char[32] -> u8[32] since it's an on-disk byte signature.
- Sys/Proc.c sys_proc_read_internal -> proc_read_internal; STDIN_FILENO
/ STDOUT_FILENO / STDERR_FILENO get literal 0/1/2 instead of the
libc FILENO(stdin)/(stdout)/(stderr) macros that were pulling libc
FILE* into the freestanding plumbing.
- Pdb.c + DwarfInfo.c qsort comparators: int return -> i32, (a,b)
parameters -> (lhs,rhs) to match the GenericCompare contract.
Build / config cleanup
----------------------
- meson_options.txt: dead `iter` option (force-pinned to true) removed
along with the FEATURE_ITER macro emit and the install-subdir-
excludes branches.
- meson.build: dead FEATURE_PARSER_ELF / FEATURE_PARSER_PE set10 emits
removed (those macros were never referenced from any C source); a
comment line that referenced a specific commit hash was deleted.
- _StartWin.c's file: banner normalised to the lowercase short shape
used by the other 184 source files.
- All header _Generic dispatch in Sys/Socket.h, Sys/Dns.h,
Sys/MachoCache.h, Sys/PdbCache.h, Parsers/Dns.h converted from
function-pointer-selection style to the canonical inlined-arm-body
shape used by Dir.h.
Memo-bit review followups
-------------------------
- Tests/Std/List.Type.c:21: __magic comparison now routes through
MAGIC_MATCHES.
- Slab.c slab_finalize_runtime_consts: ends with SLAB_MARK_DIRTY so the
routine is self-contained against future call paths.
- Three unnecessary MAGIC_MARK_DIRTY calls dropped where the transition
preserves every structural invariant by construction (Arena.c chunk-
add + Reset, List.c insert_into_list, Vec.c reduce_space_vec
length==0 branch).
False-positive review findings explicitly NOT applied
-----------------------------------------------------
- "DwarfInfo.c:444 AddOverflow64 polarity is inverted." Math.h:178-182
documents AddOverflow64 returning true on SUCCESS; the assignment in
DwarfInfo.c:444 is correct.
- "BitVec is missing MARK_DIRTY in Resize/Clear/Remove*/Shift*/etc."
Those only change length, not data/capacity/byte_size; the
structural validator memoization pattern (matching Vec) only flips
dirty when validator-read fields change.
- "DwarfUnwind.c:259 discards decode_eh_ptr failure." The trailing
IterMustMove resets the cursor regardless.
- "Graph PascalCase functions in Access.h/Ops.h are wrappers." The
CODING-CONVENTIONS skeleton's "Public API: PascalCase" rule applies;
these are public API, not alias wrappers around a backend.
- "PeSection.name/MachoSection.name should be u8[N]." They are NUL-
terminated string fields, used via ZstrCompare; char[N] is correct.
87 files changed, 1428 insertions(+), 1333 deletions(-)1 parent e6c3217 commit 662dafc
87 files changed
Lines changed: 1428 additions & 1333 deletions
File tree
- Benchmark
- Scripts
- Bin
- Include/Misra
- Parsers
- Dns
- Dwarf
- Elf
- Http
- KvConfig
- MachO
- Pdb
- Pe
- Std
- Allocator
- Container
- BitVec
- Graph
- List
- Map
- Str
- Vec
- Sys
- Source/Misra
- Parsers
- Std
- Allocator
- Container
- Sys
- Tests/Std
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 17 | + | |
| 18 | + | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | 51 | | |
54 | 52 | | |
55 | 53 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
71 | 69 | | |
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
76 | 74 | | |
77 | 75 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
81 | 79 | | |
82 | 80 | | |
83 | 81 | | |
84 | 82 | | |
85 | 83 | | |
86 | 84 | | |
87 | 85 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
97 | 95 | | |
98 | 96 | | |
99 | 97 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
107 | 105 | | |
108 | 106 | | |
109 | 107 | | |
110 | 108 | | |
111 | 109 | | |
112 | 110 | | |
113 | | - | |
114 | 111 | | |
115 | 112 | | |
116 | | - | |
| 113 | + | |
117 | 114 | | |
118 | 115 | | |
119 | 116 | | |
120 | | - | |
121 | | - | |
122 | 117 | | |
123 | 118 | | |
124 | 119 | | |
125 | 120 | | |
126 | 121 | | |
127 | 122 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 123 | | |
141 | 124 | | |
142 | 125 | | |
| |||
148 | 131 | | |
149 | 132 | | |
150 | 133 | | |
151 | | - | |
| 134 | + | |
152 | 135 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
| 62 | + | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | | - | |
68 | | - | |
69 | 66 | | |
70 | 67 | | |
71 | 68 | | |
72 | 69 | | |
73 | 70 | | |
74 | 71 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 72 | | |
88 | 73 | | |
89 | 74 | | |
| |||
0 commit comments