cpu: reject FS/GS and LOCK prefixes in the shared lowering #189
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/190"
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 Spaghetih on 2026-11-21T18:10:53Z.
Change
lower()intools/ffx_version_query.py, the integer lowering shared by theffx_*translators,bink_heap_aotand theheap_layoutandversion_queryfixtures, emitted flat loads and stores without checking prefixes. Before this change:65 48 8b 04 25 30 00 00 00mov rax, gs:[0x30]rax = load<uint64_t>(48ull)(reads absolute address 0x30)64 8b 41 08mov eax, fs:[rcx+8]rax = load<uint32_t>(rcx + 8ull)(segment base dropped)f0 01 01lock add [rcx], eaxlower()now raisesValueError("unsupported instruction prefix at 0x…: …")for FS/GS segment overrides and LOCK. This matchescpu_chained_aot.pyandcpu_switch_aot.py, which already reject prefixed instructions. Segment overrides that have no effect in 64-bit mode (CS/DS/ES/SS) andrep retstill lower exactly as the bare instruction. An instruction replaced throughhost_opsbypasses the check.Verification
Commit
68e1bacon345d919. Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.14.6,iced-x861.21.0,pefile2024.8.26.11 FS/GS or LOCK forms rejected; 6 neutral or unprefixed forms matched the bare lowering; host override kept. Passed.mainversion oftools/ffx_version_query.py:AssertionError: accepted mov rax, gs:[0x30]. Failed as expected.82 passed, 0 failed, 3 capability skips:
bvh_wave64_hardware,bvh_wave64_warp(lane range excludes 64) andwave_shuffle_warp. Hardware tests ran on an NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088. The translations regenerated at build time (cpu_heap_layout_lifted,cpu_version_query_lifted,cpu_create_lifted,cpu_bink_heap_lifted) still pass.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.pygenerated byte-identical C++ before and after the change (171, 1290 and 109 lines). None of the selected package intervals carries an FS/GS or LOCK prefix.-DFFX_UPSCALER_IMAGE, which compilesffx_device_slice.cppandffx_loop_loader.cppintooffscreen_check,ctest --test-dir out/build/ffx-device --no-tests=error -R '^ffx_'passed all 6ffx_*tests. The full suite in that configuration gave the same 82 passes and 3 skips.Evidence and follow-up
tests/cpu/lower_prefixes_check.pyuses synthetic x64 byte sequences only, written for this repository under its MIT license. It decodes them withiced_x86and callslower()directly, so it needs no native fixture and no game files. The public test verifies the rejection and the unchanged lowering of neutral prefixes. The local package check verifies only that the existing package translations are unaffected.docs/experiments.mddescribes this behavior after thecpu_aot_version_queryparagraph and gives the reproduction command.Follow-up I can open separately:
lower()also ignores the67address-size prefix.lea rax, [ecx+edx]lowers to the 64-bit sumrcx + rdx, while the hardware zero-extends the 32-bit sum. With ECX = 0xFFFFFFFF and EDX = 1, the hardware gives 0 and the lowering gives 0x100000000. That fix changes semantics rather than rejecting input, so I would pair it with a native MASM fixture.Checklist
AI-assisted (Claude Code). Every result above was run locally on the configuration listed.