feat(relinker): execute supported scalar guest GS accesses on Windows #11628

Open
Felipebmaitan wants to merge 29 commits from upstream-pr/11628 into main
Felipebmaitan commented 2026-10-26 23:45:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Felipebmaitan on 2026-10-26T23:45:23Z.


What

Replay supported scalar guest GS memory instructions against the Windows per-thread guest GS base. Unmodeled forms retain their own-length UD2 fallback.

Address MarcZX10’s November 14 review. A first-chance fault in replay leaves the live replay RIP, stack and scratch register available to a later Windows handler. Guest fault delivery receives the original guest context and retains callback edits to the continuation. If guest delivery declines, the runtime reports the guest location without claiming the fault is fatal. The terminal UD2 restores guest state and resumes at the next guest instruction.

Preserved published history and merged main eb09474ec2adb501b3454652157ef4a784af3bcf. The ELF changes retain main’s covered SCE RELRO file checks and #10518’s load and uncovered SCE RELRO alignment checks.

The November 27 conventions run on 5922e359e9 failed because the branch’s older libkernel.md masked four entries needed by upstream debt fragments. The refreshed branch carries its Windows GS wording in the existing macOS guest GS debt fragment, preserves the macOS wording, and removes the direct libkernel debt file edit. Failed conventions run

Draft pending #10518 and the #10861 integration gate. A trial merge with #10518’s current head conflicts in ElfReaderBoundsTests.cpp. #10861’s collector and callers need to retain generated-trap continuation entries when composed with scalar replay. The overlap scan covered 2,260 open PRs with 111 shared-file or export candidates and 37 inconclusive comparisons. #18523 shares the Windows entry-stub signatures and #19470 shares the ELF checks. The scan did not identify a competing scalar replay implementation. GitHub requires upstream write access for a formal re-request to MarcZX10. The review reply is posted in the conversation.

Merged main at 4a7fd1c405a7ff410d4f2fc1de9cbbdd19ed7d90. The Windows exception handler runs #27532’s CLZERO emulation after SSE4a and before GS fault projection. It preserves early GS trap handling and main’s GCC exception handoff. I trial-merged the 34 newly listed overlap candidates against the same base and the combined branch. They introduced no additional merge-conflict paths.

Tested

Windows x86-64 build 26300, Ryzen 7 9800X3D, WinLibs GCC 15.2 r7. The old f013da9725 replay handler failed the new late-handler test because the context had already been rewritten. The updated standalone runner passed all 50 scalar cases, including in-place retry of a load, a store and LOCK XADD.

The native libc component run passed the same 50 cases plus the guest-fault callback and unrepaired access-violation checks. The callback test validates original guest RIP, RSP, scratch registers and exception address, then verifies that edited RIP and RAX take effect. The unrepaired-fault test verifies the native exception code and guest-coordinate diagnostic. The component runs used historical converter and supporting objects with freshly compiled replay and reporting changes. The current entry-stub and ELF reader sources and bounds tests also passed when rebuilt against the archived relinker support library.

One independent reviewer checked 4446f4f0c4b4a0dc2e5241f492f34cd0c90b63aa, found no blocking source problem, and identified a gap covering callback-edited continuation registers. 870917228a closes that gap and the native component test passed again. The November 20 merge changed none of the replay or relinker files reviewed.

On d37ed55b75b2996cd37b778d7606c69863372b82, the native Release CMake/Ninja build completed with two compiler jobs. 52/52 focused CTests passed in 31.52 s, including standalone and production-libc scalar replay and fault retry, emitted executable and module startup, relocations, Windows entry-stub and ELF bounds, TLS coverage, and libkernel sysarch, pthread, signal context and exception delivery tests. JUnit SHA-256 77a4ce74546511713ba3344e3db417b6bc36f1af4ec419db61ffe8ab34ac4cca. Conventions and whitespace checks passed against origin/main 27d83474a0. Debt folding passed and the folded libkernel entry retains the macOS text and links to the Windows replay limits. The public-header audit verified 413 libraries and 35,066 exports. The earlier native Windows run also passed 52 focused tests at 5922e359e9.

On 1ae3585bef67d7561f12cecc4d763715903a97a6, all 52 focused Windows CTests passed in 32.78 s after rebuilding the relinker and production runtime with two compiler jobs. A separate injected illegal-instruction probe verified that the merged production libc.prx CLZERO handler clears exactly the addressed cache line and resumes. The Windows run of test_frame_capture_minimize_replay.py passed all 22 cases. Conventions, whitespace and debt folding passed against the integrated main. GitHub CI finished with 20 passing checks and 2 skipped. The macOS relinker job reported 1,027 CTests passed after integrating #27860’s cleanup fix. macOS CI

