cpu: truncate 32-bit effective addresses in ffx_version_query #202
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/205"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T18:22:07Z.
Change
Truncate 32-bit effective addresses (x64
67haddress-size override, where the memory base or index register is 32-bit) touint32_tintools/ffx_version_query.py(lower/address).Previously,
address()mapped 32-bit base and index registers (ECX,EDX, etc.) to their full 64-bit host variables without truncating the resulting address to 32 bits. Whenever the upper 32 bits of the base/index register were nonzero or the 32-bit sum wrapped around (for examplelea rax, [ecx + edx*2 + 4]orlea r8, [ecx + 1]), the lifted code produced a 64-bit sum instead of the zero-extended 32-bit x64 effective address.address()now checksRegisterExt.size(...) == 4onmemory_baseandmemory_indexand wraps the expression instatic_cast<uint32_t>(...).Adds a source-built MASM function
addr32_probetotests/cpu/version_query.asm(exported intests/cpu/version_query.def), lifts it intests/cpu/version_query_fixture.py, and compares native Windows execution against the lifted DLL across four inputs including nonzero upper 32-bit halves and 32-bit wraparound.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,iced-x86==1.21.0), at commitcccd89c:tools/ffx_version_query.py, native and lifted outputs diverge on the first case:cpu_aot_version_queryoutput includesaddr32_probe: 4 native/lifted cases matched)Evidence and follow-up
The regression fixture is built from original MASM source in
tests/cpu/version_query.asmand verified differentially against native x64 execution on Windows.Because
address()is shared byLEAand memory operands inffx_version_query.lower, this fixes 32-bit effective address computation across all lowered memory andLEAinstructions.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:24:25Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
cccd89cℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by Spaghetih on 2026-11-21T18:46:21Z.
Thanks for picking this up. I had flagged the 67h case as a follow-up in #190 and had a local branch for it, so I ran my fixture against your head instead of opening a duplicate.
Your head
cccd89cwith an extra fixture applied locally (Windows 11 26200.9974, MSVC 14.44.35207, Python 3.14.6,iced-x861.21.0):The extra fixture is a separate MASM image with four 67h-prefixed functions, compared native vs. translated against a 32-bit reference:
lea_sum3267 48 8d 04 11lea rax,[ecx+edx]lea_scaled3267 48 8d 44 d1 f8lea rax,[ecx+edx*8-8]load3267 8b 04 11mov eax,[ecx+edx]store3267 44 89 04 11mov [ecx+edx],r8dThe inputs combine 32-bit wraparound with upper-half noise (
0,0xdeadbeef00000000,0xffffffff00000000) on both registers. The load and store cases use a page committed below 4 GiB, including a base +0xffffff14index that wraps back into the page. Each store also checks that no other word in the page changed. The-8case matters because iced reports a 32-bit-mode displacement as0xfffffff8, so without the truncation even a zero upper half is off by 4 GiB.Result on your head:
72 lea and 42 load/store cases matched the 32-bit reference on the native and translated images.cpu_aot_version_query(includingaddr32_probe) also passed. Onmainthe same fixture fails at the first case:lifted lea_sum32(0xffffffff, 0x1) = 0x100000000, expected 0x0.Local package check. With a local copy of the loader and upscaler whose SHA-256 values match the
LOADERandUPSCALERprofiles,ffx_version_query.py,ffx_device_init.pyandffx_create_context.pygenerate byte-identical C++ on your head and onmain. None of the selected package intervals uses 32-bit addressing.One remaining edge, low priority. A 67h EIP-relative operand (
67 8b 05 10 00 00 00,mov eax,[eip+0x10]) takes theis_ip_rel_memory_operandbranch before the new truncation. It ends in a bareKeyErrorfromglobals_, or binds to a global if one happens to sit at the truncated RVA, while the hardware uses the low 32 bits of the runtime RIP. Compilers do not emit this form. An explicitValueErrorwould make it a clear rejection.Once this merges, I can open a small follow-up with the MASM load/store fixture and the EIP-relative rejection, unless you would rather fold either into this PR.
AI-assisted (Claude Code). The results above were run locally on the configuration listed.