cpu: bind call targets without unwind data through an opt-in range manifest #424

Merged
grahamster2 merged 13 commits from upstream-pr/430 into main 2026-11-22 03:31:41 +00:00
grahamster2 commented 2026-11-22 01:45:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-22T01:45:36Z.


Stacked on #425 and #420; review only commit 4b2e125 (the merges of #425, #420 and main on top of it change no code of this PR; 01fb256 brings in #425's 843154f and #420's head 5ec180f).

Refs #317 (step 2, follow-up). Narrowed, as requested in the review, from heuristic acceptance to opt-in bindings. #425's entry boundary stays the default.

Change

Default. A direct call or tail-jump target with no unwind entry and no export is still refused. The message now gives the target RVA and the binding it needs:

call target 0x1000 is not a function entry (no runtime-function entry or export; a range binding [start, end) for this image (--bind-ranges) is needed)

Tail jumps that used to stop at edge outside owned ranges for such a target now get the same message.

Opt-in binding. The invoker passes cpu_switch_aot.py --bind-ranges MANIFEST, or RANGES <file> in the CMake function cpu_translation. The manifest is JSON:

{"image_sha256": "...", "functions": [{"name": "bare_mix", "start": "0x1000", "end": "0x100b"}]}

tools/range_manifest.py IMAGE MAP OUT NAME... writes it from the source labels an MSVC /MAP file lists: the function's symbol for start, its NAME_end label for end, and the image's SHA-256. PDB function symbols would be another source; they are not read yet.

The translator checks the manifest before translating anything:

  • the SHA-256 matches the image;
  • each range lies in the file-backed bytes of an executable section;
  • no range overlaps another binding or any .pdata interval.

Then, for each call or tail jump:

  • A bound range may be entered only at its start. An interior target, including an instruction interior, is refused and the message names the range it lies in.
  • The bound callee is walked within its own [start, end) only. An edge that leaves it is refused, and the message names what the edge reaches: another function's unwind interval, another bound range, or unbound code. Code outside the range is never decoded as part of the callee.
  • Kept checks: the callee may not move RSP or call (a function without unwind data is a leaf), may not be an import thunk, and the self- and mutual-recursion rules apply.

Verification

Environment: Windows 11 Pro build 26200, VS Build Tools 2026 18.3 / MSVC 19.50.35725, ML64, Windows SDK 10.0.26100, Python 3.12.