Historical evidence remains attached to its tested revisions. The previous description recorded 23 focused Windows tests on f013da9725. JJenkx independently tested that head on an earlier main merge. See JJenkx’s November 8 comment in this PR for the tested revisions.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: #10518
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5026347266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628). Originally posted by [Felipebmaitan](https://github.com/Felipebmaitan) on 2026-10-26T23:45:23Z. --- ### What Replay supported scalar guest GS memory instructions against the Windows per-thread guest GS base. Unmodeled forms retain their own-length UD2 fallback. Address MarcZX10’s November 14 review. A first-chance fault in replay leaves the live replay RIP, stack and scratch register available to a later Windows handler. Guest fault delivery receives the original guest context and retains callback edits to the continuation. If guest delivery declines, the runtime reports the guest location without claiming the fault is fatal. The terminal UD2 restores guest state and resumes at the next guest instruction. Preserved published history and merged main `eb09474ec2adb501b3454652157ef4a784af3bcf`. The ELF changes retain main’s covered SCE RELRO file checks and #10518’s load and uncovered SCE RELRO alignment checks. The November 27 conventions run on `5922e359e9` failed because the branch’s older `libkernel.md` masked four entries needed by upstream debt fragments. The refreshed branch carries its Windows GS wording in the existing macOS guest GS debt fragment, preserves the macOS wording, and removes the direct libkernel debt file edit. [Failed conventions run](https://github.com/boykopovar/AnyPS5/actions/runs/45903094043/job/140193317660) Draft pending #10518 and the #10861 integration gate. A trial merge with #10518’s current head conflicts in `ElfReaderBoundsTests.cpp`. #10861’s collector and callers need to retain generated-trap continuation entries when composed with scalar replay. The overlap scan covered 2,260 open PRs with 111 shared-file or export candidates and 37 inconclusive comparisons. #18523 shares the Windows entry-stub signatures and #19470 shares the ELF checks. The scan did not identify a competing scalar replay implementation. GitHub requires upstream write access for a formal re-request to MarcZX10. The review reply is posted in the conversation. Merged `main` at `4a7fd1c405a7ff410d4f2fc1de9cbbdd19ed7d90`. The Windows exception handler runs #27532’s CLZERO emulation after SSE4a and before GS fault projection. It preserves early GS trap handling and `main`’s GCC exception handoff. I trial-merged the 34 newly listed overlap candidates against the same base and the combined branch. They introduced no additional merge-conflict paths. ### Tested Windows x86-64 build 26300, Ryzen 7 9800X3D, WinLibs GCC 15.2 r7. The old `f013da9725` replay handler failed the new late-handler test because the context had already been rewritten. The updated standalone runner passed all 50 scalar cases, including in-place retry of a load, a store and LOCK XADD. The native libc component run passed the same 50 cases plus the guest-fault callback and unrepaired access-violation checks. The callback test validates original guest RIP, RSP, scratch registers and exception address, then verifies that edited RIP and RAX take effect. The unrepaired-fault test verifies the native exception code and guest-coordinate diagnostic. The component runs used historical converter and supporting objects with freshly compiled replay and reporting changes. The current entry-stub and ELF reader sources and bounds tests also passed when rebuilt against the archived relinker support library. One independent reviewer checked `4446f4f0c4b4a0dc2e5241f492f34cd0c90b63aa`, found no blocking source problem, and identified a gap covering callback-edited continuation registers. `870917228a` closes that gap and the native component test passed again. The November 20 merge changed none of the replay or relinker files reviewed. On `d37ed55b75b2996cd37b778d7606c69863372b82`, the native Release CMake/Ninja build completed with two compiler jobs. **52/52 focused CTests passed in 31.52 s**, including standalone and production-libc scalar replay and fault retry, emitted executable and module startup, relocations, Windows entry-stub and ELF bounds, TLS coverage, and libkernel sysarch, pthread, signal context and exception delivery tests. JUnit SHA-256 `77a4ce74546511713ba3344e3db417b6bc36f1af4ec419db61ffe8ab34ac4cca`. Conventions and whitespace checks passed against `origin/main` `27d83474a0`. Debt folding passed and the folded libkernel entry retains the macOS text and links to the Windows replay limits. The public-header audit verified 413 libraries and 35,066 exports. The earlier native Windows run also passed 52 focused tests at `5922e359e9`. On `1ae3585bef67d7561f12cecc4d763715903a97a6`, all **52 focused Windows CTests passed in 32.78 s** after rebuilding the relinker and production runtime with two compiler jobs. A separate injected illegal-instruction probe verified that the merged production `libc.prx` CLZERO handler clears exactly the addressed cache line and resumes. The Windows run of `test_frame_capture_minimize_replay.py` passed all 22 cases. Conventions, whitespace and debt folding passed against the integrated `main`. GitHub CI finished with 20 passing checks and 2 skipped. The macOS relinker job reported **1,027 CTests passed** after integrating #27860’s cleanup fix. [macOS CI](https://github.com/boykopovar/AnyPS5/actions/runs/46687914061/job/142787013971) Historical evidence remains attached to its tested revisions. The previous description recorded 23 focused Windows tests on `f013da9725`. JJenkx independently tested that head on an earlier main merge. See JJenkx’s November 8 comment in this PR for the tested revisions. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: <!-- #PR, or none --> #10518 - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-27 00:06:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T00:06:05Z.

Review: CHANGES_REQUESTED


Reviewed the feature commit 1bb3d0cfcb8a7cfe102b9384b8e723bca8925d32 separately from the explicitly listed prerequisite stack.

[P1] Decode address-size-32 mod=00, r/m=101 as absolute disp32, not RIP-relative. In WindowsGuestGs::Append, the mod == 0 && rm == 5 case always sets base = 0xfe (RIP-relative). But when address-size override 0x67 is present in 64-bit mode, this ModRM form uses an absolute 32-bit displacement. The runtime then adds the instruction resume address before truncating the effective offset to 32 bits (GuestGs.cpp), so e.g. 65 67 48 8b 05 00 00 00 00 reads from GS.base + (resume & 0xffffffff) instead of GS.base + 0. That can read or write the wrong guest location. The current address32-wrap fixture uses a SIB form and does not cover this special non-SIB form.

Please set the no-base sentinel for this encoding when AddressSize32 is true, preserve the 32-bit displacement as an unsigned effective offset, and add a 67 + mod=00/rm=101 execution fixture (zero displacement is enough with the existing runner's nonzero GS base). The relinker-only build is in progress locally; conventions and git diff --check pass, and the hosted Linux/Windows relinker checks currently pass. No local Windows runtime test is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5660717639 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5660717639). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T00:06:05Z. **Review:** CHANGES_REQUESTED --- Reviewed the feature commit `1bb3d0cfcb8a7cfe102b9384b8e723bca8925d32` separately from the explicitly listed prerequisite stack. **[P1] Decode address-size-32 `mod=00, r/m=101` as absolute disp32, not RIP-relative.** In `WindowsGuestGs::Append`, the `mod == 0 && rm == 5` case always sets `base = 0xfe` (RIP-relative). But when address-size override `0x67` is present in 64-bit mode, this ModRM form uses an absolute 32-bit displacement. The runtime then adds the instruction resume address before truncating the effective offset to 32 bits (`GuestGs.cpp`), so e.g. `65 67 48 8b 05 00 00 00 00` reads from `GS.base + (resume & 0xffffffff)` instead of `GS.base + 0`. That can read or write the wrong guest location. The current `address32-wrap` fixture uses a SIB form and does not cover this special non-SIB form. Please set the no-base sentinel for this encoding when `AddressSize32` is true, preserve the 32-bit displacement as an unsigned effective offset, and add a `67` + `mod=00/rm=101` execution fixture (zero displacement is enough with the existing runner's nonzero GS base). The relinker-only build is in progress locally; conventions and `git diff --check` pass, and the hosted Linux/Windows relinker checks currently pass. No local Windows runtime test is claimed.
MarcZX10 commented 2026-10-27 01:29:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T01:29:14Z.

Review: CHANGES_REQUESTED


Reviewed current head 87ef2af9591ba4fd21148fa1e1fd862d79f24abe. The unsupported-form UD2 fallback now appears to address the separate conversion-regression concern. A blocking address-size decoding issue remains in WindowsGuestGs::Append: for mod=00, r/m=101 the code always writes base sentinel 0xfe, which makes the runtime add the instruction resume address. With a 0x67 address-size override in 64-bit mode, this encoding is absolute disp32 with no base, not RIP-relative. The runtime then truncates the sum to 32 bits, so 65 67 48 8b 05 00 00 00 00 reads from GS.base + (resume & 0xffffffff) rather than GS.base + 0. The address32-wrap fixture uses a SIB form and does not cover this special non-SIB encoding.

Please select the no-base sentinel when AddressSize32 is true, preserve the unsigned 32-bit displacement, and add an execution fixture for 67 + mod=00/rm=101 (zero displacement with the runner's nonzero GS base is sufficient). This is still outstanding from my prior review and applies to this substantially updated head.

Validation: git diff --check upstream/main...upstream/pr/11628 passes. Hosted conventions and Linux/Windows relinker jobs pass; macOS relinker and one macOS register-context job remain in progress/queued. I did not run the Windows execution suite locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661215277 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5661215277). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T01:29:14Z. **Review:** CHANGES_REQUESTED --- Reviewed current head `87ef2af9591ba4fd21148fa1e1fd862d79f24abe`. The unsupported-form UD2 fallback now appears to address the separate conversion-regression concern. A blocking address-size decoding issue remains in `WindowsGuestGs::Append`: for `mod=00, r/m=101` the code always writes base sentinel `0xfe`, which makes the runtime add the instruction resume address. With a `0x67` address-size override in 64-bit mode, this encoding is absolute disp32 with no base, not RIP-relative. The runtime then truncates the sum to 32 bits, so `65 67 48 8b 05 00 00 00 00` reads from `GS.base + (resume & 0xffffffff)` rather than `GS.base + 0`. The `address32-wrap` fixture uses a SIB form and does not cover this special non-SIB encoding. Please select the no-base sentinel when `AddressSize32` is true, preserve the unsigned 32-bit displacement, and add an execution fixture for `67` + `mod=00/rm=101` (zero displacement with the runner's nonzero GS base is sufficient). This is still outstanding from my prior review and applies to this substantially updated head. Validation: `git diff --check upstream/main...upstream/pr/11628` passes. Hosted conventions and Linux/Windows relinker jobs pass; macOS relinker and one macOS register-context job remain in progress/queued. I did not run the Windows execution suite locally.
MarcZX10 commented 2026-10-27 01:33:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T01:33:58Z.

Review: APPROVED


Corrected my prior address-size finding: Intel SDM confirms mod=00, r/m=101 remains RIP-relative with 0x67 in 64-bit mode and the effective address is truncated to 32 bits. The current resume-relative calculation and truncation are correct. The UD2 fallback changes also address my earlier concern. I found no remaining blocker on this head. Hosted Linux/Windows relinker, ASan and the completed macOS jobs pass; the remaining macOS checks are still pending. The author reports extensive Windows/Linux execution fixtures; I did not independently rerun those suites.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661242102 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5661242102). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T01:33:58Z. **Review:** APPROVED --- Corrected my prior address-size finding: Intel SDM confirms `mod=00, r/m=101` remains RIP-relative with `0x67` in 64-bit mode and the effective address is truncated to 32 bits. The current resume-relative calculation and truncation are correct. The UD2 fallback changes also address my earlier concern. I found no remaining blocker on this head. Hosted Linux/Windows relinker, ASan and the completed macOS jobs pass; the remaining macOS checks are still pending. The author reports extensive Windows/Linux execution fixtures; I did not independently rerun those suites.
MarcZX10 commented 2026-10-29 10:01:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T10:01:46Z.

Review: APPROVED


Reviewed exact head 00cfc900d6c4feeefc6ac109ea674ee5ca54f939. The follow-up preserves the scalar replay and unsupported-instruction UD2 fallback, adds/retains the address-size override regression cases, and integrates the current-main thread startup changes without merge conflicts. git diff --check and the repository convention check pass against current main. The author reports fresh Windows and Linux production libc/libkernel builds, 61 focused Windows relinker checks and 59 focused Linux runtime/relinker checks in the latest validation, plus fixture parity; I did not independently rerun those suites locally. No console/title behavior is claimed. I found no remaining blocking issue in the reviewed change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695919684 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5695919684). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T10:01:46Z. **Review:** APPROVED --- Reviewed exact head `00cfc900d6c4feeefc6ac109ea674ee5ca54f939`. The follow-up preserves the scalar replay and unsupported-instruction UD2 fallback, adds/retains the address-size override regression cases, and integrates the current-main thread startup changes without merge conflicts. `git diff --check` and the repository convention check pass against current main. The author reports fresh Windows and Linux production libc/libkernel builds, 61 focused Windows relinker checks and 59 focused Linux runtime/relinker checks in the latest validation, plus fixture parity; I did not independently rerun those suites locally. No console/title behavior is claimed. I found no remaining blocking issue in the reviewed change.
MarcZX10 commented 2026-10-30 04:03:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T04:03:39Z.

