cpu: allow repeated calls to the same IAT slot in cpu_call_aot #219

Manually merged
github merged 1 commit from gh-pr/219/head into gh-pr/219/base 2026-11-26 21:35:11 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 18:32 UTC · original
Vonsek:ag/cpu-repeated-import-call → main · +67 −20 · 6 files · 1 commits · merged 2026-11-21 18:54 UTC

Change

Allow repeated calls to the same IAT slot in tools/cpu_call_aot.py (lift_body / translate), matching the existing support for repeated direct calls to one target.

Previously, lift_body accepted repeated direct calls sharing a single target but rejected any second via_iat call with unexpected additional call, even when both call sites targeted the same IAT slot. It now records ("import", slot_rva, name) on the first IAT call and reuses the single bound dllimport declaration for subsequent calls to the same slot, while rejecting a second call to a different IAT slot or mixed direct/import calls with call to a second target.

Adds:

  • IMPORT_MIX support in tests/cpu/repeat_call.asm, tests/cpu/repeat_import.def, and cpu_repeat_import / cpu_repeat_import_lifted targets in CMakeLists.txt;
  • differential native-vs-lifted checks over all 249 input pairs (return, guarded trace, RBX, RSI) and a distinct-IAT-slot rejection control in tests/cpu/repeat_call_check.py;
  • matching documentation updates in docs/experiments.md.

Verification

Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0, ML64 14.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (pefile==2024.8.26), at commit 331eb8c:

  • Before the change in tools/cpu_call_aot.py, building cpu_repeat_import_lifted fails as expected:
    cmake --build --preset dev --target cpu_repeat_import_lifted
    unexpected additional call at RVA 0x1026
    
  • After the change:
    ctest --preset dev --no-tests=error -R '^cpu_aot_(direct_call|repeated_call|import_call|ordinal_import)$' -V
    1/4 Test #76: cpu_aot_direct_call ..............   Passed    0.16 sec
    2/4 Test #77: cpu_aot_repeated_call ............   Passed    0.16 sec
    3/4 Test #78: cpu_aot_import_call ..............   Passed    1.11 sec
    4/4 Test #79: cpu_aot_ordinal_import ...........   Passed    1.57 sec
    100% tests passed, 0 tests failed out of 4
    
    (cpu_aot_repeated_call output includes mixed direct/import calls and two distinct IAT slots are rejected and 249 repeated-import input pairs match native execution, guarded trace, RBX and RSI)

Evidence and follow-up

All fixtures are assembled from the original MASM source in tests/cpu/repeat_call.asm linked against the source-built cpu_import_provider.dll, and verified differentially against native Windows x64 execution.

Multiple distinct import targets in one caller remain intentionally rejected in this single-binding profile.

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.
**@⁠Vonsek** on GitHub · 2026-11-21 18:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/219) `Vonsek:ag/cpu-repeated-import-call` → `main` · +67 −20 · 6 files · 1 commits · merged 2026-11-21 18:54 UTC ## Change Allow repeated calls to the same IAT slot in `tools/cpu_call_aot.py` (`lift_body` / `translate`), matching the existing support for repeated direct calls to one target. Previously, `lift_body` accepted repeated direct calls sharing a single target but rejected any second `via_iat` call with `unexpected additional call`, even when both call sites targeted the same IAT slot. It now records `("import", slot_rva, name)` on the first IAT call and reuses the single bound `dllimport` declaration for subsequent calls to the same slot, while rejecting a second call to a different IAT slot or mixed direct/import calls with `call to a second target`. Adds: - `IMPORT_MIX` support in `tests/cpu/repeat_call.asm`, `tests/cpu/repeat_import.def`, and `cpu_repeat_import` / `cpu_repeat_import_lifted` targets in `CMakeLists.txt`; - differential native-vs-lifted checks over all 249 input pairs (return, guarded trace, RBX, RSI) and a distinct-IAT-slot rejection control in `tests/cpu/repeat_call_check.py`; - matching documentation updates in `docs/experiments.md`. ## Verification Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0, ML64 14.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (`pefile==2024.8.26`), at commit `331eb8c`: - Before the change in `tools/cpu_call_aot.py`, building `cpu_repeat_import_lifted` fails as expected: ```text cmake --build --preset dev --target cpu_repeat_import_lifted unexpected additional call at RVA 0x1026 ``` - After the change: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_(direct_call|repeated_call|import_call|ordinal_import)$' -V 1/4 Test #76: cpu_aot_direct_call .............. Passed 0.16 sec 2/4 Test #77: cpu_aot_repeated_call ............ Passed 0.16 sec 3/4 Test #78: cpu_aot_import_call .............. Passed 1.11 sec 4/4 Test #79: cpu_aot_ordinal_import ........... Passed 1.57 sec 100% tests passed, 0 tests failed out of 4 ``` (`cpu_aot_repeated_call` output includes `mixed direct/import calls and two distinct IAT slots are rejected` and `249 repeated-import input pairs match native execution, guarded trace, RBX and RSI`) ## Evidence and follow-up All fixtures are assembled from the original MASM source in `tests/cpu/repeat_call.asm` linked against the source-built `cpu_import_provider.dll`, and verified differentially against native Windows x64 execution. Multiple distinct import targets in one caller remain intentionally rejected in this single-binding profile. ## 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.
cpu_call_aot previously allowed repeated direct calls to one target but rejected any second IAT import call even when both call sites targeted the same IAT slot. Allow repeated calls to the same IAT slot (binding the import once) while continuing to reject two distinct IAT slots or mixed direct/import calls. Add an IMPORT_MIX build of tests/cpu/repeat_call.asm (cpu_repeat_import / cpu_repeat_import_lifted), verify all 249 input pairs differentially against native execution in tests/cpu/repeat_call_check.py, add a distinct-IAT-slot rejection control, and update docs/experiments.md.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:35:09 +00:00
github manually merged commit 331eb8c953 into gh-pr/219/base 2026-11-26 21:35:11 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 18:36 UTC · original · edited 2026-11-21 18:39 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:39:02.747405Z 331eb8c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 18:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/219#issuecomment-7067375889) · edited 2026-11-21 18:39 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"331eb8c953f2849ac0589e3ff655fa4c68cc1500","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T18:39:02.747405Z">2026-11-21T18:39:02.747405Z</relative-time> | `331eb8c` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠denn0x on GitHub · 2026-11-21 18:47 UTC · original

For coordination: as requested in review on #223, that branch now carries this PR's commit (rebased onto current main as 4e820ab, otherwise unchanged) with the distinct-direct-callees change on top. The generated cpu_repeat_import source is byte-identical to what this PR's translator produces. The two-slot and mixed-call cases are still rejected, with the messages "call to a second IAT slot" and "mixed import and direct calls". If this PR merges first, #223 reduces to its own commit.

AI-assisted (Claude Code).

**@⁠denn0x** on GitHub · 2026-11-21 18:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/219#issuecomment-7067509974) For coordination: as requested in review on #223, that branch now carries this PR's commit (rebased onto current `main` as `4e820ab`, otherwise unchanged) with the distinct-direct-callees change on top. The generated `cpu_repeat_import` source is byte-identical to what this PR's translator produces. The two-slot and mixed-call cases are still rejected, with the messages "call to a second IAT slot" and "mixed import and direct calls". If this PR merges first, #223 reduces to its own commit. AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
No description provided.