fix(relinker): trap only GS memory accesses in Windows and macOS output #8063

Merged
AasishDairelSahayaGrinspan merged 5 commits from upstream-pr/8063 into main 2026-10-21 03:35:25 +00:00
AasishDairelSahayaGrinspan commented 2026-10-19 19:25:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-19T19:25:45Z.


What

#6458 (macOS) and #6102 (Windows) replace every guest instruction that carries a GS segment prefix by UD2 and NOP padding. A GS prefix on an instruction without a memory operand (65 90, 65 48 89 c8, 65 0f a2) is architecturally ignored and does not touch GS, so the instruction can run unchanged in the converted output, but it currently faults. docs/dev/debt/relinker.md records the macOS case, with those two byte examples, as a known gap.

  • DecodedInstructionInfo gains HasMemoryOperand: set for a ModRM memory operand (mod != 3, including the Group 5 indirect call/jump path and VEX/EVEX/XOP instructions) and for the encodings whose memory operand is implicit (INS/OUTS, MOV moffs, MOVS/CMPS/STOS/LODS/SCAS, XLATB, MASKMOVQ/MASKMOVDQU/VMASKMOVDQU, MONITOR/MONITORX, UMONITOR and CLZERO).
  • The Windows TLS builder and the macOS TLS scan trap a GS-prefixed instruction only when HasMemoryOperand is set. A GS-prefixed instruction without a memory operand is left unchanged and executes with the ignored prefix.
  • The Windows gs_traps and gs_traps_implicit groups and test_macos_gs_traps.py gain 65 90, 65 48 89 c8, 65 0f a2, the implicit-memory 65 66 0f f7 c1, 65 0f f7 c1, 65 c5 f9 f7 c1, 65 0f 01 c8, 65 0f 01 fa, 65 0f 01 fc and 65 f3 0f ae f0, and the non-memory 65 0f 01 c9 (MWAIT), 65 0f 01 fd (RDPRU) and 65 f2 0f ae f0 (UMWAIT) as negative cases. The decoder test also covers the three-byte VEX form 65 c4 e1 79 f7 c1. The macOS debt entry no longer records the no-memory case.
  • Overlap: open PR #7706 adds a "branch into a trapped GS instruction" refusal whose case is 74 01 65 b8 2a 00 00 00 c3; 65 b8 2a 00 00 00 has no memory operand and no longer traps here, so if #7706 lands after this change its case needs a memory-operand instruction (for example 65 8b 05 ...). Nothing else in #7706 changes.

Tested

