feat(relinker): frame red-zone leaves whose prologue or exit is shorter than a jump #10871
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10871"
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 Chronyyx on 2026-10-25T06:59:21Z.
What
In short: on Windows, a fault AnyPS5 resumes on a guest thread can overwrite values a function keeps just below RSP (#361).
--frame-red-zoneprotects such leaf functions by moving their stack, but it skipped every leaf whose start or end is shorter than the 5-byte jump it patches in, and every leaf without pushes. This PR frames those too. In ASTRO BOT (PPSA21564) that is 362 of 463 red-zone leaves, up from 146 onmain. Agreed with @EagleBearerYS on #9514 before starting.How:
pop rbx; ret, 2 bytes) borrows the instructions just before it into its stub, the way #5640's operand stubs already do. The stub runs them with RSP still lowered, then raises RSP, pops and returns.push rbx, 1 byte) borrows the instructions just after it: the stub pushes, lowers RSP, then runs them.ret.When it still refuses, each with its own reason in the relinker output:
ret, RIP-relative instruction, push, pop or another site comes before there are 5 bytes;branch into the instructions before a short exit,… after a short prologue);branch to the start of a widened prologue);push or pop in a leaf without pushes). This also refuses shrink-wrapped leaves that push later, which must be refused: once RSP is lowered on entry, their pushes land on their own spills (ASTRO BOT's0x10cffa0, below). Apush rbp; mov rbp, rspprologue is not affected (second commit).[rsp]operands after the body push are shifted past the pushed slot. That is onmainalready, and this PR reaches more such leaves: on its head apush rbxleaf whose prologue it widens, with apush rsi … pop rsiin its body, returns 0x44b4 instead of 0x6666 even without the clobber. #11061 refuses those leaves.The relinker now prints how many prologues and exits it widened.
docs/dev/debt/relinker.mdand--frame-red-zoneinUSAGE.mddescribe what is framed now.ASTRO BOT framing report,
mainand this PRmainmainreports under "other use of rsp" are reported under the earlier push/pop check here.subis 4 bytes whileadd …; retis 5, two whose three pushes are 4 bytes while their pops andretare 5), and two leaves with 2 and 4 widened exits: 216 − 5 + 1 + 3 = 215.Tested
In short: unit tests for each new case and refusal, the Linux execution test running the new stubs under a clobber below RSP, the full relinker suite on Windows and Linux, and ASTRO BOT to its title screen in 10 runs, with frame rates against
main's framing.red_zone_framer: new cases for a 1-bytepush rbxwith a 2-byte exit, apush rbp; mov rbp, rspleaf with a 2-byte exit, a leaf without pushes, a loop back to a widened prologue's first instruction, a branch into the instructions borrowed before a short exit, and a fragment that pops without pushing. The existing short-prologue case now puts a RIP-relative load after the pushes, so it still covers a prologue that cannot be widened.red_zone_framer_execution(Linux, WSL Ubuntu 26.04, GCC 15.2.0): three new leaves, one without pushes, one pushing onlyrbxand one with onlypush rbp; mov rbp, rsp, each keeping values below RSP or RBP across a loop. Under the single-step clobber the unframed leaves return0xfffffffffffffff5,0x2d2d2d2d2d2e605aand0xfffffffffffffff5; framed, they return the expected0x1aaa9,0x1bbbaand0x1aaa9. The existing leaves still pass. The frame-pointer leaf found that the first commit's push/pop check refused it; the second commit fixes that.597f1392a8, by @EagleBearerYS, on review): a branch into the instructions borrowed after a short prologue, a widened prologue that allocates, a leaf without pushes with tworetexits, a VEX RSP operand in a widened exit, and a frame-pointer leaf with a balanced push and pop in its body, each as a unit case and, apart from the refusal, an execution leaf.red_zone_framerpasses on Windows 11 and Linux;red_zone_framer_executionpasses on Linux, where each new leaf returns the wrong value unframed under the clobber and the expected one framed.ctestat this PR's head: Windows 11 (WinLibs GCC 15.2.0 r7) 260 of 260 onmainaf49a0788; Linux 264 of 264 onmaine7e3e9c19(no relinker file changed between the two bases).check_test_registration.pypasses.vkWaitForFences recorder: Vulkan result -4(device lost) in a compute dispatch; the same device loss happened once in a run of the title relinked without--frame-red-zone, out of 74 runs in all.main's framing (146 leaves) 102.6, 108.0, 114.1 and 103.3 (mean 107.0); this PR (362 leaves) 111.8, 105.9 and 111.6 (mean 109.8), the fourth run being the device loss above. The difference is within the run-to-run spread; the title screen is GPU-bound, so a small CPU cost would not show.0x10cffa0, and one of its 6 runs stopped without a crash report after 31 s. That leaf is shrink-wrapped: no pushes on entry, six pushes and pops on its slow path, spills down torsp-0x58after the pushes. That build lowered RSP by 0x60 on entry, so the six pushes land atrsp-0x68torsp-0x90of the entry RSP, while the spills keep their addresses atrsp-0x58torsp-0x88: the spills overwrite saved registers whenever the slow path runs. That is a likely cause of the stop, not a measured one; the same build ran 4 more times without stopping. This PR refuses the leaf.python3 tools/check_conventions.py --base origin/mainpasses.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)🤖 Generated with Claude Code