urt-rs / docs /research /AREA_FLOODING.md
nmarshall's picture
Recover snapshot area mask lifecycle and message arguments
10b0261
|
Raw History Blame Contribute Delete
6.87 kB
# Area flooding, epoch guards and area-bit output
Reproduce: `python3 scripts/analyze_area_flooding.py`. Validate: `python3 scripts/test_area_flooding.py`. Evidence: [area-flooding.json](area-flooding.json), with hash-verified graphs for four functions in both Linux ELF64 engines. This extends [portal counter findings](BSP_REFERENCES.md).
These are bounded synthetic instruction compositions, not original executable/callee execution. PUSH traffic is explicitly replaced with NOPs; supplied stack windows hold local words. Recursive boundaries evaluate a separate synthetic graph, carry its memory changes back and restore the supplied caller registers before continuing. They do not validate real ABI clobbers, stack frames or exception propagation. Execution stops before epilogues and error calls. Memset effects in the area-bit branch are supplied separately. Counts, matrices, labels/stamps and buffers are fixtures, not loaded maps.
## FLOOD-001 — Component generation and portal-to-label composition (RE-329)
CM_FloodAreaConnections increments the flood epoch, scans area indices in ascending order, and starts successive labels at one. Each unvisited area starts a new label. The flood graph follows matrix entries whose signed value is **greater than zero**; zero and tested negative entries do not connect areas. Native area records contain label +0 and epoch stamp +4, at stride eight.
The collector composes all instructions reached by 108 paired fixtures: area counts 0/1/2/3/4/8/12/16/32 and six symmetric matrix families (empty, chain, clique, star, groups of three, and negative off-diagonal weights). Positive edges use counter two. Outputs agree with an independent breadth-first component oracle, despite the native graph's unrolled depth-first/recursive walk. Initial epoch 40 becomes 41 and every sampled real area receives stamp 41. A zero-area composition still increments the epoch.
The 32-area chain/clique fixtures reach recursive call boundaries, with maximum synthetic nesting depth four. The collector bounds nesting at sixteen and each aggregate composition at 200,000 evaluated instructions. Larger traces retain instruction counts/hashes, requested recursive arguments/sites and maximum depth; small fixtures retain addresses. This samples complete output compositions for these families, not every possible branch or malformed graph.
Eighteen paired portal-update steps then connect CM_AdjustAreaPortalState to actual synthetic flood instructions. A four-area fixture starts disconnected, opens the same pair twice, closes it once, opens a chain through other areas, closes edges and opens/closes a self-pair. Each update carries matrix and area memory into the next step. The independent oracle checks every matrix, label, stamp and epoch. The duplicate open survives one close; the second close splits the first area away. The self-pair moves its diagonal counter 0→2→0. These valid sampled transitions establish bounded update-to-label behavior; error handling and original runtime remain open.
## FLOOD-002 — Revisit consistency and epoch aliasing (RE-330)
Forty-eight paired entry probes exercise CM_FloodArea_r with supplied current epoch, previous stamp, previous label and requested label:
| Entry state | Observed behavior |
| --- | --- |
| Stamp differs from current epoch | Write requested label/current stamp, then walk |
| Stamp matches and label matches | Return without relabeling |
| Stamp matches and label differs | Stop at Com_Error request, `FloodArea_r: reflooded` |
The error text appears at the retained unrolled consistency-check sites as well, but only the entry mismatch branch is isolated with error fixtures. Complete mismatch coverage across all unrolled/reentrant paths remains open.
Twenty-four paired outer-epoch probes cover raw epochs 0/40/0xfffffffe/0xffffffff and stamps 0/1/0xffffffff. The native ADD increments modulo 2^32. When a supplied stamp already equals the incremented epoch, the existing label 77 is retained. In particular, 0xffffffff→0 with stamp zero skips relabeling. This characterizes native word arithmetic and a local aliasing condition; it does not establish that such stale/wrapped states occur in a legal game session, or prescribe target recovery behavior.
## FLOOD-003 — Area-bit packing and existing buffer state (RE-331)
One hundred sixty-eight paired output probes cover area counts 0/1/7/8/9/16/17, area -1/0, cm_noAreas words 0/1/7 and buffers seeded with 0/0xa0. The returned byte length is `(count + 7) >> 3` for these nonnegative counts.
For ordinary area zero, supplied labels `i % 3 + 1` select matching-label areas. Bit `i % 8` goes into byte `i / 8`. The native instruction is byte OR: existing buffer bits are retained, including bits for nonmatching areas. This function does not clear the buffer on the ordinary path. Initialization/union behavior must therefore be recovered from callers before implementing snapshot output.
Area -1 or nonzero cm_noAreas requests memset(buffer, 255, returned length). The collector stops there and supplies the requested byte writes before resuming the return-length instructions. This sets unused tail bits too; the regular path only ORs qualifying area bits. Canaries before and after the output remain unchanged in every sampled fixture.
The ordinary path reads the requested area's label before its area-count loop guard. The count-zero/area-zero fixture explicitly provides that record; it is not proof that an empty real map can safely call the function. This function's local graph does not validate the requested area's index. Negative values other than -1, count overflow, undersized buffers and complete caller bounds remain open.
## Validation and follow-up
Eight independent tests cover component labels/stamps and recursion use, mutable portal sequences, revisit errors, modular epoch/stamp aliasing, bit packing/OR/canaries/supplied memset, paired outcomes and prior-state slots. Restricted evaluator additions cover signed greater-than, 32-bit shifts, count masking/zero-count flag preservation and byte OR/alias preservation. Unknown flags and unsupported operations remain errors.
RE-332: cover asymmetric/malformed matrices, all unrolled consistency errors and allocator/reset/stamp/epoch lifetime; recover portal writers and error/serialization semantics; connect area-bit buffer initialization/union/inversion and snapshot consumers; compose connectivity/PVS with generated labels and real BSP variants; obtain original-runtime and all-platform differential fixtures. Complete collision geometry and Rust/Bevy/Solari rendering remain open.
Follow-up: [snapshot area-mask lifecycle](SNAPSHOT_AREAS.md) composes native reset/union/complement and captures serialization spans. Complete frame/viewpoint/codec/client/renderer/runtime behavior remains open under RE-332/RE-336.