Review: COMMENTED


Re-checked — new head, current-main integration needs validation

The scalar GS fixtures and prior correction remain sound, but current main now changes the shared Windows entry-stub builder and adds a bounds test that the reported runtime runs predate.

What I ran

  • Exact PR head: cedb9ac8cddc5083dff0b477dd406313ec8a6bcc; PR base: 1189ec3003672bb364dd9f3119ead7b3976e3c83.
  • Compared against current main 5ecef095b61e7a406b279c97896f3a8a6fbd6353; merge preview was clean, tree 729dc713fab2e47fca5e6ae1b26762866013cccf.
  • Environment: Linux x86_64; no compiler or local tests run.
git merge-tree --write-tree upstream/main refs/review/pr-11628-current
git diff --check upstream/main...refs/review/pr-11628-current
python tools/check_conventions.py --base upstream/main --head refs/review/pr-11628-current
python tools/check_main_sync.py --base upstream/main --head refs/review/pr-11628-current

Results

Check Result
Current-main merge preview Clean; tree 729dc713fab2e47fca5e6ae1b26762866013cccf
git diff --check Passed; no output
Repository conventions Passed
Main synchronization Four touched files changed on both sides since base
Hosted checks Windows, Ubuntu/Windows relinker, relinker ASan, Ubuntu register-context, conventions, eligibility, labels and report pass on the exact PR head; Linux product CI is skipped. Several macOS checks are queued.
Author-reported focused runtime tests Windows and Linux runs report passing after the four 0x67/mod=00,r/m=101 execution cases were added, on an earlier integration. They were not run on the current-main merge.
Unedited local command output
$ git merge-tree --write-tree upstream/main refs/review/pr-11628-current
729dc713fab2e47fca5e6ae1b26762866013cccf
$ python tools/check_conventions.py --base upstream/main --head refs/review/pr-11628-current
All conventions checks passed.
$ python tools/check_main_sync.py --base upstream/main --head refs/review/pr-11628-current
refs/review/pr-11628-current is 18 ahead and 275 behind upstream/main (merge base 1189ec300)
merge: clean
4 file(s) changed on both sides since the merge base:
  core/libs/prx/libc/CMakeLists.txt
  core/relinker/CMakeLists.txt
  core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp
  docs/dev/debt/libkernel.md