macOS 15.7.7, x86_64, AppleClang, relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON) on this branch rebased onto main 49fd13a74:

  • ctest 210/210 pass.
  • The Windows GS cases are split into gs_traps (9 cases) and gs_traps_implicit (10 cases) so each stays well under its 30 s CTest timeout; the combined group ran close to that limit on a loaded Windows host.
  • The five implicit-memory encodings from the review (65 66 0f f7 c1, 65 0f f7 c1, 65 c5 f9 f7 c1, 65 0f 01 c8, 65 0f 01 fa), the mov rax, gs:[rax] control, UMONITOR (65 f3 0f ae f0) and CLZERO (65 0f 01 fc) convert to UD2 and NOP padding in Windows output; 65 90, 65 0f 01 c9, 65 0f 01 fd, 65 f2 0f ae f0 and 65 66 0f ae f0 remain unchanged. VEX2 and VEX3 VMASKMOVDQU are covered by the decoder test.
  • Reverting the decoder change leaves the seven implicit-memory encodings unchanged in both tests; reverting the two writer changes traps gs-nop again, so the tests cover both sides.
  • HasMemoryOperand was compared against /usr/bin/objdump -d for the GS-prefixed instructions of /usr/lib/dyld, libsystem_pthread.dylib, libsystem_kernel.dylib, libsystem_platform.dylib, libdispatch.dylib and /usr/lib/ignition (306 unique instructions): no instruction whose disassembly uses %gs: was reported as having no memory operand.
  • python3 tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4926223366 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-10-19T19:25:45Z. --- ### What #6458 (macOS) and #6102 (Windows) replace every guest instruction that carries a GS segment prefix by `UD2` and NOP padding. A GS prefix on an instruction without a memory operand (`65 90`, `65 48 89 c8`, `65 0f a2`) is architecturally ignored and does not touch GS, so the instruction can run unchanged in the converted output, but it currently faults. `docs/dev/debt/relinker.md` records the macOS case, with those two byte examples, as a known gap. - `DecodedInstructionInfo` gains `HasMemoryOperand`: set for a ModRM memory operand (`mod != 3`, including the Group 5 indirect call/jump path and VEX/EVEX/XOP instructions) and for the encodings whose memory operand is implicit (INS/OUTS, MOV moffs, MOVS/CMPS/STOS/LODS/SCAS, XLATB, MASKMOVQ/MASKMOVDQU/VMASKMOVDQU, MONITOR/MONITORX, UMONITOR and CLZERO). - The [Windows TLS builder](https://github.com/boykopovar/AnyPS5/blob/main/core/relinker/elfpatcher/src/windows/WindowsTlsBuilder.cpp) and the [macOS TLS scan](https://github.com/boykopovar/AnyPS5/blob/main/core/relinker/elfpatcher/src/macos/MacOsImage.cpp) trap a GS-prefixed instruction only when `HasMemoryOperand` is set. A GS-prefixed instruction without a memory operand is left unchanged and executes with the ignored prefix. - The Windows `gs_traps` and `gs_traps_implicit` groups and `test_macos_gs_traps.py` gain `65 90`, `65 48 89 c8`, `65 0f a2`, the implicit-memory `65 66 0f f7 c1`, `65 0f f7 c1`, `65 c5 f9 f7 c1`, `65 0f 01 c8`, `65 0f 01 fa`, `65 0f 01 fc` and `65 f3 0f ae f0`, and the non-memory `65 0f 01 c9` (MWAIT), `65 0f 01 fd` (RDPRU) and `65 f2 0f ae f0` (UMWAIT) as negative cases. The decoder test also covers the three-byte VEX form `65 c4 e1 79 f7 c1`. The macOS debt entry no longer records the no-memory case. - Overlap: open PR #7706 adds a "branch into a trapped GS instruction" refusal whose case is `74 01 65 b8 2a 00 00 00 c3`; `65 b8 2a 00 00 00` has no memory operand and no longer traps here, so if #7706 lands after this change its case needs a memory-operand instruction (for example `65 8b 05 ...`). Nothing else in #7706 changes. ### Tested macOS 15.7.7, x86_64, AppleClang, relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON`) on this branch rebased onto `main` 49fd13a74: - `ctest` 210/210 pass. - The Windows GS cases are split into `gs_traps` (9 cases) and `gs_traps_implicit` (10 cases) so each stays well under its 30 s CTest timeout; the combined group ran close to that limit on a loaded Windows host. - The five implicit-memory encodings from the review (`65 66 0f f7 c1`, `65 0f f7 c1`, `65 c5 f9 f7 c1`, `65 0f 01 c8`, `65 0f 01 fa`), the `mov rax, gs:[rax]` control, `UMONITOR` (`65 f3 0f ae f0`) and `CLZERO` (`65 0f 01 fc`) convert to `UD2` and NOP padding in Windows output; `65 90`, `65 0f 01 c9`, `65 0f 01 fd`, `65 f2 0f ae f0` and `65 66 0f ae f0` remain unchanged. VEX2 and VEX3 `VMASKMOVDQU` are covered by the decoder test. - Reverting the decoder change leaves the seven implicit-memory encodings unchanged in both tests; reverting the two writer changes traps `gs-nop` again, so the tests cover both sides. - `HasMemoryOperand` was compared against `/usr/bin/objdump -d` for the GS-prefixed instructions of `/usr/lib/dyld`, `libsystem_pthread.dylib`, `libsystem_kernel.dylib`, `libsystem_platform.dylib`, `libdispatch.dylib` and `/usr/lib/ignition` (306 unique instructions): no instruction whose disassembly uses `%gs:` was reported as having no memory operand. - `python3 tools/check_conventions.py --base origin/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-19 19:34:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T19:34:25Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7706 core/relinker/relinker/tests/test_macos_gs_traps.py L40

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7532 core/relinker/CMakeLists.txt
PR 7918 docs/dev/debt/relinker.md
PR 8076 docs/dev/debt/relinker.md
PR 8658 core/relinker/elfpatcher/src/macos/MacOsImage.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6275600959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6275600959). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T19:34:25Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7706](https://www.github.com/boykopovar/AnyPS5/pull/7706) | `core/relinker/relinker/tests/test_macos_gs_traps.py` [L40](https://github.com/boykopovar/AnyPS5/blob/9f4ddf7cf985d80e2885ee3942fe48871e4a5e5a/core/relinker/relinker/tests/test_macos_gs_traps.py#L40) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7532](https://www.github.com/boykopovar/AnyPS5/pull/7532) | `core/relinker/CMakeLists.txt` | | [PR 7918](https://www.github.com/boykopovar/AnyPS5/pull/7918) | `docs/dev/debt/relinker.md` | | [PR 8076](https://www.github.com/boykopovar/AnyPS5/pull/8076) | `docs/dev/debt/relinker.md` | | [PR 8658](https://www.github.com/boykopovar/AnyPS5/pull/8658) | `core/relinker/elfpatcher/src/macos/MacOsImage.cpp` |
AasishDairelSahayaGrinspan commented 2026-10-19 19:35:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-19T19:35:31Z.


Could a maintainer run the manual Build workflow on main for this PR (8063)? Locally I ran the relinker-only Release build on macOS 15.7.7 (x86_64, AppleClang): ctest 208/208 pass, and the two new GS regression cases fail when only the Windows/macOS writer changes are reverted. The relinker matrix has not been covered by a local run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6275621372 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6275621372). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-10-19T19:35:31Z. --- Could a maintainer run the manual Build workflow on `main` for this PR (8063)? Locally I ran the relinker-only Release build on macOS 15.7.7 (x86_64, AppleClang): `ctest` 208/208 pass, and the two new GS regression cases fail when only the Windows/macOS writer changes are reverted. The relinker matrix has not been covered by a local run.
wachi35676 commented 2026-10-19 23:17:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T23:17:44Z.


