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

Open
opened 2026-11-26 20:20:16 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1120
Author: @kett1m
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: x64-recomp-vzeroupper


📝 Commits (1)

  • 7b78bd6 x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM)

📊 Changes

3 files changed (+51 additions, -1 deletions)

View changed files

📝 tests/test_recomp_census.py (+26 -0)
📝 tests/test_x64_recomp.py (+16 -0)
📝 tools/x64_recomp.py (+9 -1)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1120 **Author:** [@kett1m](https://github.com/kett1m) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `x64-recomp-vzeroupper` --- ### 📝 Commits (1) - [`7b78bd6`](https://github.com/ubiquitarianism/leonida/commit/7b78bd6637a1d958e707669c24e1caf88558affc) x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM) ### 📊 Changes **3 files changed** (+51 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_recomp_census.py` (+26 -0) 📝 `tests/test_x64_recomp.py` (+16 -0) 📝 `tools/x64_recomp.py` (+9 -1) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1155
No description provided.