git diff --check exited 0 with no output.

Findings

Blocking

None found in the corrected 0x67 address calculation or the unsupported-instruction fallback.

Non-blocking

The merge preview includes current main's additional capacity/RVA checks in WindowsEntryStubBuilder::Build and its windows_entry_stub_bounds test. Those changes share a file with this PR's new GS-runtime setup. The exact-head hosted build passes, but the reported focused runtime results predate this current-main integration, so I am withholding a fresh approval until the combined entry-stub and GS execution tests are run.

Sources

Not verified

I did not build or run tests on the current-main merge. I did not verify behavior on a physical console or title workload.

To get this to a good state

Run windows_entry_stub_bounds, the focused Windows guest-GS conversion and execution tests, and the relinker tests on the current-main merge. Report the exact main and PR/merge SHAs; I will reassess that integration.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5707943584 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5707943584). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-30T04:03:39Z. **Review:** COMMENTED --- # Re-checked — new head, current-main integration needs validation The scalar GS fixtures and prior correction remain sound, but current `main` now changes the shared Windows entry-stub builder and adds a bounds test that the reported runtime runs predate. ## What I ran - Exact PR head: `cedb9ac8cddc5083dff0b477dd406313ec8a6bcc`; PR base: `1189ec3003672bb364dd9f3119ead7b3976e3c83`. - Compared against current `main` `5ecef095b61e7a406b279c97896f3a8a6fbd6353`; merge preview was clean, tree `729dc713fab2e47fca5e6ae1b26762866013cccf`. - Environment: Linux x86_64; no compiler or local tests run. ```sh git merge-tree --write-tree upstream/main refs/review/pr-11628-current git diff --check upstream/main...refs/review/pr-11628-current python tools/check_conventions.py --base upstream/main --head refs/review/pr-11628-current python tools/check_main_sync.py --base upstream/main --head refs/review/pr-11628-current ``` ## Results | Check | Result | |---|---| | Current-main merge preview | Clean; tree `729dc713fab2e47fca5e6ae1b26762866013cccf` | | `git diff --check` | Passed; no output | | Repository conventions | Passed | | Main synchronization | Four touched files changed on both sides since base | | Hosted checks | Windows, Ubuntu/Windows relinker, relinker ASan, Ubuntu register-context, conventions, eligibility, labels and report pass on the exact PR head; Linux product CI is skipped. Several macOS checks are queued. | | Author-reported focused runtime tests | Windows and Linux runs report passing after the four `0x67`/`mod=00,r/m=101` execution cases were added, on an earlier integration. They were not run on the current-main merge. | <details> <summary>Unedited local command output</summary> ```text $ git merge-tree --write-tree upstream/main refs/review/pr-11628-current 729dc713fab2e47fca5e6ae1b26762866013cccf $ python tools/check_conventions.py --base upstream/main --head refs/review/pr-11628-current All conventions checks passed. $ python tools/check_main_sync.py --base upstream/main --head refs/review/pr-11628-current refs/review/pr-11628-current is 18 ahead and 275 behind upstream/main (merge base 1189ec300) merge: clean 4 file(s) changed on both sides since the merge base: core/libs/prx/libc/CMakeLists.txt core/relinker/CMakeLists.txt core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp docs/dev/debt/libkernel.md ``` `git diff --check` exited 0 with no output. </details> ## Findings ### Blocking None found in the corrected `0x67` address calculation or the unsupported-instruction fallback. ### Non-blocking The merge preview includes current `main`'s additional capacity/RVA checks in `WindowsEntryStubBuilder::Build` and its `windows_entry_stub_bounds` test. Those changes share a file with this PR's new GS-runtime setup. The exact-head hosted build passes, but the reported focused runtime results predate this current-main integration, so I am withholding a fresh approval until the combined entry-stub and GS execution tests are run. ## Sources - [Shared entry-stub builder at current main](https://github.com/boykopovar/AnyPS5/blob/5ecef095b61e7a406b279c97896f3a8a6fbd6353/core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp) - [Author's GS fixture report](https://github.com/boykopovar/AnyPS5/pull/11628#issuecomment-6433475666) ## Not verified I did not build or run tests on the current-main merge. I did not verify behavior on a physical console or title workload. ## To get this to a good state Run `windows_entry_stub_bounds`, the focused Windows guest-GS conversion and execution tests, and the relinker tests on the current-main merge. Report the exact main and PR/merge SHAs; I will reassess that integration.
CnRJay commented 2026-11-01 19:49:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:28Z.

