feat(relinker): relocate red-zone leaves the in-place framing refuses whole into framed stubs #16371
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16371"
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 Nesyth on 2026-11-06T12:55:17Z.
What
With
--frame-red-zone, the relinker frames System V leaf functions that keep values below RSP, so that an exception Windows dispatches on a guest thread does not overwrite them (#361). The in-place framer refuses leaves whose shape it cannot widen or stub: in PPSA04264, 178 of the 617 red-zone leaves. WithAPS5_RELINK_RELOCATE_RED_ZONE=1this PR copies such a leaf whole into a framed stub instead, and jumps to the copy from the leaf's entry. The switch is off by default.How
pushq 0(%rsp)/popq shift(%rsp)pair that touches no register or flag, so explicit RSP and RBP operands read what the push wrote, while pops read the copy's slot. RBP frames keep their addresses (mov %rsp,%rbpbecomeslea shift(%rsp),%rbp,leavebecomeslea -shift(%rbp),%rsp; pop %rbp).int $0x41(the SDK assert trap, which the crash report reads from the bytes at RIP) is copied as it is, and a leaf may end inud2.APS5_RELINK_REDZONE_SKIPSlists every refused leaf with its reason;APS5_RELINK_RELOCATE_RANGE=low:highrelocates only the candidates with those ordinals, for bisecting;APS5_RELINK_RELOCATE_TRACE=<address>prints what each instruction of one leaf becomes;APS5_RELINK_STUB_MAPprints the stub of each site.Tested
red_zone_framer_tests: new static cases for the deeper shift (a frame leaf touching[rbp-0x80]relocates with a 0x90 shift), a saved RBP read through[rbp](refused), the assert trap, an indirect jump through RDI with nothing pushed (RSP raised before the jump), with RBX pushed (RBX stored at its original slot after the push, RSP raised right before the jump), a pushed RBX read through[rsp]and freed withadd(the same store after the push) and after a push and asub(refused), andmovzbl %ah/movb %ahread as AH rather than RSP (with a REX prefix the same encoding is SPL and still refused).red_zone_framer_execution_tests(Windows, single-stepped, so every step's exception frame clobbers below RSP): seven relocated leaves, among them one that pushes after its first instruction and spills to-0x80, one that allocates a local withpush %raxand frees it withadd, one that reads a pushed register atrspand frees it withaddinstead of a pop, and a frame-pointer leaf that reads a register pushed after its frame through[rbp-8]and frees it withleave. Each unframed leaf returns a wrong value under the clobber, and each relocated one returns the right value. With the shift fixed at 0x80 the push-after-entry leaf returns 0x5555 instead of 0x4444, and without the store after each push the leaf that frees its pushed register withaddreturns 0x199f849bea1 instead of 0x3333.relinker_conversion,relinker_game_patch,red_zone_framer,red_zone_framer_executionandcli_args: 5 of 5 pass on this branch rebased onmain65ad958fb9(Windows 11, WinLibs GCC 15.2).117016c665): one boot of 271 s in game with 128 leaves relocated and fault-based write tracking on, 0 crashes, 0 device losses.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.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T14:20:31Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
117016c6654a045c7de23a55c2b69a85345fecb6using the prepared diff and pinned repository reader. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The PR description reports five passing test suites and Windows 11 runtime testing, but I did not run those checks. The prepared bundle listed all six changed files as included; I inspected the relocation implementation, its tests, and relevant integration changes. I did not read the full text of all six changed files or audit every changed line, so this review does not establish that the entire change is ready to approve.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:04:16Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: refuse relocating leaves that pop into RSP, because the relocation’s stack-depth model treats that instruction as an ordinary pop.
What I ran
Reviewed head
558c1155c046bfd6f719904ea4208bba019a7832. Read the prepared description, commits, manifest, diff, and changed source and test ranges throughrepo_read.py; no build or tests were run.Results
Findings
Blocking
core/relinker/codegen/src/x86/RedZoneFramer.cpp:259-268treats every opcode from0x58through0x5fas a pop and updates the modeled depth by eight. That includespop %rsp, which instead loads a value into RSP and can redirect the stack to an unrelated address. If the in-place framer refuses such a red-zone leaf, relocation can accept it under this model and emit a copy whose stack behavior differs from the original. Explicitly refuse pops whose destination is RSP before applying the ordinary depth update.Non-blocking
None.
Not verified
No build, test suite, or runtime checks were performed. All changed files listed in the manifest were included; the relevant framer implementation and execution/static test ranges were read. Other portions of the changed tests and documentation were not read.
To get this to a good state
Refuse relocating
pop %rspleaves, then rerun the relevant static and execution tests on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T13:31:50Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing in the inspected code establishes a defect that blocks merging; the review is incomplete because several changed files’ full texts were not read.
What I ran
72e79623b155ee8f5efcd1b42bbe1036502d4707using the prepared diff andrepo_read.pyreader.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
The full head texts for
RedZoneFramer.hpp,RedZoneFramer.cpp,RedZoneFramerExecutionTests.cpp,RedZoneFramerTests.cpp,WindowsTrampolineBuilder.cpp,Conversion.cpp, andENVIRONMENT.mdwere included in the prepared review folder, but were not read in full. The implementation’s encoding coverage and uninspected integration details therefore remain unverified. No tests or build were run; reported test and game results are author-supplied.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T09:47:23Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete because the reader returned only the first 200 lines of the diff and source despite range requests.
What I ran
Read the prepared description, commits, manifest, and the first 200 lines of
diff.patch; attempted targeted reads of later ranges throughrepo_read.py.Results
Findings
Blocking
None established from the available source.
Non-blocking
The review cannot assess correctness or completeness of the relocation implementation without access to the remaining diff and changed files.
Not verified
The review bundle lists seven changed files:
RedZoneFramer.hpp,RedZoneFramer.cpp,RedZoneFramerExecutionTests.cpp,RedZoneFramerTests.cpp,WindowsTrampolineBuilder.cpp,Conversion.cpp, andENVIRONMENT.md. Only the first 200 lines ofdiff.patchwere returned, and requests for further ranges repeated those lines. The full text of these changed files, tests, integration points, and remaining diff were not verified. No commands or tests were run.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T09:52:31Z.
Review: COMMENTED
Actionable comments posted: 9
Architecture findings (2)
Advisory architecture findings (2)
047df806-4bd7-42dd-bab1-7c95c0138a91Reviewing files that changed from the base of the PR and between
b3c7769bc5and2149366882.core/relinker/codegen/include/codegen/x86/RedZoneFramer.hppcore/relinker/codegen/src/x86/RedZoneFramer.cppcore/relinker/codegen/tests/RedZoneFramerExecutionTests.cppcore/relinker/codegen/tests/RedZoneFramerTests.cppcore/relinker/elfpatcher/src/windows/WindowsTrampolineBuilder.cppcore/relinker/relinker/src/pipeline/Conversion.cppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:58:10Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONand ranred_zone_framerandred_zone_framer_executionon Linux. Both passed, covering the generated stub and its native execution.AI-assisted: yes.
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.