cpu: exercise a framed call to a bound leaf in the three-way EXE comparison #441

Manually merged
github merged 15 commits from gh-pr/441/head into gh-pr/441/base 2026-11-26 21:52:13 +00:00
Owner

@⁠R0Y00 on GitHub · 2026-11-22 03:26 UTC · original
R0Y00:codex/exe-bound-frame-chain → main · +1622 −40 · 18 files · 15 commits · merged 2026-11-22 03:32 UTC

Refs #317, #165. Integration after #420, #425 and #430. The EXE entry calls an exported, fixed-frame caller which saves RBX and directly calls a non-exported leaf without unwind data. The leaf range comes from the same EXE's linker map, bound to its image hash. The original and mapped processes run the same PE. The AOT executable links the actual generated entry, caller and leaf.

Local Windows x64, MSVC 19.51.36244, commit e88d4e7:

cmake --build out/verified --target cpu_exe_framed_lifted cpu_exe_original_lifted pe_map
ctest --test-dir out/verified --no-tests=error -R '^cpu_native_exe_(frame_)?chain$' -V

Both tests passed. For selectors 0 and 1, all three runners matched on the 16 import argument bytes, eight output bytes and process exit (0x57 and 0x60d). The control runs the unmodified EXE with the same selector and requires a difference in each field. The test retains missing-provider diagnostics.

**@⁠R0Y00** on GitHub · 2026-11-22 03:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/441) `R0Y00:codex/exe-bound-frame-chain` → `main` · +1622 −40 · 18 files · 15 commits · merged 2026-11-22 03:32 UTC Refs #317, #165. Integration after #420, #425 and #430. The EXE entry calls an exported, fixed-frame caller which saves RBX and directly calls a non-exported leaf without unwind data. The leaf range comes from the same EXE's linker map, bound to its image hash. The original and mapped processes run the same PE. The AOT executable links the actual generated entry, caller and leaf. Local Windows x64, MSVC 19.51.36244, commit e88d4e7: ```powershell cmake --build out/verified --target cpu_exe_framed_lifted cpu_exe_original_lifted pe_map ctest --test-dir out/verified --no-tests=error -R '^cpu_native_exe_(frame_)?chain$' -V ``` Both tests passed. For selectors 0 and 1, all three runners matched on the 16 import argument bytes, eight output bytes and process exit (0x57 and 0x60d). The control runs the unmodified EXE with the same selector and requires a difference in each field. The test retains missing-provider diagnostics.
Follow CALL rel32, and direct JMPs that leave the function, into the same
generated source. A target must be the first byte of an unchained .pdata
entry or a local export in an executable section. Each callee is translated
once as a static fn_<rva> taking RCX, RDX, R8 and R9 and defined before its
first caller. Self-recursion and call cycles are rejected, and a caller is
rejected with the callee's reason when any callee is.

A callee records the low bytes of each argument register it may read before
writing it; the caller must define them at the call. After a call RAX holds
the callee's return width, and the other volatile registers, the flags and
the callee's 32-byte home space at RSP are undefined. Saves into the
caller's own home space and the rest of the frame are kept. RSP must be
8 mod 16 from entry at a call, with the callee's home space below the
return address. A tail jump is checked as a RET and contributes the
callee's return width. Frame escapes and stack arguments stay rejected.
The C++ generated for existing fixtures is unchanged.

cpu_aot_direct_calls: seven MASM exports reaching three callees match the
original over 545 inputs each through the register probe, each callee is
emitted once, and 19 patched copies are refused with their stated reason.

Refs #317
A direct call or tail-jump target is now an entry only when it is the first
byte of a verified primary runtime function (an unchained record with
version 1 or 2 unwind data, a non-empty interval and executable code) or a
non-forwarded code export in an executable section outside every
runtime-function interval. Chained secondary ranges, interior labels,
records with any other unwind header, forwarded exports and data exports
are refused with a reason that names the distinction. Before, a record
start with an unverified unwind header was accepted, and the other cases
were refused later for unrelated reasons.

cpu_aot_call_entries: a fixture with explicit .pdata and .xdata (a chained
range, an exported interior label, a data export and a forwarder) checks
the entry table, matches a call and a tail jump to a primary leaf against
the original, and refuses 8 retargeted or patched copies. The C++ generated
for existing fixtures is unchanged.

Refs #317
After a direct call, only the callee's 32-byte home space at RSP was marked
undefined. The CALL's return address and the callee's own frame lie below
RSP, and #420's frame model lets RSP rise before a call and fall back over
those bytes afterwards, so a reload of them was accepted although natively
it returns the return address. Every frame byte below RSP + 32 at the call
is now undefined.

calls.asm gains below_call, the reproducer from differential fuzzing: it
stores x at entry RSP-0x40, raises RSP for the call and reloads the slot.
The test shows that natively it returns the return address for every
input, and the translator now refuses it with "undefined stack byte at
entry RSP-0x40"; with the old range it was accepted. The C++ generated for
existing fixtures and the corpus results are unchanged.

Refs #317
A direct call or tail-jump target with no unwind entry and no export stays
refused by default, now with the target RVA and the binding it needs. The
invoker may supply --bind-ranges MANIFEST (RANGES in cpu_translation): JSON
with the image's SHA-256 and trusted [start, end) RVAs per function, for
example from source labels in the linker map (tools/range_manifest.py).

