tooling: scan the XMemAllocDefault/XMemFreeDefault call sites #1225

Merged
triggered02 merged 1 commit from upstream-pr/1232 into main 2026-11-24 05:00:19 +00:00
triggered02 commented 2026-11-24 04:41:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T04:41:35Z.


Refs #126. This is the scanner-coverage slice: the attribute-word decode and policy in the issue's completion condition stay open.

Why

tools/xmem_attribute_scan.py only targeted the export names XMemAlloc and XMemFree, so call sites through the XMemAllocDefault and XMemFreeDefault aliases were invisible. src/xmem_shim.def exports the aliases (XMemAllocDefault=XMemAlloc @5, XMemFreeDefault=XMemFree @6), and a released image imports all four names by name. The alias imports have their own IAT slots and thunks, so a scan limited to the plain names misses those sites.

before after
scannable import names 2 4
fixture sites 25 28
fixture distinct words 7 7
fixture sites not fully constant 9 10

Change

  • TARGETS now lists XMemAlloc, XMemAllocDefault, XMemFree and XMemFreeDefault. Each site already records the import name it used, so a site resolves to the alias it imported and XMemAllocDefault is never reported as XMemAlloc. The report schema is unchanged, so FORMAT stays 2.
  • The source-built fixture (tests/cpu/xmem_attributes.asm / .def) gains three sites, 25 -> 28:
    • default_alloc: a direct call through XMemAllocDefault with constant word 0x05e50000 (heap, 32-byte alignment);
    • default_free_tail: a tail jump through XMemFreeDefault with constant word 0xa8004000 (memory type 5 graphics);
    • cmove_guarded: mov edx,04000000h / cmp byte ptr [guard_flag],0 / cmove rdx,rbx / call, where guard_flag is a writable byte. The scanner deliberately classifies this shape as computed; the fixture now pins that classification and pins that the immediate before the compare is not reported as a word.
  • tests/xmem_attribute_scan_check.py asserts the four-name import list, both alias records (import name, slot route, call/jump transfer, word and classification), the computed cmove site, and the new counts. No existing assertion was removed.
  • docs/experiments.md: the "Attribute words at xmem call sites" section records the four-name coverage, the alias naming rule and the cmove classification, and notes that a physical-type or other word observed at such a site comes from a separate pass over the image, not from this scanner.

Verification

Built from the F:\x2w-xmem worktree on Windows with MSVC 19.52.37029.0, configured with cmake --preset dev -DINTAKE_PYTHON='C:/Users/trigg/source/repos/Xbox2Windows/out/pe-env/Scripts/python.exe' (configure did not need FFX_UPSCALER_IMAGE).

cmake --build --preset dev --target xmem_shim cpu_xmem_attributes cpu_xmem_delay
  -> pass (xmem.dll and both fixtures linked)

ctest --preset dev --no-tests=error -R xmem_attribute_scan -V
  -> 1/1 passed
     decoding: 13 cases passed
     fixture: 28 sites, summary and exit codes passed
     delay-load fixture: 1 site and exit codes passed

python -B tests/docs_links_check.py
  -> Self-test passed. Checked 16 Markdown files and 278 links.

The scanner's own summary for the fixture: 28 sites, 7 distinct words, 2 null words, 10 sites not fully constant.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574764988 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1232). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T04:41:35Z. --- Refs #126. This is the scanner-coverage slice: the attribute-word decode and policy in the issue's completion condition stay open. ## Why `tools/xmem_attribute_scan.py` only targeted the export names `XMemAlloc` and `XMemFree`, so call sites through the `XMemAllocDefault` and `XMemFreeDefault` aliases were invisible. `src/xmem_shim.def` exports the aliases (`XMemAllocDefault=XMemAlloc @5`, `XMemFreeDefault=XMemFree @6`), and a released image imports all four names by name. The alias imports have their own IAT slots and thunks, so a scan limited to the plain names misses those sites. | | before | after | |---|---|---| | scannable import names | 2 | 4 | | fixture sites | 25 | 28 | | fixture distinct words | 7 | 7 | | fixture sites not fully constant | 9 | 10 | ## Change - `TARGETS` now lists `XMemAlloc`, `XMemAllocDefault`, `XMemFree` and `XMemFreeDefault`. Each site already records the import name it used, so a site resolves to the alias it imported and `XMemAllocDefault` is never reported as `XMemAlloc`. The report schema is unchanged, so `FORMAT` stays 2. - The source-built fixture (`tests/cpu/xmem_attributes.asm` / `.def`) gains three sites, 25 -> 28: - `default_alloc`: a direct call through `XMemAllocDefault` with constant word `0x05e50000` (heap, 32-byte alignment); - `default_free_tail`: a tail jump through `XMemFreeDefault` with constant word `0xa8004000` (memory type 5 graphics); - `cmove_guarded`: `mov edx,04000000h` / `cmp byte ptr [guard_flag],0` / `cmove rdx,rbx` / `call`, where `guard_flag` is a writable byte. The scanner deliberately classifies this shape as `computed`; the fixture now pins that classification and pins that the immediate before the compare is not reported as a word. - `tests/xmem_attribute_scan_check.py` asserts the four-name import list, both alias records (import name, slot route, call/jump transfer, word and classification), the computed `cmove` site, and the new counts. No existing assertion was removed. - `docs/experiments.md`: the "Attribute words at xmem call sites" section records the four-name coverage, the alias naming rule and the `cmove` classification, and notes that a physical-type or other word observed at such a site comes from a separate pass over the image, not from this scanner. ## Verification Built from the `F:\x2w-xmem` worktree on Windows with MSVC 19.52.37029.0, configured with `cmake --preset dev -DINTAKE_PYTHON='C:/Users/trigg/source/repos/Xbox2Windows/out/pe-env/Scripts/python.exe'` (configure did not need `FFX_UPSCALER_IMAGE`). ``` cmake --build --preset dev --target xmem_shim cpu_xmem_attributes cpu_xmem_delay -> pass (xmem.dll and both fixtures linked) ctest --preset dev --no-tests=error -R xmem_attribute_scan -V -> 1/1 passed decoding: 13 cases passed fixture: 28 sites, summary and exit codes passed delay-load fixture: 1 site and exit codes passed python -B tests/docs_links_check.py -> Self-test passed. Checked 16 Markdown files and 278 links. ``` The scanner's own summary for the fixture: 28 sites, 7 distinct words, 2 null words, 10 sites not fully constant.
upstream-sync closed this pull request 2026-11-24 06:47:07 +00:00
tedin7 commented 2026-11-24 06:47:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:48:22Z.

