Pin call translator signed imm8, import name case, link-name and ASCII checks #1009

Merged
Leyukaka merged 2 commits from upstream-pr/1016 into main 2026-11-23 21:43:02 +00:00
Leyukaka commented 2026-11-23 21:21:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-23T21:21:36Z.


Change

This closes four gaps in the test coverage of tools/cpu_call_aot.py. Each gap is shown by a small mutation of the translator that still passes the whole ^cpu_ suite on main at ca52bbc. The translator does not change; the native fixture DLL stays the reference for the differential cases.

# Change Mutation it covers Test that pins it
1 call_pair.asm: add rax, 11 in mix_args becomes sub rax, -11, written as the bytes 48 83 E8 F5 so the signed-imm8 encoding is pinned whatever the assembler picks (same result, same length) the imm8 of sub/add r64, imm8 read as unsigned cpu_aot_call_pair
2 call_pair_check.py: the mov r8, rsi reload before the second call replaced with mov rsi, rsi is refused (undefined register) R8 kept live across the first call cpu_aot_call_pair (already caught on main by cpu_aot_repeated_call; added here for the two-callee caller)
3 import_check.py: the modelled import descriptor names the provider DLL with different letter case and still binds the DLL name compared case-sensitively cpu_aot_import_call
4 import_check.py: a named import given an explicit link name is refused (unexpected link name for named import) the stray link name silently dropped cpu_aot_import_call
5 import_check.py: an ordinal import bound with the link name mé is refused (unsupported C import name) the ASCII requirement dropped from the C identifier check cpu_aot_ordinal_import

The sub rax, -11 form keeps the native return value and the Python reference unchanged. The patched image is only translated, never executed, and the import models are only passed to resolve_import. docs/experiments.md describes the R8 control, the signed-imm8 form and the non-ASCII link name.

Verification

On a8d5f062 (based on main at ca52bbc), Windows 11, MSVC 14.44.35207, Python 3.14:

ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|direct_calls?|import_calls?|import_tail_jump|ordinal_import)$'
python -B tests/docs_links_check.py

All 7 tests pass, and the docs check passes.

Each mutation was applied to tools/cpu_call_aot.py one at a time and the project was rebuilt. With main at ca52bbc, the whole ^cpu_ suite passed under mutations 1, 3, 4 and 5, and cpu_aot_repeated_call failed under mutation 2. With this branch, at least one of the seven tests above fails under each of the five; the last column names the check written for it. With the unmutated translator everything passes.

The five edits to tools/cpu_call_aot.py, numbered as in the table:

  1. imm = struct.unpack_from("b", body, pos + 3)[0] -> "B"
  2. available.intersection_update({"rbx", "rsi"}) -> {"rbx", "rsi", "r8"}
  3. if dll.casefold() != provider.name.casefold() or symbol != name: -> if dll != provider.name or symbol != name:
  4. the raise ValueError(f"unexpected link name for named import {identity}") after if not by_ordinal and link_name is not None: -> link_name = None
  5. if not identifier.isascii() or not identifier.isidentifier(): -> if not identifier.isidentifier():

Evidence and follow-up

No new fixture file: the sub rax, -11 bytes are in tests/cpu/call_pair.asm, and the other cases are a byte patch or import models inside the checks. No follow-up is needed.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6569085287 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1016). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-23T21:21:36Z. --- ## Change This closes four gaps in the test coverage of `tools/cpu_call_aot.py`. Each gap is shown by a small mutation of the translator that still passes the whole `^cpu_` suite on `main` at `ca52bbc`. The translator does not change; the native fixture DLL stays the reference for the differential cases. | # | Change | Mutation it covers | Test that pins it | |---|---|---|---| | 1 | `call_pair.asm`: `add rax, 11` in `mix_args` becomes `sub rax, -11`, written as the bytes `48 83 E8 F5` so the signed-imm8 encoding is pinned whatever the assembler picks (same result, same length) | the imm8 of `sub`/`add r64, imm8` read as unsigned | `cpu_aot_call_pair` | | 2 | `call_pair_check.py`: the `mov r8, rsi` reload before the second call replaced with `mov rsi, rsi` is refused (`undefined register`) | R8 kept live across the first call | `cpu_aot_call_pair` (already caught on `main` by `cpu_aot_repeated_call`; added here for the two-callee caller) | | 3 | `import_check.py`: the modelled import descriptor names the provider DLL with different letter case and still binds | the DLL name compared case-sensitively | `cpu_aot_import_call` | | 4 | `import_check.py`: a named import given an explicit link name is refused (`unexpected link name for named import`) | the stray link name silently dropped | `cpu_aot_import_call` | | 5 | `import_check.py`: an ordinal import bound with the link name `mé` is refused (`unsupported C import name`) | the ASCII requirement dropped from the C identifier check | `cpu_aot_ordinal_import` | The `sub rax, -11` form keeps the native return value and the Python reference unchanged. The patched image is only translated, never executed, and the import models are only passed to `resolve_import`. `docs/experiments.md` describes the R8 control, the signed-imm8 form and the non-ASCII link name. ## Verification On `a8d5f062` (based on `main` at `ca52bbc`), Windows 11, MSVC 14.44.35207, Python 3.14: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|direct_calls?|import_calls?|import_tail_jump|ordinal_import)$' python -B tests/docs_links_check.py ``` All 7 tests pass, and the docs check passes. Each mutation was applied to `tools/cpu_call_aot.py` one at a time and the project was rebuilt. With `main` at `ca52bbc`, the whole `^cpu_` suite passed under mutations 1, 3, 4 and 5, and `cpu_aot_repeated_call` failed under mutation 2. With this branch, at least one of the seven tests above fails under each of the five; the last column names the check written for it. With the unmutated translator everything passes. The five edits to `tools/cpu_call_aot.py`, numbered as in the table: 1. `imm = struct.unpack_from("b", body, pos + 3)[0]` -> `"B"` 2. `available.intersection_update({"rbx", "rsi"})` -> `{"rbx", "rsi", "r8"}` 3. `if dll.casefold() != provider.name.casefold() or symbol != name:` -> `if dll != provider.name or symbol != name:` 4. the `raise ValueError(f"unexpected link name for named import {identity}")` after `if not by_ordinal and link_name is not None:` -> `link_name = None` 5. `if not identifier.isascii() or not identifier.isidentifier():` -> `if not identifier.isidentifier():` ## Evidence and follow-up No new fixture file: the `sub rax, -11` bytes are in `tests/cpu/call_pair.asm`, and the other cases are a byte patch or import models inside the checks. No follow-up is needed. ## 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.
upstream-sync closed this pull request 2026-11-24 06:45:51 +00:00
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!1009
No description provided.