Verdict: defect. Some GS-prefixed instructions with an implicit memory operand are no longer trapped.

HasMemoryOperand is set only for a ModRM memory form and for opcodes 6C-6F, A0-A7, AA-AF and D7. Some instructions use a register-form ModRM byte but still access memory at DS:rDI or DS:rAX, and a GS override applies to that access. This PR leaves them unchanged in Windows output, while main traps them:

bytes instruction main --windows this PR --windows
65 48 8b 00 mov rax, gs:[rax] (control) 0f 0b 90 90 0f 0b 90 90
65 66 0f f7 c1 maskmovdqu xmm0, xmm1 (stores to DS:rDI) 0f 0b 90 90 90 65 66 0f f7 c1
65 0f f7 c1 maskmovq mm0, mm1 0f 0b 90 90 unchanged
65 c5 f9 f7 c1 vmaskmovdqu xmm0, xmm1 0f 0b 90 90 90 unchanged
65 0f 01 c8 monitor (DS:rAX) 0f 0b 90 90 unchanged
65 0f 01 fa monitorx (DS:rAX) 0f 0b 90 90 unchanged
65 90 nop 0f 0b 65 90 (intended)

Each image is make_image("register", "unwind", body=<bytes> + c3) from test_tls_function_coverage.py, converted with relinker --skip-sce-module --windows. The bytes shown are read back at RVA 0x11240.

The prefix is honoured on hardware. A native MinGW program on this Ryzen 5 9600X ran mov rdi, 0x28 followed by 65 66 0f f7 c1 with an 8-byte mask, and that wrote TEB+0x28 (gs:[0x28] read 0 before and a7a6a5a4a3a2a1a0 after). The Intel SDM entries for MASKMOVDQU/MASKMOVQ and MONITOR say the default DS segment can be overridden. Left unconverted, these instructions read or write relative to the host's GS (the Windows TEB) instead of faulting. One way to cover them: set HasMemoryOperand for 0F F7 (legacy and VEX) and for 0F 01 C8/0F 01 FA, and add those encodings to gs_traps.

The rest checks out here. Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release build of this PR merged onto main 9127ea36d:

  • ctest -j4 212/212 pass. The new gs-nop, gs-register-move and gs-cpuid cases convert unchanged here, and main traps 65 90.
  • Linux, WSL Ubuntu 24.04, GCC 13.3: 216/217 pass. The one failure, shader_cache_runtime_sources, also fails on main in the same environment.
  • I relinked four homebrew titles with main and with this PR, using --windows --to-intel, --macos --to-rosetta and Linux --to-intel, all with --trap-sdk-syscall-stubs. The titles were PS5 OpenGL Showcase 1.0.2 (PPSA99005), PPSA47402, PS5LM Plus 0.8.4 (PPSA99581), and Prospero Win v0.2.0 (PPSA99995) with its 16 Wine x86_64-unix modules via --module-dir. All 12 output sets are byte-identical to main, so the six GS instructions in Prospero Win's ntdll are memory forms and still trap.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279476041 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6279476041). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-19T23:17:44Z. --- Verdict: defect. Some GS-prefixed instructions with an implicit memory operand are no longer trapped. `HasMemoryOperand` is set only for a ModRM memory form and for opcodes 6C-6F, A0-A7, AA-AF and D7. Some instructions use a register-form ModRM byte but still access memory at DS:rDI or DS:rAX, and a GS override applies to that access. This PR leaves them unchanged in Windows output, while `main` traps them: | bytes | instruction | `main` `--windows` | this PR `--windows` | |---|---|---|---| | `65 48 8b 00` | `mov rax, gs:[rax]` (control) | `0f 0b 90 90` | `0f 0b 90 90` | | `65 66 0f f7 c1` | `maskmovdqu xmm0, xmm1` (stores to DS:rDI) | `0f 0b 90 90 90` | `65 66 0f f7 c1` | | `65 0f f7 c1` | `maskmovq mm0, mm1` | `0f 0b 90 90` | unchanged | | `65 c5 f9 f7 c1` | `vmaskmovdqu xmm0, xmm1` | `0f 0b 90 90 90` | unchanged | | `65 0f 01 c8` | `monitor` (DS:rAX) | `0f 0b 90 90` | unchanged | | `65 0f 01 fa` | `monitorx` (DS:rAX) | `0f 0b 90 90` | unchanged | | `65 90` | `nop` | `0f 0b` | `65 90` (intended) | Each image is `make_image("register", "unwind", body=<bytes> + c3)` from `test_tls_function_coverage.py`, converted with `relinker --skip-sce-module --windows`. The bytes shown are read back at RVA 0x11240. The prefix is honoured on hardware. A native MinGW program on this Ryzen 5 9600X ran `mov rdi, 0x28` followed by `65 66 0f f7 c1` with an 8-byte mask, and that wrote TEB+0x28 (`gs:[0x28]` read 0 before and `a7a6a5a4a3a2a1a0` after). The Intel SDM entries for MASKMOVDQU/MASKMOVQ and MONITOR say the default DS segment can be overridden. Left unconverted, these instructions read or write relative to the host's GS (the Windows TEB) instead of faulting. One way to cover them: set `HasMemoryOperand` for `0F F7` (legacy and VEX) and for `0F 01 C8`/`0F 01 FA`, and add those encodings to `gs_traps`. The rest checks out here. Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release build of this PR merged onto `main` 9127ea36d: - `ctest -j4` 212/212 pass. The new `gs-nop`, `gs-register-move` and `gs-cpuid` cases convert unchanged here, and `main` traps `65 90`. - Linux, WSL Ubuntu 24.04, GCC 13.3: 216/217 pass. The one failure, `shader_cache_runtime_sources`, also fails on `main` in the same environment. - I relinked four homebrew titles with `main` and with this PR, using `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`, all with `--trap-sdk-syscall-stubs`. The titles were PS5 OpenGL Showcase 1.0.2 (PPSA99005), PPSA47402, PS5LM Plus 0.8.4 (PPSA99581), and Prospero Win v0.2.0 (PPSA99995) with its 16 Wine `x86_64-unix` modules via `--module-dir`. All 12 output sets are byte-identical to `main`, so the six GS instructions in Prospero Win's `ntdll` are memory forms and still trap. AI-assisted: yes (Claude Code); results above were run on this machine.