Review: COMMENTED


Correction (2026-11-01): this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows Unblocks: none; a title is only required when the PR fixes a title. The technical points below are unaffected.

No title ID and no log line. The body says "No PS5 or title execution". Maintainers close PRs that name no title ID plus a log line proving a title reaches the change on main. Which title executes scalar %gs: accesses on Windows today, and what does main log for it (the UD2 trap, I assume)?

Stacked branch. 22 commits and 32 files (+1000) because it carries the #11090 and #11276 prerequisite heads and #11624. #11661, #11689 and #11698 sit on top of this one and each repeats these commits. A reviewer has to separate the replay layer from the carried work by hand. Please keep it draft until #11624 and the prerequisites merge, or retarget onto that branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729922384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5729922384). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:28Z. **Review:** COMMENTED --- **Correction (2026-11-01):** this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows `Unblocks: none`; a title is only required when the PR fixes a title. The technical points below are unaffected. **No title ID and no log line.** The body says "No PS5 or title execution". Maintainers close PRs that name no title ID plus a log line proving a title reaches the change on main. Which title executes scalar `%gs:` accesses on Windows today, and what does main log for it (the UD2 trap, I assume)? **Stacked branch.** 22 commits and 32 files (+1000) because it carries the #11090 and #11276 prerequisite heads and #11624. #11661, #11689 and #11698 sit on top of this one and each repeats these commits. A reviewer has to separate the replay layer from the carried work by hand. Please keep it draft until #11624 and the prerequisites merge, or retarget onto that branch.
MarcZX10 commented 2026-11-14 07:09:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T07:09:43Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: make replay fault recovery distinguish a memory fault from a completed replay before redirecting the instruction pointer.