Review: COMMENTED


Reviewed 288b1bf2 on Linux (Windows MASM fixture build and xmem_attribute_scan CTest were not run locally).

Diff & edge-case audit

  • tools/xmem_attribute_scan.py: extends TARGETS to ("XMemAlloc", "XMemAllocDefault", "XMemFree", "XMemFreeDefault"). Because TARGETS is matched directly against the imported symbol name for IAT slots, delay-load slots, and thunks, each site preserves the exact alias name (XMemAllocDefault / XMemFreeDefault) rather than folding into XMemAlloc / XMemFree.
  • tests/cpu/xmem_attributes.asm, tests/cpu/xmem_attributes.def, tests/xmem_attribute_scan_check.py: adds default_alloc, default_free_tail, and cmove_guarded (25 -> 28 sites), checking alias attribution and verifying that cmove after an immediate mov edx + cmp reports computed without leaking the pre-cmp immediate.
  • docs/experiments.md: consistent with the code and 100% title-neutral.

Linux checks (/root/.local/share/x2w-rev-venv/bin/python -B)

  • tests/xmem_attribute_scan_check.py: passed (decoding: 13 cases passed, exit 0)
  • tests/form_coverage_check.py: passed (form coverage checks passed, exit 0)
  • tests/docs_links_check.py: passed (16 Markdown files, 278 links, exit 0)
  • tests/bidi_controls_check.py: passed (1038 tracked files, exit 0)
  • git diff --check origin/main..HEAD: passed (exit 0)
  • Windows xmem_attribute_scan CTest (linking tests/cpu/xmem_attributes.asm against xmem.dll): not run locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033790000 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1232#pullrequestreview-6033790000). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:48:22Z. **Review:** COMMENTED --- Reviewed `288b1bf2` on Linux (Windows MASM fixture build and `xmem_attribute_scan` CTest were not run locally). ### Diff & edge-case audit - `tools/xmem_attribute_scan.py`: extends `TARGETS` to `("XMemAlloc", "XMemAllocDefault", "XMemFree", "XMemFreeDefault")`. Because `TARGETS` is matched directly against the imported symbol name for IAT slots, delay-load slots, and thunks, each site preserves the exact alias name (`XMemAllocDefault` / `XMemFreeDefault`) rather than folding into `XMemAlloc` / `XMemFree`. - `tests/cpu/xmem_attributes.asm`, `tests/cpu/xmem_attributes.def`, `tests/xmem_attribute_scan_check.py`: adds `default_alloc`, `default_free_tail`, and `cmove_guarded` (25 -> 28 sites), checking alias attribution and verifying that `cmove` after an immediate `mov edx` + `cmp` reports `computed` without leaking the pre-`cmp` immediate. - `docs/experiments.md`: consistent with the code and 100% title-neutral. ### Linux checks (`/root/.local/share/x2w-rev-venv/bin/python -B`) - `tests/xmem_attribute_scan_check.py`: **passed** (`decoding: 13 cases passed`, exit 0) - `tests/form_coverage_check.py`: **passed** (`form coverage checks passed`, exit 0) - `tests/docs_links_check.py`: **passed** (16 Markdown files, 278 links, exit 0) - `tests/bidi_controls_check.py`: **passed** (1038 tracked files, exit 0) - `git diff --check origin/main..HEAD`: **passed** (exit 0) - Windows `xmem_attribute_scan` CTest (linking `tests/cpu/xmem_attributes.asm` against `xmem.dll`): **not run locally**.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T04:41:47Z.


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-24T04:43:11.334441Z 288b1bf PR opened
ℹ️ 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:7122254189 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1232#issuecomment-7122254189). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T04:41:47Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"288b1bf2603535bd916677fa6604b42cd0ea0689","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-24T04:43:11.334441Z">2026-11-24T04:43:11.334441Z</relative-time> | `288b1bf` | PR opened | <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>
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!1225
No description provided.