feat(relinker): execute supported scalar guest GS accesses on Windows #11628
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11628"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from 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
5922e359e9failed because the branch’s olderlibkernel.mdmasked 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 runDraft 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
mainat4a7fd1c405a7ff410d4f2fc1de9cbbdd19ed7d90. The Windows exception handler runs #27532’s CLZERO emulation after SSE4a and before GS fault projection. It preserves early GS trap handling andmain’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
f013da9725replay 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.870917228acloses 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-25677a4ce74546511713ba3344e3db417b6bc36f1af4ec419db61ffe8ab34ac4cca. Conventions and whitespace checks passed againstorigin/main27d83474a0. 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 at5922e359e9.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 productionlibc.prxCLZERO handler clears exactly the addressed cache line and resumes. The Windows run oftest_frame_capture_minimize_replay.pypassed all 22 cases. Conventions, whitespace and debt folding passed against the integratedmain. 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 CIHistorical 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T00:06:05Z.
Review: CHANGES_REQUESTED
Reviewed the feature commit
1bb3d0cfcb8a7cfe102b9384b8e723bca8925d32separately from the explicitly listed prerequisite stack.[P1] Decode address-size-32
mod=00, r/m=101as absolute disp32, not RIP-relative. InWindowsGuestGs::Append, themod == 0 && rm == 5case always setsbase = 0xfe(RIP-relative). But when address-size override0x67is 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 00reads fromGS.base + (resume & 0xffffffff)instead ofGS.base + 0. That can read or write the wrong guest location. The currentaddress32-wrapfixture uses a SIB form and does not cover this special non-SIB form.Please set the no-base sentinel for this encoding when
AddressSize32is true, preserve the 32-bit displacement as an unsigned effective offset, and add a67+mod=00/rm=101execution fixture (zero displacement is enough with the existing runner's nonzero GS base). The relinker-only build is in progress locally; conventions andgit diff --checkpass, and the hosted Linux/Windows relinker checks currently pass. No local Windows runtime test is claimed.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 inWindowsGuestGs::Append: formod=00, r/m=101the code always writes base sentinel0xfe, which makes the runtime add the instruction resume address. With a0x67address-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, so65 67 48 8b 05 00 00 00 00reads fromGS.base + (resume & 0xffffffff)rather thanGS.base + 0. Theaddress32-wrapfixture uses a SIB form and does not cover this special non-SIB encoding.Please select the no-base sentinel when
AddressSize32is true, preserve the unsigned 32-bit displacement, and add an execution fixture for67+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/11628passes. 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.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=101remains RIP-relative with0x67in 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.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 --checkand 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.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
mainnow changes the shared Windows entry-stub builder and adds a bounds test that the reported runtime runs predate.What I ran
cedb9ac8cddc5083dff0b477dd406313ec8a6bcc; PR base:1189ec3003672bb364dd9f3119ead7b3976e3c83.main5ecef095b61e7a406b279c97896f3a8a6fbd6353; merge preview was clean, tree729dc713fab2e47fca5e6ae1b26762866013cccf.Results
729dc713fab2e47fca5e6ae1b26762866013cccfgit diff --check0x67/mod=00,r/m=101execution cases were added, on an earlier integration. They were not run on the current-main merge.Unedited local command output
git diff --checkexited 0 with no output.Findings
Blocking
None found in the corrected
0x67address calculation or the unsupported-instruction fallback.Non-blocking
The merge preview includes current
main's additional capacity/RVA checks inWindowsEntryStubBuilder::Buildand itswindows_entry_stub_boundstest. 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.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.
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 throughrepo_read.py. No build or tests were run by me; the Windows results in the PR description are author-reported.Results
Findings
Blocking
Rsp, then redirectsRipto the original guest instruction. It returnsfalseunless 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.jsonwas 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.
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
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.
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
Findings
Blocking
None verified.
Non-blocking
moffsreplay does not preserve the 32-bit absolute address wrap.TryAppendrecords 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 anaddr32moffs access with a guest GS base can target a different address than the original. The existingmoffs32test 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
addr32moffs case whose effective address wraps at 32 bits with a nonzero GS base, and ensure replay matches native guest semantics.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
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, andwindows_runtime/CMakeLists.txt. Other changed files and the remaining portions of those files were not fully reviewed.files.jsonlists 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.