x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM) #1120

Merged
kett1m merged 2 commits from upstream-pr/1120 into main 2026-12-01 14:53:31 +00:00
kett1m commented 2026-11-24 18:50:22 +00:00 (Migrated from github.com)

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_one gave every VEX map-1 opcode the operand shape V W, which reads a ModRM
byte. 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-256
e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993) with REA
inspect_with_objdump. Section-header evidence
ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90 maps .text RVA
0x140001000 to file 0x400 and .pdata RVA 0x14abcf000 to file 0x6e03a00;
file-header evidence ev_4ec749bb6395770cf8a099344c042bfd7ba67ff269f47e7ae115443028d4e127
gives entry 0x1456a1ec8. Ten .pdata functions hold such a vzeroupper. RVA 0xa4ab00
(file 0xa49f00, 95 bytes) has c5 f8 77 at offset 81 followed by the e8 of a call,
and ends 90 48 83 c4 68 c3, that is nop; add rsp,68h; ret. The walk read c4 68 c3
there because the vzeroupper had eaten the call's e8.

Before the change python3 -I tools/recomp_census.py <exe> aborted with IndexError: index out of range. After it the census runs over all 299,257 .pdata functions: 21,518,571
decoded instructions, 84.77% translated coverage, 41,091 decode errors, 48,224 v77, and
no .pdata function ends inside a VEX or EVEX prefix (10 before). 20,620 of the 299,257
functions 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.py already makes this exception for the same opcode
(modrm = not (vmap == 1 and b == 0x77)), and tests/test_gdk_runtime_calls.py pins
C5 F8 77 at 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

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • No new translator rule, so no docs/design.md contract row.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5478314342 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1120). Originally posted by [kett1m](https://github.com/kett1m) on 2026-11-24T18:50:22Z. --- Claimed in the coordination issue as: X64-RECOMP-VZEROUPPER-NO-MODRM ### What and why `decode_one` gave every VEX map-1 opcode the operand shape `V W`, which reads a ModRM byte. 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-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`) with REA `inspect_with_objdump`. Section-header evidence `ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90` maps `.text` RVA `0x140001000` to file `0x400` and `.pdata` RVA `0x14abcf000` to file `0x6e03a00`; file-header evidence `ev_4ec749bb6395770cf8a099344c042bfd7ba67ff269f47e7ae115443028d4e127` gives entry `0x1456a1ec8`. Ten `.pdata` functions hold such a vzeroupper. RVA `0xa4ab00` (file `0xa49f00`, 95 bytes) has `c5 f8 77` at offset 81 followed by the `e8` of a call, and ends `90 48 83 c4 68 c3`, that is `nop; add rsp,68h; ret`. The walk read `c4 68 c3` there because the vzeroupper had eaten the call's `e8`. Before the change `python3 -I tools/recomp_census.py <exe>` aborted with `IndexError: index out of range`. After it the census runs over all 299,257 `.pdata` functions: 21,518,571 decoded instructions, 84.77% translated coverage, 41,091 decode errors, 48,224 `v77`, and no `.pdata` function ends inside a VEX or EVEX prefix (10 before). 20,620 of the 299,257 functions 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.py` already makes this exception for the same opcode (`modrm = not (vmap == 1 and b == 0x77)`), and `tests/test_gdk_runtime_calls.py` pins `C5 F8 77` at 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 - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here. - [x] No new translator rule, so no `docs/design.md` contract row.
abnalstlll-byte commented 2026-11-24 18:56:14 +00:00 (Migrated from github.com)

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 opcodes vzeroupper (C5 F8 77) and vzeroall (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 against tests/test_x64_recomp.py and test_recomp_census.py. 100% clean-room.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045428336 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1120#pullrequestreview-6045428336). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T18:56:14Z. **Review:** APPROVED --- Reviewed and verified. Essential bugfix for `tools/x64_recomp.py:decode_one`. Map-1 opcodes `vzeroupper` (C5 F8 77) and `vzeroall` (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 against `tests/test_x64_recomp.py` and `test_recomp_census.py`. 100% clean-room.
Deedlyy commented 2026-11-24 20:15:53 +00:00 (Migrated from github.com)

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 with main. Merge once the queued checks are green.

Impact level: 4/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143271830 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1120#issuecomment-7143271830). Originally posted by [Deedlyy](https://github.com/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 with `main`. Merge once the queued checks are green. **Impact level:** 4/10
kevincommits commented 2026-11-25 21:59:49 +00:00 (Migrated from github.com)

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 main at cb699500a into the branch locally (904 commits behind, no conflicts).

  • main alone decodes c5 f8 77 c3 as one instruction: [('v77', 4)]. The ret is swallowed, as the description says.
  • This branch: [('v77', 3), ('ret', 1)].
  • tests/test_x64_recomp.py: 35/35 (33 on main). tests/test_recomp_census.py: 12/12 (11 on main). tests/test_gdk_runtime_calls.py: OK.
  • Every standalone tests/test_*.py under python -I: 510 run, 506 pass; the 4 that fail are the same 4 that fail on plain main.

The three new tests fail on main and pass here. The change is confined to the map-1 VEX decode path. No game files used. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7175804513 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1120#issuecomment-7175804513). Originally posted by [kevincommits](https://github.com/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 `main` at `cb699500a` into the branch locally (904 commits behind, no conflicts). - `main` alone decodes `c5 f8 77 c3` as one instruction: `[('v77', 4)]`. The `ret` is swallowed, as the description says. - This branch: `[('v77', 3), ('ret', 1)]`. - `tests/test_x64_recomp.py`: 35/35 (33 on `main`). `tests/test_recomp_census.py`: 12/12 (11 on `main`). `tests/test_gdk_runtime_calls.py`: OK. - Every standalone `tests/test_*.py` under `python -I`: 510 run, 506 pass; the 4 that fail are the same 4 that fail on plain `main`. The three new tests fail on `main` and pass here. The change is confined to the map-1 VEX decode path. No game files used. AI-assisted.
MoonEyes commented 2026-11-28 17:58:57 +00:00 (Migrated from github.com)

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 the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243436672 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1120#issuecomment-7243436672). Originally posted by [MoonEyes](https://github.com/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 the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; 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).
aslan2142 commented 2026-12-01 11:39:56 +00:00 (Migrated from github.com)

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-620 cleanly marks map-1 VEX opcode 0x77 (vzeroupper/vzeroall) as having no ModRM byte (spec = ("simd", "")), with unit and census regression tests in tests/test_x64_recomp.py and tests/test_recomp_census.py. Clean-room verified. Approving; please merge/rebase current main so CI runs green before merge.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130488414 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1120#pullrequestreview-6130488414). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:39:56Z. **Review:** APPROVED --- Reviewed the diff against `main`: `tools/x64_recomp.py:218-221,617-620` cleanly marks map-1 VEX opcode `0x77` (`vzeroupper`/`vzeroall`) as having no ModRM byte (`spec = ("simd", "")`), with unit and census regression tests in `tests/test_x64_recomp.py` and `tests/test_recomp_census.py`. Clean-room verified. Approving; please merge/rebase current `main` so CI runs green before merge. *(AI-assisted review.)*
MoonEyes commented 2026-12-01 13:07:12 +00:00 (Migrated from github.com)

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 stays dd60cba73. MoonEyes's agent.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7312132595 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1120#issuecomment-7312132595). Originally posted by [MoonEyes](https://github.com/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 stays `dd60cba73`. MoonEyes's agent.
MoonEyes commented 2026-12-01 13:18:57 +00:00 (Migrated from github.com)

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 dd60cba73 is unchanged and approved by Aslanek. I also ran it on main ed867d7b2 (Windows, Python 3.14): tests/test_recomp_census.py gives 12 tests OK and fails with 1 failure without the change; tests/test_x64_recomp.py fails 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.py once this is merged.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7312427894 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1120#issuecomment-7312427894). Originally posted by [MoonEyes](https://github.com/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 `dd60cba73` is unchanged and approved by Aslanek. I also ran it on `main` `ed867d7b2` (Windows, Python 3.14): `tests/test_recomp_census.py` gives 12 tests OK and fails with 1 failure without the change; `tests/test_x64_recomp.py` fails 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.py` once this is merged. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1120
No description provided.