What I ran

Reviewed head f013da972573fa4dfca95607f2462501d6ad2234. Read the prepared description, commit list, manifest, diff, and all changed files listed as reviewed. Read targeted decoder, exception-handler, and caller context through repo_read.py. No build or tests were run by me; the Windows results in the PR description are author-reported.

Results

Check Result Note
Diff and targeted source review passed One verified blocking defect
Build and tests not run PR reports Windows checks

Findings

Blocking

  • On an access violation during the replayed memory instruction, the pending-replay branch restores the scratch register and adds 128 to Rsp, then redirects Rip to the original guest instruction. It returns false unless the exception is the terminal UD2 (core/libs/prx/libc/src/specifics/windows/GuestGs.cpp:107-113). The caller therefore continues searching for a handler, while the exception context has already been modified. If another handler repairs the memory fault and resumes execution, it resumes at the original GS-prefixed instruction rather than the replay instruction, causing the access to fault again or run with a corrupted stack. Recover nonterminal replay faults without discarding replay state or changing the context; restore the original context only when propagating the fault.

Non-blocking

None.

Not verified

I did not run the claimed Windows build or tests, hosted checks, PS5/title execution, or physical-console behavior. I read every changed file marked included in the manifest; no changed files were excluded there. files.json was not available through the reader.

To get this to a good state

Fix replay fault handling so a recoverable memory fault can retry the replay instruction with the pending state intact, and so propagated faults do not leave a modified stack or instruction pointer. Then rerun the focused Windows replay and fault-retry tests on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5902523206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5902523206). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T07:09:43Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: make replay fault recovery distinguish a memory fault from a completed replay before redirecting the instruction pointer. ## What I ran Reviewed head `f013da972573fa4dfca95607f2462501d6ad2234`. Read the prepared description, commit list, manifest, diff, and all changed files listed as reviewed. Read targeted decoder, exception-handler, and caller context through `repo_read.py`. No build or tests were run by me; the Windows results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | One verified blocking defect | | Build and tests | not run | PR reports Windows checks | ## Findings ### Blocking - On an access violation during the replayed memory instruction, the pending-replay branch restores the scratch register and adds 128 to `Rsp`, then redirects `Rip` to the original guest instruction. It returns `false` unless the exception is the terminal UD2 (`core/libs/prx/libc/src/specifics/windows/GuestGs.cpp:107-113`). The caller therefore continues searching for a handler, while the exception context has already been modified. If another handler repairs the memory fault and resumes execution, it resumes at the original GS-prefixed instruction rather than the replay instruction, causing the access to fault again or run with a corrupted stack. Recover nonterminal replay faults without discarding replay state or changing the context; restore the original context only when propagating the fault. ### Non-blocking None. ## Not verified I did not run the claimed Windows build or tests, hosted checks, PS5/title execution, or physical-console behavior. I read every changed file marked included in the manifest; no changed files were excluded there. `files.json` was not available through the reader. ## To get this to a good state Fix replay fault handling so a recoverable memory fault can retry the replay instruction with the pending state intact, and so propagated faults do not leave a modified stack or instruction pointer. Then rerun the focused Windows replay and fault-retry tests on the new head.
MarcZX10 commented 2026-11-20 18:40:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T18:40:10Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed head is 5922e359e9a3e74ad8366698f3f15bbd0e7cf4b5; the inspected replay and fault paths support the stated behavior, and no blocking defect was verified.

