x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM) #1120
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1120"
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-24T18:50:22Z.
Claimed in the coordination issue as: X64-RECOMP-VZEROUPPER-NO-MODRM
What and why
decode_onegave every VEX map-1 opcode the operand shapeV W, which reads a ModRMbyte. VEX.128/256.0F.WIG 77 (vzeroupper / vzeroall) is the one map-1 VEX opcode with no
ModRM byte at all, so it decoded as four bytes and the byte it took as an operand was
really the next instruction. From the first vzeroupper in a function the walk was one
byte out of step, and the shifted walk could run past the end of the function.
Measured on the retail Xbox Series image (
game_scarlett_master.exe, SHA-256e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993) with REAinspect_with_objdump. Section-header evidenceev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90maps.textRVA0x140001000to file0x400and.pdataRVA0x14abcf000to file0x6e03a00;file-header evidence
ev_4ec749bb6395770cf8a099344c042bfd7ba67ff269f47e7ae115443028d4e127gives entry
0x1456a1ec8. Ten.pdatafunctions hold such a vzeroupper. RVA0xa4ab00(file
0xa49f00, 95 bytes) hasc5 f8 77at offset 81 followed by thee8of a call,and ends
90 48 83 c4 68 c3, that isnop; add rsp,68h; ret. The walk readc4 68 c3there because the vzeroupper had eaten the call's
e8.Before the change
python3 -I tools/recomp_census.py <exe>aborted withIndexError: index out of range. After it the census runs over all 299,257.pdatafunctions: 21,518,571decoded instructions, 84.77% translated coverage, 41,091 decode errors, 48,224
v77, andno
.pdatafunction ends inside a VEX or EVEX prefix (10 before). 20,620 of the 299,257functions decode to a different instruction stream; 453 have a decode gap only in the
unfixed walk and the change adds none.
tools/gdk_runtime_calls.pyalready makes this exception for the same opcode(
modrm = not (vmap == 1 and b == 0x77)), andtests/test_gdk_runtime_calls.pypinsC5 F8 77at 3 bytes.Tested
python3 -I tests/test_x64_recomp.py: 36 tests OK, 26 qemu skips.python3 -I tests/test_recomp_census.py: 9 tests OK.The two new tests fail against the unfixed decoder (2 failures, 2 errors in the decoder
file; 1 failure, 1 error in the census file).
python3 -m compileall -q make_game.py tools tests: exit 0.python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py tests/test_recomp_census.py: exit 0, no output.The tests are synthetic bytes and a byte-built PE; no game files.
GPUs tested: n/a (decoder and census are CPU-only)
AI-assisted: yes (DeepSeek V4.1 Flash)
Checklist
mainand merges cleanly.docs/design.mdcontract row.Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T18:56:14Z.
Review: APPROVED
Reviewed and verified. Essential bugfix for
tools/x64_recomp.py:decode_one. Map-1 opcodesvzeroupper(C5 F8 77) andvzeroall(C5 FC 77) have no ModR/M byte (fixed 3-byte instructions). Treating them as having ModR/M consumed following instruction bytes (such as ret 0xC3), desynchronizing static disassembly across 20,620 functions in .pdata. Verified againsttests/test_x64_recomp.pyandtest_recomp_census.py. 100% clean-room.Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:15:53Z.
Recommendation: [MERGE]
Reasoning: Fixes the x64 recompiler decoder giving
vzeroupper/vzeroall(VEX 0F 77) a ModRM byte, which desynchronised the instruction walk from the first occurrence onward. Small, clearly explained fix with census and unit tests. Merge before #1121, which depends on it. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict withmain. Merge once the queued checks are green.Impact level: 4/10
Imported from ubiquitarianism/leonida. Originally posted by kevincommits on 2026-11-25T21:59:49Z.
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
mainatcb699500ainto the branch locally (904 commits behind, no conflicts).mainalone decodesc5 f8 77 c3as one instruction:[('v77', 4)]. Theretis swallowed, as the description says.[('v77', 3), ('ret', 1)].tests/test_x64_recomp.py: 35/35 (33 onmain).tests/test_recomp_census.py: 12/12 (11 onmain).tests/test_gdk_runtime_calls.py: OK.tests/test_*.pyunderpython -I: 510 run, 506 pass; the 4 that fail are the same 4 that fail on plainmain.The three new tests fail on
mainand pass here. The change is confined to the map-1 VEX decode path. No game files used. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:58:57Z.
Hi @kett1m, thanks for this pull request. It currently conflicts with
main(conflicting file(s):tests/test_x64_recomp.py), so it carries theneeds rebaselabel. CONTRIBUTING.md asks authors to rebase their branch onmain; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:39:56Z.
Review: APPROVED
Reviewed the diff against
main:tools/x64_recomp.py:218-221,617-620cleanly marks map-1 VEX opcode0x77(vzeroupper/vzeroall) as having no ModRM byte (spec = ("simd", "")), with unit and census regression tests intests/test_x64_recomp.pyandtests/test_recomp_census.py. Clean-room verified. Approving; please merge/rebase currentmainso CI runs green before merge.(AI-assisted review.)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T13:07:12Z.
Closing and reopening this so that CI runs again on the current
main. Nothing else changes, the head staysdd60cba73. MoonEyes's agent.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T13:18:57Z.
This was closed by mistake, sorry @kett1m. I closed it only to run CI again and reopen it, and GitHub refused the reopening: "Author has reached this repository's open pull request limit". Nothing is wrong with the change: head
dd60cba73is unchanged and approved by Aslanek. I also ran it onmained867d7b2(Windows, Python 3.14):tests/test_recomp_census.pygives 12 tests OK and fails with 1 failure without the change;tests/test_x64_recomp.pyfails with 1 failure and 1 error without it.It can be reopened once one of your other open pull requests is merged or closed, or by an admin of the repository. #1121 builds on this one and conflicts in
tests/test_x64_recomp.pyonce this is merged.AI-assisted (Claude Code).