fix(libSceFiber): end the frame chain of a fiber with a null frame #4770

Merged
ee6aba54 merged 1 commit from upstream-pr/4770 into main 2026-10-14 17:32:08 +00:00
ee6aba54 commented 2026-10-12 21:25:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-12T21:25:35Z.


What

Aps5FiberMain calls the fiber's entry function with the entry address left in rbp, because the library is built without frame pointers and the compiler keeps the call target there. The guest entry saves rbp as its caller's frame, so a guest that walks frame pointers from inside a fiber reads the entry function's machine code as a frame record and faults.

libSceFiber is now built with -fno-omit-frame-pointer. Aps5FiberMain then sets up a frame of its own whose saved rbp is the zero of the initial fiber frame, and a walk from a fiber ends there with a null frame.

Tested

  • Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, rebased onto 18c438b10 (fibers run on host stacks since 794714983; the fix applies there unchanged).
  • fiber gains a fiber whose entry walks the frame chain: every frame has to lie within 1 MiB above the first one and above the previous frame, and the chain has to end with a null frame. Without the change it fails with frame chain climbs the stack (the entry address is taken as a frame); with it the test passes. ctest on the previous base 8cf6a0bc3 plus this change: 1072 tests pass.
  • PPSA15304 (engine: Unreal Engine 5): its game thread runs on a fiber. When the title raises a fatal error there, it collects the call stack by walking frame pointers until a null frame, a null return address or 100 frames. That walk faulted at mov 0x8(%rax),%rcx with rax holding instruction bytes (55 48 89 e5 41 57 41 56, a function prologue), so the process died with SIGSEGV and no message; the core dump shows the chain passing Aps5FiberMain with the entry address as the next frame. With the change the walk ends at the fiber's first frame and the title prints its error (LowLevelFatalError [File:.\Runtime/RenderCore/Private/RenderingThread.cpp] [Line: 1272] GameThread timed out waiting for RenderThread after 120.00 secs) with the collected addresses before it aborts.
  • Windows not built or tested.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4835169809 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4770). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-12T21:25:35Z. --- ### What `Aps5FiberMain` calls the fiber's entry function with the entry address left in `rbp`, because the library is built without frame pointers and the compiler keeps the call target there. The guest entry saves `rbp` as its caller's frame, so a guest that walks frame pointers from inside a fiber reads the entry function's machine code as a frame record and faults. `libSceFiber` is now built with `-fno-omit-frame-pointer`. `Aps5FiberMain` then sets up a frame of its own whose saved `rbp` is the zero of the initial fiber frame, and a walk from a fiber ends there with a null frame. ### Tested - Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, rebased onto `18c438b10` (fibers run on host stacks since `794714983`; the fix applies there unchanged). - `fiber` gains a fiber whose entry walks the frame chain: every frame has to lie within 1 MiB above the first one and above the previous frame, and the chain has to end with a null frame. Without the change it fails with `frame chain climbs the stack` (the entry address is taken as a frame); with it the test passes. `ctest` on the previous base `8cf6a0bc3` plus this change: 1072 tests pass. - PPSA15304 (engine: Unreal Engine 5): its game thread runs on a fiber. When the title raises a fatal error there, it collects the call stack by walking frame pointers until a null frame, a null return address or 100 frames. That walk faulted at `mov 0x8(%rax),%rcx` with `rax` holding instruction bytes (`55 48 89 e5 41 57 41 56`, a function prologue), so the process died with `SIGSEGV` and no message; the core dump shows the chain passing `Aps5FiberMain` with the entry address as the next frame. With the change the walk ends at the fiber's first frame and the title prints its error (`LowLevelFatalError [File:.\Runtime/RenderCore/Private/RenderingThread.cpp] [Line: 1272] GameThread timed out waiting for RenderThread after 120.00 secs`) with the collected addresses before it aborts. - Windows not built or tested. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-13 03:55:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T03:55:14Z.


Windows test: head e51aacc90 merged onto current main 495bf91a0 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter fiber: fiber passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137874115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4770#issuecomment-6137874115). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T03:55:14Z. --- Windows test: head `e51aacc90` merged onto current `main` `495bf91a0` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest with the filter `fiber`: fiber passed (1 test(s), 0 failed); `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
ee6aba54 commented 2026-10-13 19:12:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-13T19:12:11Z.


Rebased onto 18c438b10: 27b75311f. Fibers run on host stacks since 794714983, so the test no longer requires the frames to lie inside the guest context; it bounds the chain by its first frame and requires each frame to lie above the previous one. The fix itself is unchanged and still needed: without it the test fails with frame chain climbs the stack.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153175133 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4770#issuecomment-6153175133). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-13T19:12:11Z. --- Rebased onto `18c438b10`: `27b75311f`. Fibers run on host stacks since `794714983`, so the test no longer requires the frames to lie inside the guest context; it bounds the chain by its first frame and requires each frame to lie above the previous one. The fix itself is unchanged and still needed: without it the test fails with `frame chain climbs the stack`.
blawesom commented 2026-10-14 05:54:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-14T05:54:28Z.


Independent verification of your rebase — the current head builds and passes the full local suite on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): 1099/1100 — the only failure is the known main regression (agc_driver_tessellation segfault, #4727), not this PR. Conventions green. From my side this is merge-ready.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161914730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4770#issuecomment-6161914730). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-14T05:54:28Z. --- **Independent verification of your rebase** — the current head builds and passes the full local suite on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): **1099/1100** — the only failure is the known `main` regression (`agc_driver_tessellation` segfault, #4727), not this PR. Conventions green. From my side this is merge-ready.
adriadam10 commented 2026-10-14 17:06:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:06:18Z.


Checked on the head merged onto current main: build and the fiber test pass; with the -fno-omit-frame-pointer line removed the test aborts with frame chain climbs the stack, so it covers the fix. The Windows run by @xXPBSXx and the full Linux suite by @blawesom agree. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6173872639 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4770#issuecomment-6173872639). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T17:06:18Z. --- Checked on the head merged onto current `main`: build and the `fiber` test pass; with the `-fno-omit-frame-pointer` line removed the test aborts with `frame chain climbs the stack`, so it covers the fix. The Windows run by @xXPBSXx and the full Linux suite by @blawesom agree. Merging.
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!4770
No description provided.