What I ran

No commands or tests were run. The PR description reports a native build and 52 focused CTests passed; these are author-reported results.

Results

Check Result Note
Source review passed Replay and fault paths inspected
Build and tests not run Author reports 52 focused tests passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The manifest lists 24 changed files, all marked included, but the reader interface did not expose the prepared review/files/ bundle. I therefore reviewed only the prepared diff and targeted repository source ranges, not every changed file's full text. Excluded-file details were not available. Windows runtime behavior, physical-console behavior, and the reported build and tests were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5997674576 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-5997674576). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T18:40:10Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed head is `5922e359e9a3e74ad8366698f3f15bbd0e7cf4b5`; the inspected replay and fault paths support the stated behavior, and no blocking defect was verified. ## What I ran No commands or tests were run. The PR description reports a native build and 52 focused CTests passed; these are author-reported results. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Replay and fault paths inspected | | Build and tests | not run | Author reports 52 focused tests passed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The manifest lists 24 changed files, all marked included, but the reader interface did not expose the prepared `review/files/` bundle. I therefore reviewed only the prepared diff and targeted repository source ranges, not every changed file's full text. Excluded-file details were not available. Windows runtime behavior, physical-console behavior, and the reported build and tests were not independently verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-27 03:53:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T03:53:54Z.

Review: COMMENTED


Reviewed — comments

This review covers the scalar GS replay implementation at head d37ed55b75b2996cd37b778d7606c69863372b82; targeted source inspection found a behavior gap, and the changed lines listed below were not all read.

What I ran

No commands or tests were run. I read the prepared description, commit list, manifest and diff, then inspected selected source and caller ranges through repo_read.py.

Results

Check Result Note
Source review not run Targeted inspection only
Tests not run Author reports prior runs
Build not run Not verified here

Findings

Blocking

None verified.

Non-blocking

  • Address-size-32 moffs replay does not preserve the 32-bit absolute address wrap. TryAppend records the 4-byte immediate in the 64-bit displacement field (WindowsGuestGs.cpp:47-50), while the runtime adds the guest GS base without truncating that address (GuestGs.cpp:148-153). The instruction is rewritten as a normal memory operand (WindowsGuestGs.cpp:51-52), so an addr32 moffs access with a guest GS base can target a different address than the original. The existing moffs32 test uses a zero immediate and therefore does not exercise wraparound. Preserve address-size semantics for this form or leave it on the unsupported-instruction fallback.

Not verified

No tests or builds were run; the historical results in the PR description are author-reported. I did not read every changed line in the manifest. The 27 changed files are all marked included, but this review read only selected ranges in GuestGs.cpp, CrashReport.cpp, WindowsGuestGs.cpp, WindowsTlsBuilder.cpp, WindowsEntryStubBuilder.cpp, WindowsPePatcher.cpp, WindowsLoadImage.cpp, WindowsRelocationBuilder.cpp, WindowsGuestModuleWriter.cpp, ElfReader.cpp, and the related decoder type and macOS GS rewrite. Other changed-file ranges remain unverified.

To get this to a good state