AasishDairelSahayaGrinspan commented 2026-10-20 04:45:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-20T04:45:54Z.


@wachi35676 thanks for the detailed check and the hardware validation. You are right: MASKMOVQ/MASKMOVDQU/VMASKMOVDQU and MONITOR/MONITORX use a register-form ModRM byte but still access memory at DS:rDI or DS:rAX, and the first version of HasMemoryOperand missed them.

Fixed in cde44070e, rebased onto main 49fd13a74:

  • HasMemoryOperand is now set for legacy 0F F7, VEX map-0F 0F F7, and 0F 01 C8/0F 01 FA.
  • gs_traps and test_macos_gs_traps.py now cover 65 66 0f f7 c1, 65 0f f7 c1, 65 c5 f9 f7 c1, 65 0f 01 c8 and 65 0f 01 fa; 65 0f 01 c9 (mwait, no memory operand) is a negative case. The decoder test also covers the three-byte VEX form 65 c4 e1 79 f7 c1.
  • Your table now reproduces as expected locally: all six implicit-memory cases trap to 0F 0B plus NOP padding, while 65 90 and 65 0f 01 c9 stay unchanged.
  • Relinker-only ctest is 209/209 on macOS after the rebase, and python3 tools/check_conventions.py --base origin/main passes.

I cannot run the Windows or Linux matrix locally, so a manual Build run on the new commit would still be useful. Could you re-test the Windows matrix when you have a chance?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6283593914 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6283593914). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-10-20T04:45:54Z. --- @wachi35676 thanks for the detailed check and the hardware validation. You are right: `MASKMOVQ`/`MASKMOVDQU`/`VMASKMOVDQU` and `MONITOR`/`MONITORX` use a register-form ModRM byte but still access memory at `DS:rDI` or `DS:rAX`, and the first version of `HasMemoryOperand` missed them. Fixed in `cde44070e`, rebased onto `main` `49fd13a74`: - `HasMemoryOperand` is now set for legacy `0F F7`, VEX map-0F `0F F7`, and `0F 01 C8`/`0F 01 FA`. - `gs_traps` and `test_macos_gs_traps.py` now cover `65 66 0f f7 c1`, `65 0f f7 c1`, `65 c5 f9 f7 c1`, `65 0f 01 c8` and `65 0f 01 fa`; `65 0f 01 c9` (`mwait`, no memory operand) is a negative case. The decoder test also covers the three-byte VEX form `65 c4 e1 79 f7 c1`. - Your table now reproduces as expected locally: all six implicit-memory cases trap to `0F 0B` plus NOP padding, while `65 90` and `65 0f 01 c9` stay unchanged. - Relinker-only `ctest` is 209/209 on macOS after the rebase, and `python3 tools/check_conventions.py --base origin/main` passes. I cannot run the Windows or Linux matrix locally, so a manual Build run on the new commit would still be useful. Could you re-test the Windows matrix when you have a chance?
AasishDairelSahayaGrinspan commented 2026-10-20 04:50:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-20T04:50:15Z.


One more from the same audit: UMONITOR (F3 0F AE /6, register-form ModRM) takes its effective address from the register operand and uses DS with segment overrides per the Intel SDM, so it was in the same gap. Added in a58d560c9:

  • 65 f3 0f ae f0 now traps; the register-form encoding is recognized by the F3 prefix and /6.
  • UMWAIT (65 f2 0f ae f0) and TPAUSE (65 66 0f ae f0) use the same opcode with different mandatory prefixes and have no memory operand, so they remain unchanged; gs-umwait is the negative case in both test suites.