The translator checks the hash, that each range lies in executable code
and that no range overlaps another or a runtime function. A bound range
may be entered only at its start; its callee is walked within that range
alone, may not move RSP, call or be an import thunk, and an edge that
leaves the range is refused with what it reaches.

cpu_aot_bound_callees: two leaves without .pdata in a source-built DLL are
refused without the manifest and, bound by the manifest the build writes
from its map, match the original over 545 inputs per export through the
register probe. 16 controls (another build, interior and instruction-
interior targets, out-of-range and overlapping ranges, a range that ends
early, traversal into other functions, ranges and unbound code, a thunk,
and the leaf, stack and recursion rules) are refused. The C++ generated for
existing fixtures and the unbound corpus results are unchanged.

Refs #317
Resolved conflicts:
- README.md: CPU translation row keeps main's source-built EXE sentence and adds the fixed-frame and direct-call sentences.
- tools/form_coverage.py: CPU_FIXTURES keeps main's rotates_shifts entry followed by frame, calls and call_entries.
Brings in origin/main through the #425 merge (5817408).

Resolved conflicts:
- README.md: CPU translation row takes the merged #425 row and keeps this branch's opt-in range manifest wording for callees without an unwind entry.
Brings in 7fb6a9a, which forgets the frame bytes that ADD RSP and POP
leave below RSP, and 5ec180f's merge of main. Conflicts: in Frame the
released ranges are recorded only for ordinary instructions, since calls
and tail jumps keep RSP; README and form_coverage keep this branch's
text and entries; the frame paragraph of docs/experiments.md keeps this
branch's wording and adds #420's sentence on released bytes.
b9935bc marked every frame byte below RSP + 32 undefined at a call,
because the return address and the callee's frame lie below RSP and RSP
could fall back over them. With #420's 7fb6a9a, the bytes that ADD RSP
and POP leave below RSP become unwritten, and no access is below RSP, so
every byte below RSP is already unwritten at a call. Clearing it again
changed nothing; the call step clears the 32-byte home space as before
b9935bc.

below_call is still refused with "undefined stack byte at entry
RSP-0x40", now by the released bytes of its ADD RSP. With 7fb6a9a's
release step disabled it is accepted, so the call step depends on it.

Refs #317
Brings in #420's 7fb6a9a frame lifetime rule and main through 5ec180f,
and 843154f, which clears only the callee's home space at a call again.
The one conflict, in the direct-call paragraph of docs/experiments.md,
keeps this branch's text on bound callees and takes 843154f's sentence
on the bytes a call leaves undefined.
# Conflicts:
#	README.md
#	docs/experiments.md
# Conflicts:
#	README.md
# Conflicts:
#	tools/form_coverage.py
# Conflicts:
#	tools/form_coverage.py
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:52:11 +00:00
github manually merged commit 30a2dcfa71 into gh-pr/441/base 2026-11-26 21:52:13 +00:00
Author
Owner

@⁠grahamster2 on GitHub · 2026-11-22 03:33 UTC · original

Independent run on a second MSVC version: Windows 11 Pro build 26200, VS Build Tools 2026 18.3 (MSVC 19.50.35725, ML64), Windows SDK 10.0.26100, head e88d4e7.

  • cpu_native_exe_chain passed: selector 0 arguments 0303000001000000fdffffff00000000, output 1103000000000000, exit 0x60d; selector 1 arguments 30000000000000000600000000000000, output 3500000000000000, exit 0x57. Original, mapped and AOT runners matched.
  • cpu_native_exe_frame_chain passed with the same values, selectors swapped by the nested leaf (0 -> exit 0x57, 1 -> exit 0x60d). The bypass control differed in every field.
  • Full suite (-E '^(conditional_import_paths|static_exe_intake|bundled_export_forwarders)$'): 160 passed, 0 failed, 3 capability skips of 163 (bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp).
  • Differential call fuzz (frames, direct calls, tail jumps) against this head's cpu_switch_aot.py, seeds 100-119: 644 exports, 534 translated (314 with calls or tails), 110 refused as expected, 0 mismatches.
**@⁠grahamster2** on GitHub · 2026-11-22 03:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/441#issuecomment-7073610084) Independent run on a second MSVC version: Windows 11 Pro build 26200, VS Build Tools 2026 18.3 (MSVC 19.50.35725, ML64), Windows SDK 10.0.26100, head e88d4e7. - `cpu_native_exe_chain` passed: selector 0 arguments `0303000001000000fdffffff00000000`, output `1103000000000000`, exit 0x60d; selector 1 arguments `30000000000000000600000000000000`, output `3500000000000000`, exit 0x57. Original, mapped and AOT runners matched. - `cpu_native_exe_frame_chain` passed with the same values, selectors swapped by the nested leaf (0 -> exit 0x57, 1 -> exit 0x60d). The bypass control differed in every field. - Full suite (`-E '^(conditional_import_paths|static_exe_intake|bundled_export_forwarders)$'`): 160 passed, 0 failed, 3 capability skips of 163 (`bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`). - Differential call fuzz (frames, direct calls, tail jumps) against this head's `cpu_switch_aot.py`, seeds 100-119: 644 exports, 534 translated (314 with calls or tails), 110 refused as expected, 0 mismatches.
This discussion has been locked. Commenting is limited to contributors.
No description provided.