x64_recomp: 0F 01 /r needs its ModRM byte (X64-RECOMP-GROUP7) #1483
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1483"
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 ubiquitarianism/leonida. Originally posted by kett1m on 2026-11-25T01:19:11Z.
tools/x64_recomp.py's0Ftable has no entry for opcode0x01, so the wholesystem-instruction group decoded as the unknown
op0f_01of two bytes. Every form of0F 01 /rcarries a ModRM byte: the memory forms are SGDT/SIDT/LGDT/LIDT/SMSW/LMSW/INVLPG, andthe register forms are whole ModRM bytes (MONITOR, MWAIT, XGETBV, XSETBV, CLZERO, MONITORX,
MWAITX, RDTSCP, SWAPGS, the VMX/SVM instructions). The walk stopped after the two opcode bytes,
so every instruction after it in the function was read at the wrong offset.
Measurement
A per-instruction differential against GNU objdump over the retail image's
.text: objdump'slinear walk and the decoder's walk read the same bytes and the instruction lengths are compared
(
objdump -d --start-address/--stop-addressover the section, 26,674,180 objdump instructions).The image is
game_scarlett_master.exe, SHA-256e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993. REA measured the sectionranges with
gnu.objdumpsection_headers, evidenceev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90:.textVMA0x140001000, file0x400, size0x5f3f966;.pdataVMA0x14abcf000, file0x6e03a00.The differential flags 16
0F 01boundaries, all one byte short before the fix:clzero, RVAs0x4e89a70to0x4e89bb4, in two neighbouring.pdatafunctions(
0x4e899c0and0x4e89b80). The first sits at the head of the title's 64-byte zeroing loop(
clzero;add $0x40,%rax;cmp %r10,%rax;jbback to it), so these run, they are notstray data.
xgetbv, RVAs0x21ae7b5and0x55e8e92.monitorx, RVAs0x4fafbd7and0x4fafd21.mwaitx, RVAs0x4fafc00and0x4fafd52.Over the whole
.pdatacorpus (recomp_census.py's walk, 299,257 functions), the fix lets 9functions decode further, 638 instructions in total, and 7 of them reach the end of the function
with no unknown instruction left.
Test
tests/test_x64_recomp.py::DecodeTests::test_group7_0f01_carries_modrmpins the register forms(CLZERO, XGETBV, MONITORX, MWAITX, MONITOR, RDTSCP, SWAPGS, SMSW) at three bytes and the memory
forms (
sgdt [rax],sgdt [rsp+0x10],invlpg [rsp+0x10]) at their fullModRM/SIB/displacement length. Against the unfixed decoder it fails:
0f 01 fcdecodes to size2.
python -I tests/test_x64_recomp.py: 33 tests OK, 26 skipped (this host has noqemu-system-aarch64).
python -I tests/test_recomp_census.py: 11 tests OK.python3 -m compileall -q make_game.py tools testsexits 0.python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.mdexits0 with no output.
docs/mobile.mdrecords the measurement and the evidence ID. The differential is local analysisof the shipped file; nothing was executed. No game files, no GPU, nothing online. Tested on Linux
(openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12 cores.
AI-assisted (DeepSeek V4.1 Flash).
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T03:53:34Z.
Review: APPROVED
Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). 0F 01 is group 7: memory forms by ModRM.reg (sgdt, sidt, lgdt, lidt, smsw, -, lmsw, invlpg) and register forms as whole ModRM bytes. The table matches the opcode map (C1 vmcall ... CB stac, D0 xgetbv/D1 xsetbv, D5 xend/D6 xtest, D8-DF SVM, EE/EF rdpkru/wrpkru, F8 swapgs, F9 rdtscp, FA/FB monitorx/mwaitx, FC clzero), and the walk now consumes the ModRM byte instead of stopping one byte late.
AI-assisted (Claude).
Imported from ubiquitarianism/leonida. Originally posted by kevincommits on 2026-11-25T22:10:16Z.
Independent run. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew, so the 26 exec tests ran rather than skipped. I merged
mainatd3b8251bcinto the branch locally (635 commits behind, no conflicts).tests/test_x64_recomp.py: 34/34 (33 onmain), so the new test fails onmainand passes here.tests/test_recomp_census.py: 11/11.tests/test_*.pyunderpython -I: 510 run, 506 pass; the 4 that fail are the same 4 that fail on plainmain.Beyond the fixtures, I fed
disasmsome inputs the new test does not cover:main0f 01 d0 c3op0f_01(2), thenrolxgetbv(3),ret(1)0f 01 05 78 56 34 12(RIP-relative)op0f_01(2), thenaddsgdt(7)66 0f 01 d0op0f_01(3),dbxgetbv(4)f3 0f 01 e8,0f 01 c0,0f 01 ff(no table entry)op0f_01,dbsysat the right length0f 01(buffer ends before ModRM)op0f_01(2)dberror record, no exception0f 01 04,0f 01 44 24(ends inside SIB / displacement)op0f_01,dbdberror record, no exceptionSo truncated buffers end in the decoder's own error record, not an
IndexError, and unlisted register forms still get the right length. I found nothing wrong. I did not reproduce the retail-image counts in thedocs/mobile.mdparagraph. No game files used. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:19:49Z.
Red/green: the PR's tests fail on main
4938673and pass on headc1df54c119(Linux, Python 3.13.18).Targeted batch of 11 PRs (their tests, the tests importing the changed modules, the docs tests) on main
3ca0707: no new failure, Linux / Python 3.13.AI-assisted (Claude Code, Claude Opus 5.5)