Full relinker-only ctest is still 209/209 on macOS, and the decoder tests cover UMONITOR, UMWAIT, TPAUSE and INCSSP.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6283644932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6283644932). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-10-20T04:50:15Z. --- One more from the same audit: `UMONITOR` (`F3 0F AE /6`, register-form ModRM) takes its effective address from the register operand and uses DS with segment overrides per the Intel SDM, so it was in the same gap. Added in `a58d560c9`: - `65 f3 0f ae f0` now traps; the register-form encoding is recognized by the `F3` prefix and `/6`. - `UMWAIT` (`65 f2 0f ae f0`) and `TPAUSE` (`65 66 0f ae f0`) use the same opcode with different mandatory prefixes and have no memory operand, so they remain unchanged; `gs-umwait` is the negative case in both test suites. Full relinker-only `ctest` is still 209/209 on macOS, and the decoder tests cover `UMONITOR`, `UMWAIT`, `TPAUSE` and `INCSSP`.
wachi35676 commented 2026-10-20 05:02:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T05:02:50Z.


I re-tested a58d560c9 merged onto main 329b9aa1a. All five cases from my earlier table now trap, and so does UMONITOR. One more register-form instruction is still missed: AMD CLZERO (0F 01 FC).

bytes instruction main this PR
65 66 0f f7 c1 / 65 0f f7 c1 / 65 c5 f9 f7 c1 / 65 c4 e1 79 f7 c1 maskmovdqu / maskmovq / vmaskmovdqu (2- and 3-byte VEX) trap trap
65 0f 01 c8 / 65 0f 01 fa monitor / monitorx trap trap
65 f3 0f ae f0 umonitor trap trap
65 f2 0f ae f0 / 65 66 0f ae f0 umwait / tpause trap unchanged
65 0f 01 c9 / 65 0f 01 fb mwait / mwaitx trap unchanged
65 90, 65 48 89 c8, 65 0f a2, 65 0f ae f8 nop / mov rax,rcx / cpuid / sfence trap unchanged
65 0f ae 38, 65 66 0f 38 f8 01, 65 f2 0f 38 f8 01, 65 d7, 65 a4 clflush [rax] / movdir64b / enqcmd / xlat / movsb trap trap
65 0f 01 fc clzero (rAX) trap unchanged

The method is the same as before: make_image("register", "unwind", body=<bytes> + c3), relinker --skip-sce-module --windows, bytes read back at RVA 0x11240. Here "trap" means 0f 0b plus NOP padding. Leaving UMWAIT and TPAUSE unchanged matches the SDM: the r32 operand is a control value and Mod must be 11B, so there is no memory operand. MOVDIR64B, ENQCMD and CLFLUSH have only memory-form ModRM encodings, so the existing ModRM check already covers them.

The CLZERO gap is real on hardware. The AMD APM describes CLZERO as clearing "the cache line specified by the logical address in rAX" and says it performs the segmentation checks a store would. I ran a native MinGW program on this Ryzen 5 9600X (CPUID 8000_0008 EBX[0] = 1) with a 64-byte buffer filled with 0xAA and rax = buffer - TEB:

  • 0f 01 fc without a prefix faulted once and left the buffer untouched.
  • 65 0f 01 fc did not fault and zeroed the buffer. The GS base is applied, so it clears a line relative to the host TEB.
  • 0f 01 fc with rax = buffer (control) zeroed the buffer.

Adding info.ModRmByte == 0xFC next to 0xC8/0xFA in the TwoByteGrp7 branch, with a gs-clzero case in gs_traps and test_macos_gs_traps.py, would cover it.