Nothing is required. Optional: add a nonzero addr32 moffs case whose effective address wraps at 32 bits with a nonzero GS base, and ensure replay matches native guest semantics.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6083256462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-6083256462). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T03:53:54Z. **Review:** COMMENTED --- # Reviewed — comments This review covers the scalar GS replay implementation at head `d37ed55b75b2996cd37b778d7606c69863372b82`; targeted source inspection found a behavior gap, and the changed lines listed below were not all read. ## What I ran No commands or tests were run. I read the prepared description, commit list, manifest and diff, then inspected selected source and caller ranges through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Source review | not run | Targeted inspection only | | Tests | not run | Author reports prior runs | | Build | not run | Not verified here | ## Findings ### Blocking None verified. ### Non-blocking - Address-size-32 `moffs` replay does not preserve the 32-bit absolute address wrap. `TryAppend` records the 4-byte immediate in the 64-bit displacement field (`WindowsGuestGs.cpp:47-50`), while the runtime adds the guest GS base without truncating that address (`GuestGs.cpp:148-153`). The instruction is rewritten as a normal memory operand (`WindowsGuestGs.cpp:51-52`), so an `addr32` moffs access with a guest GS base can target a different address than the original. The existing `moffs32` test uses a zero immediate and therefore does not exercise wraparound. Preserve address-size semantics for this form or leave it on the unsupported-instruction fallback. ## Not verified No tests or builds were run; the historical results in the PR description are author-reported. I did not read every changed line in the manifest. The 27 changed files are all marked included, but this review read only selected ranges in `GuestGs.cpp`, `CrashReport.cpp`, `WindowsGuestGs.cpp`, `WindowsTlsBuilder.cpp`, `WindowsEntryStubBuilder.cpp`, `WindowsPePatcher.cpp`, `WindowsLoadImage.cpp`, `WindowsRelocationBuilder.cpp`, `WindowsGuestModuleWriter.cpp`, `ElfReader.cpp`, and the related decoder type and macOS GS rewrite. Other changed-file ranges remain unverified. ## To get this to a good state Nothing is required. Optional: add a nonzero `addr32` moffs case whose effective address wraps at 32 bits with a nonzero GS base, and ensure replay matches native guest semantics.
MarcZX10 commented 2026-12-01 16:15:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T16:15:50Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected Windows guest GS replay and fault handling changes show no verified blocking defect, but the full changed-file set was not reviewed, so a formal decision is not justified.

What I ran

Inspected the prepared diff and selected changed-file text at head 1ae3585bef67d7561f12cecc4d763715903a97a6. No tests or builds were run.

Results

Check Result Note
Prepared diff inspection passed Reviewed selected hunks
Tests and builds not run No execution performed
Full changed-file review not run Review remains incomplete

Findings

Blocking

None verified in the inspected changes.

Non-blocking

None.

Not verified

Read selected content from GuestGs.hpp, CrashReport.cpp, GuestGs.cpp, Exception.cpp, WindowsGuestGs.cpp, WindowsTlsBuilder.cpp, WindowsEntryStubBuilder.cpp, WindowsLoadImage.cpp, WindowsPePatcher.cpp, WindowsGuestModuleWriter.cpp, WindowsRelocationBuilder.cpp, ElfReader.cpp, ElfReaderBoundsTests.cpp, GuestGsRunner.cpp, test_windows_guest_gs.py, test_windows_guest_gs_integration.py, and windows_runtime/CMakeLists.txt. Other changed files and the remaining portions of those files were not fully reviewed. files.json lists no files excluded by its rules. The author-described integration status for #10518 and #10861 was not independently checked. No runtime, platform, or test behavior was confirmed.

To get this to a good state

Nothing is required for this comment. Optional: complete review of the remaining changed lines after the integration dependencies are resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6135243361 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11628#pullrequestreview-6135243361). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-01T16:15:50Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected Windows guest GS replay and fault handling changes show no verified blocking defect, but the full changed-file set was not reviewed, so a formal decision is not justified. ## What I ran Inspected the prepared diff and selected changed-file text at head `1ae3585bef67d7561f12cecc4d763715903a97a6`. No tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Prepared diff inspection | passed | Reviewed selected hunks | | Tests and builds | not run | No execution performed | | Full changed-file review | not run | Review remains incomplete | ## Findings ### Blocking None verified in the inspected changes. ### Non-blocking None. ## Not verified Read selected content from `GuestGs.hpp`, `CrashReport.cpp`, `GuestGs.cpp`, `Exception.cpp`, `WindowsGuestGs.cpp`, `WindowsTlsBuilder.cpp`, `WindowsEntryStubBuilder.cpp`, `WindowsLoadImage.cpp`, `WindowsPePatcher.cpp`, `WindowsGuestModuleWriter.cpp`, `WindowsRelocationBuilder.cpp`, `ElfReader.cpp`, `ElfReaderBoundsTests.cpp`, `GuestGsRunner.cpp`, `test_windows_guest_gs.py`, `test_windows_guest_gs_integration.py`, and `windows_runtime/CMakeLists.txt`. Other changed files and the remaining portions of those files were not fully reviewed. `files.json` lists no files excluded by its rules. The author-described integration status for #10518 and #10861 was not independently checked. No runtime, platform, or test behavior was confirmed. ## To get this to a good state Nothing is required for this comment. Optional: complete review of the remaining changed lines after the integration dependencies are resolved.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/11628:upstream-pr/11628'
git switch 'upstream-pr/11628'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/11628'
git switch 'upstream-pr/11628'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/11628'
git switch 'upstream-pr/11628'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/11628'
git switch 'main'
git merge --squash 'upstream-pr/11628'
git switch 'main'
git merge --ff-only 'upstream-pr/11628'
git switch 'main'
git merge 'upstream-pr/11628'
git push origin 'main'
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!11628
No description provided.