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

Merged
Vonsek merged 1 commit from upstream-pr/219 into main 2026-11-21 18:54:24 +00:00
Vonsek commented 2026-11-21 18:32:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T18:32:48Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532790372 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/219). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T18:32:48Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:41:52 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:47:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:36:13Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067375889 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/219#issuecomment-7067375889). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T18:36:13Z. --- <!-- 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>
denn0x commented 2026-11-24 06:47:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-21T18:47:02Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067509974 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/219#issuecomment-7067509974). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-21T18:47:02Z. --- 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).
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!216
No description provided.