Everything else passes on this machine (Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, relinker-only Release):

  • Windows ctest -j4: 214/214 pass on main and 214/214 with the PR, including decoder_length, tls_function_coverage_gs_traps and macos_gs_traps.
  • WSL Ubuntu 24.04, GCC 13.3: 219/219 pass on main and 219/219 with the PR.
  • I relinked the same four homebrew titles as before (PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with its 16 Wine modules) with --windows --to-intel, --macos --to-rosetta and Linux --to-intel, all with --trap-sdk-syscall-stubs. All 12 output sets are byte-identical to main.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6283794297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6283794297). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T05:02:50Z. --- I re-tested `a58d560c9` merged onto `main` 329b9aa1a. All five cases from my earlier table now trap, and so does UMONITOR. One more register-form instruction is still missed: AMD `CLZERO` (`0F 01 FC`). | bytes | instruction | `main` | this PR | |---|---|---|---| | `65 66 0f f7 c1` / `65 0f f7 c1` / `65 c5 f9 f7 c1` / `65 c4 e1 79 f7 c1` | maskmovdqu / maskmovq / vmaskmovdqu (2- and 3-byte VEX) | trap | trap | | `65 0f 01 c8` / `65 0f 01 fa` | monitor / monitorx | trap | trap | | `65 f3 0f ae f0` | umonitor | trap | trap | | `65 f2 0f ae f0` / `65 66 0f ae f0` | umwait / tpause | trap | unchanged | | `65 0f 01 c9` / `65 0f 01 fb` | mwait / mwaitx | trap | unchanged | | `65 90`, `65 48 89 c8`, `65 0f a2`, `65 0f ae f8` | nop / mov rax,rcx / cpuid / sfence | trap | unchanged | | `65 0f ae 38`, `65 66 0f 38 f8 01`, `65 f2 0f 38 f8 01`, `65 d7`, `65 a4` | clflush [rax] / movdir64b / enqcmd / xlat / movsb | trap | trap | | `65 0f 01 fc` | **clzero** (rAX) | trap | **unchanged** | The method is the same as before: `make_image("register", "unwind", body=<bytes> + c3)`, `relinker --skip-sce-module --windows`, bytes read back at RVA 0x11240. Here "trap" means `0f 0b` plus NOP padding. Leaving UMWAIT and TPAUSE unchanged matches the SDM: the r32 operand is a control value and Mod must be 11B, so there is no memory operand. MOVDIR64B, ENQCMD and CLFLUSH have only memory-form ModRM encodings, so the existing ModRM check already covers them. The CLZERO gap is real on hardware. The AMD APM describes CLZERO as clearing "the cache line specified by the logical address in rAX" and says it performs the segmentation checks a store would. I ran a native MinGW program on this Ryzen 5 9600X (CPUID 8000_0008 EBX[0] = 1) with a 64-byte buffer filled with `0xAA` and `rax = buffer - TEB`: - `0f 01 fc` without a prefix faulted once and left the buffer untouched. - `65 0f 01 fc` did not fault and zeroed the buffer. The GS base is applied, so it clears a line relative to the host TEB. - `0f 01 fc` with `rax = buffer` (control) zeroed the buffer. Adding `info.ModRmByte == 0xFC` next to `0xC8`/`0xFA` in the `TwoByteGrp7` branch, with a `gs-clzero` case in `gs_traps` and `test_macos_gs_traps.py`, would cover it. Everything else passes on this machine (Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, relinker-only Release): - Windows `ctest -j4`: 214/214 pass on `main` and 214/214 with the PR, including `decoder_length`, `tls_function_coverage_gs_traps` and `macos_gs_traps`. - WSL Ubuntu 24.04, GCC 13.3: 219/219 pass on `main` and 219/219 with the PR. - I relinked the same four homebrew titles as before (PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with its 16 Wine modules) with `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`, all with `--trap-sdk-syscall-stubs`. All 12 output sets are byte-identical to `main`. AI-assisted: yes (Claude Code); results above were run on this machine.
AasishDairelSahayaGrinspan commented 2026-10-20 05:24:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-20T05:24:16Z.


@wachi35676 thanks for the hardware CLZERO test — you are right, the GS base is applied. Fixed in a0e591c93:

  • 0F 01 FC now joins 0F 01 C8/0F 01 FA in the group-7 implicit-memory set.
  • gs-clzero is added to gs_traps and test_macos_gs_traps.py; RDPRU (65 0f 01 fd) is the negative case.
  • Local repro: 65 0f 01 fc now converts to 0F 0B + NOP padding; 65 0f 01 fd stays unchanged.
  • Full relinker-only ctest is 209/209 on macOS, and check_conventions.py passes.

Please re-run the Windows/Linux matrix on a0e591c93 when you have a chance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284055051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6284055051). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-10-20T05:24:16Z. --- @wachi35676 thanks for the hardware `CLZERO` test — you are right, the GS base is applied. Fixed in `a0e591c93`: - `0F 01 FC` now joins `0F 01 C8`/`0F 01 FA` in the group-7 implicit-memory set. - `gs-clzero` is added to `gs_traps` and `test_macos_gs_traps.py`; `RDPRU` (`65 0f 01 fd`) is the negative case. - Local repro: `65 0f 01 fc` now converts to `0F 0B` + NOP padding; `65 0f 01 fd` stays unchanged. - Full relinker-only `ctest` is 209/209 on macOS, and `check_conventions.py` passes. Please re-run the Windows/Linux matrix on `a0e591c93` when you have a chance.
wachi35676 commented 2026-10-20 06:08:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T06:08:23Z.


