tooling: scan the XMemAllocDefault/XMemFreeDefault call sites #1232

Manually merged
github merged 1 commit from gh-pr/1232/head into gh-pr/1232/base 2026-11-26 22:50:56 +00:00
Owner

@⁠triggered02 on GitHub · 2026-11-24 04:41 UTC · original
triggered02:tooling/xmem-scan-default-aliases → main · +72 −12 · 5 files · 1 commits · merged 2026-11-24 05:00 UTC

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.

**@⁠triggered02** on GitHub · 2026-11-24 04:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1232) `triggered02:tooling/xmem-scan-default-aliases` → `main` · +72 −12 · 5 files · 1 commits · merged 2026-11-24 05:00 UTC 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.
Released images import all four xmem allocation export names. The Default
aliases have their own IAT slots and thunks even though they forward to the
same implementations, so call sites through them were invisible to a scan that
only knew XMemAlloc and XMemFree.

TARGETS now covers 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 grows from 25 to 28 sites: a direct call through
XMemAllocDefault with a constant word, a tail jump through XMemFreeDefault, and
a conditional-move-guarded word (mov edx,imm32 / cmp byte ptr [flag],0 /
cmove rdx,rbx / call) that the scanner must report as computed with no word.
docs/experiments.md records the four-name coverage, the new fixture forms and
the cmove classification.

Verified:
- cmake --build --preset dev --target xmem_shim cpu_xmem_attributes cpu_xmem_delay: pass
- ctest --preset dev --no-tests=error -R xmem_attribute_scan -V: 1/1 passed,
  28 sites, 7 distinct words, 10 sites not fully constant
- python -B tests/docs_links_check.py: 16 files and 278 links checked, pass

Refs #126
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:50:54 +00:00
github manually merged commit 288b1bf260 into gh-pr/1232/base 2026-11-26 22:50:56 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 04:41 UTC · original · edited 2026-11-24 04:43 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-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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 04:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1232#issuecomment-7122254189) · edited 2026-11-24 04:43 UTC <!-- 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>
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 04:48 UTC · original · reviewed

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.
**@⁠tedin7** on GitHub · 2026-11-24 04:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1232#pullrequestreview-6033790000) · **reviewed** 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**.
This discussion has been locked. Commenting is limited to contributors.
No description provided.