ctest --preset dev --no-tests=error -R '^cpu_aot_bound_callees$' -V: passed. Everything below uses the same source-built DLL, tests/cpu/bare_calls.asm linked with /MAP. Its two leaves are declared without FRAME, so they have no .pdata entry, and neither is exported.

  • Refused by default: without a manifest, call_bare's call and tail_bare's tail jump are refused, each with its target RVA and the binding message.

  • Matches native with the binding: the build writes the manifest from the map and translates with it. 3 exports x 545 inputs = 1,635 calls per side. The original and the translation match a Python reference on the defined return bytes, guarded trace, RBX and RSI. Each bound callee is emitted once, and tail_bare reports width 1.

  • Interior label: bare_mix_inner is aligned, and MOV, SUB and RET from it translate. Bound as its own range, a call to it translates. With bare_mix's range bound, the same call is refused. So the refusal comes from the binding rule alone.

  • 16 controls, each refused with its stated reason:

    Control Refusal
    manifest applied to a copy with a different TimeDateStamp (another build) range binding is for another image
    call to the aligned interior label inside the bound range bare_mix [0x1000, 0x100b), not its start
    call into an instruction interior inside the bound range bare_mix
    tail jump into the other leaf's interior jump target ... inside the bound range bare_low
    range in .rdata ... is not inside executable code
    range past the end of .text ... is not inside executable code
    range overlapping a framed function overlaps the runtime function at 0x1016
    two overlapping ranges range binding bare_low ... overlaps range binding bare_mix
    range that ends before the leaf's RET edge outside owned ranges at RVA 0x100a: outside the bound range bare_mix
    bound leaf jumping into a framed function another function's unwind interval
    bound leaf jumping into the other bound range jump target 0x1004 ... inside the bound range bare_mix
    bound leaf jumping into unbound code jump target 0x1010 ... a range binding ... is needed
    bound JMP [RIP+slot] thunk bound function fake_thunk ... is an import thunk
    bound leaf patched to call call in a function without unwind data
    bound leaf patched to PUSH/POP stack change in a function without unwind data
    bound leaf patched to call itself self-recursion

    Every control except the first rehashes the manifest for the patched copy, so only the intended check can fail.

  • Mutation checks, each planted and restored:

    Planted bug Result
    hash not compared wrong-build control accepted
    any address in a range counts as its start interior-label control accepted
    bound callee walked over its whole section early-end control accepted
    range may overlap a runtime function overlap control accepted
    bindings may overlap each other still refused by a later check (the other range as a foreign interval); the test fails on the message
    executable-bounds check removed still refused (the target is then unbound); the test fails on the message
    thunk check removed still refused (unsupported control flow); the test fails on the message
    leaf rule removed still refused (call-site alignment); the test fails on the message
  • The generated C++ for every earlier fixture of this translator is byte-identical to #425's head (843154f). That covers the jump-table, addr32, entry-order, narrow and fourth-argument fixtures, #420's cpu_frame, cpu_calls and cpu_call_entries. cpu_bare_calls is byte-identical to this PR's previous head (5f7a0e0).

  • Full Debug suite, run serially: ctest --preset dev --no-tests=error -E '^(conditional_import_paths|static_exe_intake|bundled_export_forwarders)$'. At 01fb256: 154 passed, 3 capability skips (bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp). I did not run the three intake tests. docs_links, tests/bidi_controls_check.py and tests/form_coverage_check.py passed.

  • Corpus, against #425's translator: a Release (/O2) build of this branch, covering every .pdata entry of 97 readable non-generated images, with each unique function body translated with four arguments and no manifest.

    • Translated: 97 of 2,346 before and after. None is lost or gained.
    • Candidates for a binding: 872 functions are refused first at a target that needs one (808 calls and 64 tail jumps). Counting a refused callee's innermost reason, the figure is 974.
    • Targets: they reach 421 distinct target RVAs. 129 of them are shaped like import thunks, which a binding would not admit (#343).
    • These are candidates only. No binding was supplied for them.

Evidence and follow-up

tests/cpu/bare_calls.asm, bare_calls.def, bare_calls_check.py and tools/range_manifest.py are original sources written for this PR (MIT). The DLL, its map and its manifest are produced in the build, and no binaries are added. bare_calls is classified in tools/form_coverage.py. Docs: the jump-table section of docs/experiments.md and the README CPU row.

For review:

  1. Manifest format and provenance. The file is JSON with a hash and [start, end) RVAs. The fixture's evidence is the linker map's source labels, a public NAME and NAME_end per function. A PDB reader could produce the same file later.
  2. No RSP movement or call in a bound callee. A bound callee may not move RSP or call, because a function without unwind data must be a leaf. The rule does not apply to exports translated by name, which keep their existing behaviour.
  3. When the manifest is checked. The whole manifest is checked once per translation. An invalid entry refuses the translation, even when the invalid entry is never reached.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536993047 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/430). Originally posted by [grahamster2](https://github.com/grahamster2) on 2026-11-22T01:45:36Z. --- Stacked on #425 and #420; review only commit 4b2e125 (the merges of #425, #420 and main on top of it change no code of this PR; 01fb256 brings in #425's 843154f and #420's head 5ec180f). Refs #317 (step 2, follow-up). Narrowed, as requested in the review, from heuristic acceptance to opt-in bindings. #425's entry boundary stays the default. ## Change **Default.** A direct call or tail-jump target with no unwind entry and no export is still refused. The message now gives the target RVA and the binding it needs: > call target 0x1000 is not a function entry (no runtime-function entry or export; a range binding [start, end) for this image (--bind-ranges) is needed) Tail jumps that used to stop at `edge outside owned ranges` for such a target now get the same message. **Opt-in binding.** The invoker passes `cpu_switch_aot.py --bind-ranges MANIFEST`, or `RANGES <file>` in the CMake function `cpu_translation`. The manifest is JSON: ```json {"image_sha256": "...", "functions": [{"name": "bare_mix", "start": "0x1000", "end": "0x100b"}]} ``` `tools/range_manifest.py IMAGE MAP OUT NAME...` writes it from the source labels an MSVC `/MAP` file lists: the function's symbol for `start`, its `NAME_end` label for `end`, and the image's SHA-256. PDB function symbols would be another source; they are not read yet. The translator checks the manifest before translating anything: - the SHA-256 matches the image; - each range lies in the file-backed bytes of an executable section; - no range overlaps another binding or any `.pdata` interval. Then, for each call or tail jump: - A bound range may be entered only at its start. An interior target, including an instruction interior, is refused and the message names the range it lies in. - The bound callee is walked within its own `[start, end)` only. An edge that leaves it is refused, and the message names what the edge reaches: another function's unwind interval, another bound range, or unbound code. Code outside the range is never decoded as part of the callee. - Kept checks: the callee may not move RSP or call (a function without unwind data is a leaf), may not be an import thunk, and the self- and mutual-recursion rules apply. ## Verification Environment: Windows 11 Pro build 26200, VS Build Tools 2026 18.3 / MSVC 19.50.35725, ML64, Windows SDK 10.0.26100, Python 3.12. `ctest --preset dev --no-tests=error -R '^cpu_aot_bound_callees$' -V`: passed. Everything below uses the same source-built DLL, `tests/cpu/bare_calls.asm` linked with `/MAP`. Its two leaves are declared without `FRAME`, so they have no `.pdata` entry, and neither is exported. - **Refused by default:** without a manifest, `call_bare`'s call and `tail_bare`'s tail jump are refused, each with its target RVA and the binding message. - **Matches native with the binding:** the build writes the manifest from the map and translates with it. 3 exports x 545 inputs = 1,635 calls per side. The original and the translation match a Python reference on the defined return bytes, guarded trace, RBX and RSI. Each bound callee is emitted once, and `tail_bare` reports width 1. - **Interior label:** `bare_mix_inner` is aligned, and `MOV`, `SUB` and `RET` from it translate. Bound as its own range, a call to it translates. With `bare_mix`'s range bound, the same call is refused. So the refusal comes from the binding rule alone. - 16 controls, each refused with its stated reason: | Control | Refusal | |---|---| | manifest applied to a copy with a different `TimeDateStamp` (another build) | `range binding is for another image` | | call to the aligned interior label | `inside the bound range bare_mix [0x1000, 0x100b), not its start` | | call into an instruction interior | `inside the bound range bare_mix` | | tail jump into the other leaf's interior | `jump target ... inside the bound range bare_low` | | range in `.rdata` | `... is not inside executable code` | | range past the end of `.text` | `... is not inside executable code` | | range overlapping a framed function | `overlaps the runtime function at 0x1016` | | two overlapping ranges | `range binding bare_low ... overlaps range binding bare_mix` | | range that ends before the leaf's `RET` | `edge outside owned ranges at RVA 0x100a: outside the bound range bare_mix` | | bound leaf jumping into a framed function | `another function's unwind interval` | | bound leaf jumping into the other bound range | `jump target 0x1004 ... inside the bound range bare_mix` | | bound leaf jumping into unbound code | `jump target 0x1010 ... a range binding ... is needed` | | bound `JMP [RIP+slot]` thunk | `bound function fake_thunk ... is an import thunk` | | bound leaf patched to call | `call in a function without unwind data` | | bound leaf patched to `PUSH`/`POP` | `stack change in a function without unwind data` | | bound leaf patched to call itself | `self-recursion` | Every control except the first rehashes the manifest for the patched copy, so only the intended check can fail. - Mutation checks, each planted and restored: | Planted bug | Result | |---|---| | hash not compared | wrong-build control accepted | | any address in a range counts as its start | interior-label control accepted | | bound callee walked over its whole section | early-end control accepted | | range may overlap a runtime function | overlap control accepted | | bindings may overlap each other | still refused by a later check (the other range as a foreign interval); the test fails on the message | | executable-bounds check removed | still refused (the target is then unbound); the test fails on the message | | thunk check removed | still refused (`unsupported control flow`); the test fails on the message | | leaf rule removed | still refused (call-site alignment); the test fails on the message | - The generated C++ for every earlier fixture of this translator is byte-identical to #425's head (843154f). That covers the jump-table, `addr32`, entry-order, narrow and fourth-argument fixtures, #420's `cpu_frame`, `cpu_calls` and `cpu_call_entries`. `cpu_bare_calls` is byte-identical to this PR's previous head (5f7a0e0). - Full Debug suite, run serially: `ctest --preset dev --no-tests=error -E '^(conditional_import_paths|static_exe_intake|bundled_export_forwarders)$'`. At 01fb256: 154 passed, 3 capability skips (`bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`). I did not run the three intake tests. `docs_links`, `tests/bidi_controls_check.py` and `tests/form_coverage_check.py` passed. - Corpus, against #425's translator: a Release (`/O2`) build of this branch, covering every `.pdata` entry of 97 readable non-generated images, with each unique function body translated with four arguments and no manifest. - **Translated:** 97 of 2,346 before and after. None is lost or gained. - **Candidates for a binding:** 872 functions are refused first at a target that needs one (808 calls and 64 tail jumps). Counting a refused callee's innermost reason, the figure is 974. - **Targets:** they reach 421 distinct target RVAs. 129 of them are shaped like import thunks, which a binding would not admit (#343). - These are candidates only. No binding was supplied for them. ## Evidence and follow-up `tests/cpu/bare_calls.asm`, `bare_calls.def`, `bare_calls_check.py` and `tools/range_manifest.py` are original sources written for this PR (MIT). The DLL, its map and its manifest are produced in the build, and no binaries are added. `bare_calls` is classified in `tools/form_coverage.py`. Docs: the jump-table section of `docs/experiments.md` and the README CPU row. For review: 1. **Manifest format and provenance.** The file is JSON with a hash and `[start, end)` RVAs. The fixture's evidence is the linker map's source labels, a public `NAME` and `NAME_end` per function. A PDB reader could produce the same file later. 2. **No RSP movement or call in a bound callee.** A bound callee may not move RSP or call, because a function without unwind data must be a leaf. The rule does not apply to exports translated by name, which keep their existing behaviour. 3. **When the manifest is checked.** The whole manifest is checked once per translation. An invalid entry refuses the translation, even when the invalid entry is never reached. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted (Claude Code)._
upstream-sync closed this pull request 2026-11-24 06:43:00 +00:00
R0Y00 commented 2026-11-24 06:48:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T01:57:00Z.


Please narrow the top commit to opt-in bindings, or leave #425’s boundary in place. A direct call/jump can land on an aligned interior label that decodes cleanly, never adjusts RSP and runs to RET. Even together with a missing .pdata entry, those observations do not establish a distinct function. Unbound corpus hits can be counted as candidates only.

For an opt-in path, the caller supplies trusted start and end evidence for this exact image. A source-label [start,end) manifest bound to the image hash is sufficient; a matching link-time PDB function symbol and length is another source. PDB parsing can wait. Verify image identity, executable bounds, overlaps and all reachable edges. Reject instruction-interior targets and entry into or traversal across another known function or an unauthorized range. Keep the existing leaf, stack, import-thunk and recursion checks. When evidence is missing, report the target RVA and which binding is needed.

On the same source-built DLL, show that an actual no-unwind leaf is refused by default and matches native execution with the right binding. Include an aligned interior label with a valid path to RET that still gets refused, plus wrong-build and out-of-range bindings. Please rebase after #425; #420 and #425 can proceed independently of this change.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7072567839 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/430#issuecomment-7072567839). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T01:57:00Z. --- Please narrow the top commit to opt-in bindings, or leave #425’s boundary in place. A direct call/jump can land on an aligned interior label that decodes cleanly, never adjusts RSP and runs to RET. Even together with a missing `.pdata` entry, those observations do not establish a distinct function. Unbound corpus hits can be counted as candidates only. For an opt-in path, the caller supplies trusted start **and end** evidence for this exact image. A source-label `[start,end)` manifest bound to the image hash is sufficient; a matching link-time PDB function symbol and length is another source. PDB parsing can wait. Verify image identity, executable bounds, overlaps and all reachable edges. Reject instruction-interior targets and entry into or traversal across another known function or an unauthorized range. Keep the existing leaf, stack, import-thunk and recursion checks. When evidence is missing, report the target RVA and which binding is needed. On the same source-built DLL, show that an actual no-unwind leaf is refused by default and matches native execution with the right binding. Include an aligned interior label with a valid path to RET that still gets refused, plus wrong-build and out-of-range bindings. Please rebase after #425; #420 and #425 can proceed independently of this change.
grahamster2 commented 2026-11-24 06:48:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-22T02:16:09Z.


Narrowed to opt-in bindings, as you asked, and rebased onto #425's updated head (165a66f). #425's boundary remains the default: an unbound target with no unwind entry is refused, and the message gives the target RVA and says a range binding is needed. --bind-ranges takes a [start, end) manifest bound to the image's SHA-256, which the fixture's build writes from source labels in the linker map. The translator checks the hash, executable bounds, overlaps with other bindings and with .pdata, entry only at the start of a range, and every edge of the callee staying inside its range. The leaf, stack, thunk and recursion checks are unchanged. On the same DLL, the no-unwind leaf is refused by default and matches native with the binding (1,635 calls). An aligned interior label that translates when bound on its own is refused, and so are a wrong-build and out-of-range bindings. With overlap and traversal controls, that makes 16 controls; 4 of the 8 mutations get their control accepted, and the other 4 make it fail on the expected message. The corpus is unchanged without a manifest (97 of 2,346), and unbound hits are reported only as candidates: 872 functions, 421 targets.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7072803732 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/430#issuecomment-7072803732). Originally posted by [grahamster2](https://github.com/grahamster2) on 2026-11-22T02:16:09Z. --- Narrowed to opt-in bindings, as you asked, and rebased onto #425's updated head (165a66f). #425's boundary remains the default: an unbound target with no unwind entry is refused, and the message gives the target RVA and says a range binding is needed. `--bind-ranges` takes a `[start, end)` manifest bound to the image's SHA-256, which the fixture's build writes from source labels in the linker map. The translator checks the hash, executable bounds, overlaps with other bindings and with `.pdata`, entry only at the start of a range, and every edge of the callee staying inside its range. The leaf, stack, thunk and recursion checks are unchanged. On the same DLL, the no-unwind leaf is refused by default and matches native with the binding (1,635 calls). An aligned interior label that translates when bound on its own is refused, and so are a wrong-build and out-of-range bindings. With overlap and traversal controls, that makes 16 controls; 4 of the 8 mutations get their control accepted, and the other 4 make it fail on the expected message. The corpus is unchanged without a manifest (97 of 2,346), and unbound hits are reported only as candidates: 872 functions, 421 targets.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!424
No description provided.