I re-tested a0e591c93 merged onto main 1ed63f63c, and CLZERO is now trapped. I found nothing else.

  • Probe: I re-ran the same 22 cases as before, plus rdpru and two prefixed CLZERO forms, through relinker --skip-sce-module --windows. The bytes were read back at RVA 0x11240.
    • Now trapped (0f 0b + NOPs): 65 0f 01 fc (clzero), 65 67 0f 01 fc (32-bit address) and 65 48 0f 01 fc (REX.W).
    • Left unchanged: 65 0f 01 fd (rdpru).
    • The other 22 results are identical to my previous table.
  • RDPRU: the AMD APM defines it as reading the register selected by ECX into EDX:EAX, with no memory operand, so leaving it alone is correct. On this Ryzen 5 9600X (CPUID 8000_0008 EBX[4] = 1, max id 1), native 0f 01 fd and 65 0f 01 fd with ECX = 0 and 1 both return MPERF/APERF without faulting. The GS prefix has no effect.
  • Negative control: I reverted only the X64InstructionDecoder.cpp hunk. Three tests then fail:
    • decoder_length: "Wrong memory operand presence for 650f01fc"
    • tls_function_coverage_gs_traps: ('gs-clzero', '650f01fcc3')
    • macos_gs_traps: "gs-clzero: the GS access was not replaced by ud2 and NOP padding"
  • Windows (11 Home 10.0.26300, WinLibs GCC 15.2.0, relinker-only Release): ctest -j4 passes 215/215 on main and 215/215 with the PR.
  • WSL (Ubuntu 24.04, GCC 13.3): 220/220 on main and 220/220 with the PR.
  • Homebrew: PPSA99005, PPSA47402, PPSA99581 and PPSA99995 (with its 16 modules), relinked with --windows --to-intel, --macos --to-rosetta and Linux --to-intel, all with --trap-sdk-syscall-stubs. All 12 output sets are byte-identical to main.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284610834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6284610834). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T06:08:23Z. --- I re-tested `a0e591c93` merged onto `main` 1ed63f63c, and CLZERO is now trapped. I found nothing else. - **Probe:** I re-ran the same 22 cases as before, plus `rdpru` and two prefixed CLZERO forms, through `relinker --skip-sce-module --windows`. The bytes were read back at RVA 0x11240. - Now trapped (`0f 0b` + NOPs): `65 0f 01 fc` (clzero), `65 67 0f 01 fc` (32-bit address) and `65 48 0f 01 fc` (REX.W). - Left unchanged: `65 0f 01 fd` (rdpru). - The other 22 results are identical to my previous table. - **RDPRU:** the AMD APM defines it as reading the register selected by ECX into EDX:EAX, with no memory operand, so leaving it alone is correct. On this Ryzen 5 9600X (CPUID 8000_0008 EBX[4] = 1, max id 1), native `0f 01 fd` and `65 0f 01 fd` with ECX = 0 and 1 both return MPERF/APERF without faulting. The GS prefix has no effect. - **Negative control:** I reverted only the `X64InstructionDecoder.cpp` hunk. Three tests then fail: - `decoder_length`: "Wrong memory operand presence for 650f01fc" - `tls_function_coverage_gs_traps`: `('gs-clzero', '650f01fcc3')` - `macos_gs_traps`: "gs-clzero: the GS access was not replaced by ud2 and NOP padding" - **Windows** (11 Home 10.0.26300, WinLibs GCC 15.2.0, relinker-only Release): `ctest -j4` passes 215/215 on `main` and 215/215 with the PR. - **WSL** (Ubuntu 24.04, GCC 13.3): 220/220 on `main` and 220/220 with the PR. - **Homebrew:** PPSA99005, PPSA47402, PPSA99581 and PPSA99995 (with its 16 modules), relinked with `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`, all with `--trap-sdk-syscall-stubs`. All 12 output sets are byte-identical to `main`. AI-assisted: yes (Claude Code); results above were run on this machine.
AasishDairelSahayaGrinspan commented 2026-10-20 08:26:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-20T08:26:42Z.


Thanks for the thorough re-test and the negative control — good to have the prefixed CLZERO forms covered too. No further changes on my side; the head is a0e591c93. The only remaining item is the manual Build workflow and maintainer review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286768680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6286768680). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-10-20T08:26:42Z. --- Thanks for the thorough re-test and the negative control — good to have the prefixed CLZERO forms covered too. No further changes on my side; the head is `a0e591c93`. The only remaining item is the manual Build workflow and maintainer review.
screamm commented 2026-10-20 13:43:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-20T13:43:02Z.


Windows run of a0e591c93 merged onto main d50ec76da (merges cleanly).

Host: Windows 11 Pro 26220, Ryzen 7 5700X, NVIDIA GeForce RTX 4070 driver 596.21, WinLibs MinGW-w64 GCC 15.2 r7, Release, relinker-only build (-DANYPS5_RELINKER_ONLY=ON); libs from a full build of the same main for the title boots.

  • PR tests: decoder_length 3/3 and macos_gs_traps 3/3 under ctest. tls_function_coverage_gs_traps passed 3/3 run directly (26-30 s each). Under ctest it timed out once at its 30 s TIMEOUT, because the host was loaded by other builds. On main the same group takes 10-18 s here; the PR grows it from 8 to 21 cases, so on a slow Windows box it now runs close to that limit.
  • Negative control: with only WindowsTlsBuilder.cpp restored from main, gs_traps fails with AssertionError: ('gs-nop', '0f0bc3'). With the PR's file back, it passes.
  • Relink of 51 local homebrew titles (all with an eboot.elf, including Showcase PPSA99005 and Prospero Win PPSA99995 with its 16 Wine modules), default Linux target and --windows, main vs PR. The 5 largest executables ran 3 times each and the rest once. Every output file (executables, guest modules, registry and needed JSON) has the same sha256 as main, so none of these titles has a GS-prefixed instruction without a memory operand in its converted code. PPSA99360 --windows fails the same way on main and on the PR (Base relocation target crosses a page boundary (offset 0x3243fff)).
  • Relink time: no change. Default target, sum of medians over 51 titles: 119.5 s on main, 123.5 s with the PR; user CPU 15.5 s vs 15.4 s. --windows: 844.3 s vs 843.3 s; user CPU 536.8 s vs 543.3 s. The largest per-title difference is 0.6 s (default) and 2.5 s (--windows). The two relinkers ran side by side for every sample.
  • Boots (--windows, 60 s each, RTX 4070): PPSA99005 and PPSA99995 were still running at 60 s with both main and the PR (162/175 and 41/48 frames; low counts because the host was loaded), and neither printed a stop line.
  • python tools/check_conventions.py --base origin/main passes, and git diff origin/main --check is clean.

