tooling: add mid-body RSP generators to the CPU fuzz test #1402
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1409"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T10:52:30Z.
Change
Adds
--area rsptotools/fuzz_cpu.pyand the CTestcpu_aot_fuzz_rsp, with the same structure ascpu_aot_fuzz_switchesandcpu_aot_fuzz_scalar_fp: its own seed (CPU_FUZZ_RSP_SEED=0xB0D1,CPU_FUZZ_RSP_FUNCTIONS=36), one MASM DLL, one translation built at the preset's optimization and at/O2, a mutant translation, andTIMEOUT 60. Refs #446 (the "mid-body RSP changes" generator from the issue's list; it stays open for x87,pe_mapheader mutation and fault equivalence).cpu_switch_aot. The prologue pushes one to three of RBX, RSI, RDI and R12 to R15 and allocates 16 to 48 bytes, with unwind directives. The body then moves RSP:SUB/ADD RSPby 8 to 48,PUSH/POPof saved registers that hold data, and 1-, 2-, 4- and 8-byte stores, reloads and in-place updates anywhere in the allocation, the caller's home space and what the body allocated. Reloads prefer bytes stored at another RSP, so the same bytes are reached through different displacements. Every reloaded value goes to the output buffer and RAX, and the saved registers' final values are written to the buffer.PUSH/POP; aTEST+Jccwhose two arms move RSP by the same amount in different ways, so the join sees one depth; a mid-bodySUB RSPthat aligns one or two direct calls to frameless callees that no export names; and two RBP-anchored shapes (PUSH RBP,MOV RBP, RSP,.setframe) that mix[RBP+d]and[RSP+d]and end withLEAVEor withADD RSP+POP RBP.ADD RSPorPOP, the callee's home space after a call, and bytes only one branch arm wrote are not read again.refusedmechanism: reload of released bytes (undefined stack byte), join at two depths (stack depth differs at join), read below RSP (stack access below RSP),SUB RSP, 4(unsupported stack adjustment).stale_rsp: every[RSP+d]operand is resolved against the RSP after the prologue's allocation (the firstSUB RSP), as if no laterSUB,ADD,PUSHorPOPhad moved RSP.PUSH,POP,[RBP+d]operands and the frame proof are unchanged, and an operand whose moved bytes would leave the frame array keeps its index, so the mutant never indexes outside the array. The test fails unless it differs from native.docs/experiments.md: one paragraph after the scalar_fp one.Only
AREASandMUTANTSgain an entry; no existing generator,inputs_for,run_checkortranslatecode changes, and the new CMake block sits aftercpu_aot_fuzz_scalar_fp. No open PR touchestools/fuzz_cpu.pyor the fuzz CMake section.Verification
Commit
dd73bde1on origin/main07211552. Windows 11 Enterprise build 26300.9974, Visual Studio Build Tools (MSVC 19.51.36248, ML64 14.51.36248), Windows SDK 26100, Python 3.14.5.ctest --preset dev --no-tests=error -R '^cpu_aot_fuzz_': 7/7 passed (smoke, frames, calls, chains, switches, scalar_fp, rsp), 0 failed, 0 skipped.--preset releaseaftercmake --preset releaseand building the 27cpu_fuzz*targets: 7/7 passed, the same three lines as above.--mutantfails withmutant stale_rsp: 0/11268 mismatches in 0/36 functionsandthe planted translator fault was not detected(exit 1). Passing the mutant as the translation fails at the first mismatch (fuzz_rsp_0, input 1, first differing byte at output offset 24) with the MASM and the reproduction command (exit 1). The five exports the mutant does not change are two anchored ones that read through RBP and three calling ones whose moved operands would leave the frame array.cmake --preset dev -DCPU_FUZZ_RSP_SEED=<seed> -DCPU_FUZZ_RSP_FUNCTIONS=120, then the build and ctest above): seeds0x1,0x2,0xBEEF,0xCCD1each made 75,120 comparisons with no refusal and no mismatch; the mutant differed in 28,393, 30,027, 29,171 and 31,033 of 37,560 calls (97 to 107 of 120 exports).python -B tools/fuzz_cpu.py emit <seed> <count> ... --area <area>before and after the change, compared withdiff -r, byte-identical for leaf0xA902/20 and0xCCD1/96, frames0xF4A3/16 and0xBEEF/128, calls0xCA11/16 and0x1/128, chains0xCA11/16 and0x2/64, switches0x5717/48 and0xBEEF/96, scalar_fp0xF10A/60 and0x2/120 (24 files).tests/docs_links_check.py(16 files, 317 links) andtests/bidi_controls_check.pypass;git diff --checkis clean.Not run: the Ubuntu job and other MSVC versions.
Evidence and follow-up
The fixture is generated MASM from a fixed seed; no third-party inputs. At the default seed the 36 exports have 110 mid-body
SUB RSP, 77 mid-bodyADD RSP, 52PUSHand 13POPafter the prologue, 11 branches, 10 calls, 6LEAVEepilogues, 362[RSP+d]and 72[RBP+d]operands, and 168 reloads; 123 reloads andPOPs read bytes stored at another RSP (at least one in every export). Not generated:MOV RSP, RBP,LEA RSP,ENTER(refused as a dynamic frame), an RBP anchor moved after the prologue, stack arguments, calls in an anchored frame. x87,pe_mapheader mutation and bad-pointer fault equivalence remain open in #446.Checklist
AI-assisted.