Not checked: macOS and Rosetta outputs, a hardware probe of the encodings on this CPU, and the full relinker suite under a quiet host (a -j3 run gave 190/223 with the other 33 at their hard-coded 20-300 s limits on this loaded host, and a serial rerun was cut short by a host problem).

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6292283454 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6292283454). Originally posted by [screamm](https://github.com/screamm) on 2026-10-20T13:43:02Z. --- Windows run of `a0e591c93` merged onto `main` `d50ec76da` (merges cleanly). Host: Windows 11 Pro 26220, Ryzen 7 5700X, NVIDIA GeForce RTX 4070 driver 596.21, WinLibs MinGW-w64 GCC 15.2 r7, Release, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON`); `libs` from a full build of the same `main` for the title boots. - **PR tests:** `decoder_length` 3/3 and `macos_gs_traps` 3/3 under ctest. `tls_function_coverage_gs_traps` passed 3/3 run directly (26-30 s each). Under ctest it timed out once at its 30 s `TIMEOUT`, because the host was loaded by other builds. On `main` the same group takes 10-18 s here; the PR grows it from 8 to 21 cases, so on a slow Windows box it now runs close to that limit. - **Negative control:** with only `WindowsTlsBuilder.cpp` restored from `main`, `gs_traps` fails with `AssertionError: ('gs-nop', '0f0bc3')`. With the PR's file back, it passes. - **Relink of 51 local homebrew titles** (all with an `eboot.elf`, including Showcase PPSA99005 and Prospero Win PPSA99995 with its 16 Wine modules), default Linux target and `--windows`, `main` vs PR. The 5 largest executables ran 3 times each and the rest once. Every output file (executables, guest modules, registry and needed JSON) has the same sha256 as `main`, so none of these titles has a GS-prefixed instruction without a memory operand in its converted code. PPSA99360 `--windows` fails the same way on `main` and on the PR (`Base relocation target crosses a page boundary (offset 0x3243fff)`). - **Relink time:** no change. Default target, sum of medians over 51 titles: 119.5 s on `main`, 123.5 s with the PR; user CPU 15.5 s vs 15.4 s. `--windows`: 844.3 s vs 843.3 s; user CPU 536.8 s vs 543.3 s. The largest per-title difference is 0.6 s (default) and 2.5 s (`--windows`). The two relinkers ran side by side for every sample. - **Boots** (`--windows`, 60 s each, RTX 4070): PPSA99005 and PPSA99995 were still running at 60 s with both `main` and the PR (162/175 and 41/48 frames; low counts because the host was loaded), and neither printed a stop line. - `python tools/check_conventions.py --base origin/main` passes, and `git diff origin/main --check` is clean. Not checked: macOS and Rosetta outputs, a hardware probe of the encodings on this CPU, and the full relinker suite under a quiet host (a `-j3` run gave 190/223 with the other 33 at their hard-coded 20-300 s limits on this loaded host, and a serial rerun was cut short by a host problem). Written with Claude Code assistance (validation by a subagent, reviewed in this session).
AasishDairelSahayaGrinspan commented 2026-10-20 16:25:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-10-20T16:25:04Z.


Thanks for the Windows run and for catching the timing risk.

I split the combined case set so the 30 s limit is no longer in play:

  • tls_function_coverage_gs_traps: the original 8 cases plus gs-without-pt-tls (9 relinker runs).
  • tls_function_coverage_gs_traps_implicit: the 7 implicit-memory positives plus the MWAIT/RDPRU/UMWAIT negatives (10 relinker runs).
  • Both are registered in CMake and share one per-case checker; all still runs both.

Local macOS relinker-only ctest is 210/210, and both groups pass when run directly. This adds one CTest entry, so the Windows count goes from 215 to 216. Head is 0d3f6f726, one test-only commit on top of a0e591c93; the functional code is unchanged. Could you re-run the Windows matrix and the ctest timing when you have a chance?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6295741474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8063#issuecomment-6295741474). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-10-20T16:25:04Z. --- Thanks for the Windows run and for catching the timing risk. I split the combined case set so the 30 s limit is no longer in play: - `tls_function_coverage_gs_traps`: the original 8 cases plus `gs-without-pt-tls` (9 relinker runs). - `tls_function_coverage_gs_traps_implicit`: the 7 implicit-memory positives plus the MWAIT/RDPRU/UMWAIT negatives (10 relinker runs). - Both are registered in CMake and share one per-case checker; `all` still runs both. Local macOS relinker-only `ctest` is 210/210, and both groups pass when run directly. This adds one CTest entry, so the Windows count goes from 215 to 216. Head is `0d3f6f726`, one test-only commit on top of `a0e591c93`; the functional code is unchanged. Could you re-run the Windows matrix and the ctest timing when you have a chance?
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
boykopovar/AnyPS5!8063
No description provided.