feat(libc): implement sceLibcBacktraceSelf and GetBufferSize on Linux #7060

Merged
Aryansh1520 merged 4 commits from upstream-pr/7060 into main 2026-10-17 15:49:45 +00:00
Aryansh1520 commented 2026-10-17 09:32:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-17T09:32:22Z.


What

Implements sceLibcBacktraceSelf and sceLibcBacktraceGetBufferSize on Linux. The frame record layout is inferred from a title and is recorded in the libc technical debt. Adds GuestBacktrace test covering the record layout and the buffer-size query.

Tested

Linux (x86-64, gcc, Release): ctest -R guest_backtrace passes. Hardware: AMD Ryzen 7 260 host, NVIDIA GeForce RTX 5060 Laptop GPU (Wayland). Game check: God of War Sons of Sparta (PPSA28997) on Linux, Il2Cpp imports these at startup and no longer stops on them.

Overlaps open PRs #6447 (@mashingaan) and #7084 on the same two functions. Coordinating which goes first before merge.

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 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: none
  • Fixes: none
  • Unblocks: PPSA28997 (God of War Sons of Sparta); Game bring-up discussion not linked yet
  • GPUs tested: n/a (no AGC, shader recompiler or VideoOut change); game run on NVIDIA GeForce RTX 5060 Laptop GPU, driver 615.78.08, Linux (Wayland)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4898973875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7060). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-17T09:32:22Z. --- ### What Implements `sceLibcBacktraceSelf` and `sceLibcBacktraceGetBufferSize` on Linux. The frame record layout is inferred from a title and is recorded in the libc technical debt. Adds `GuestBacktrace` test covering the record layout and the buffer-size query. ### Tested Linux (x86-64, gcc, Release): `ctest -R guest_backtrace` passes. Hardware: AMD Ryzen 7 260 host, NVIDIA GeForce RTX 5060 Laptop GPU (Wayland). Game check: God of War Sons of Sparta (PPSA28997) on Linux, Il2Cpp imports these at startup and no longer stops on them. Overlaps open PRs #6447 (@mashingaan) and #7084 on the same two functions. Coordinating which goes first before merge. <!-- 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 --> - [ ] 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 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: none - [x] Fixes: none - [x] Unblocks: PPSA28997 (God of War Sons of Sparta); Game bring-up discussion not linked yet - [x] GPUs tested: n/a (no AGC, shader recompiler or VideoOut change); game run on NVIDIA GeForce RTX 5060 Laptop GPU, driver 615.78.08, Linux (Wayland) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-17 09:33:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T09:33:05Z.


Progress report (6d6e33d → 2e0d310)

📈 System libraries: 89.5% (+0.06%, +2 implemented functions)

✅ 2 implemented
Library Name
libc sceLibcBacktraceGetBufferSize_nid_postfix
libc sceLibcBacktraceSelf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232333913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7060#issuecomment-6232333913). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T09:33:05Z. --- <!-- progress-report --> ### Progress report (6d6e33d → 2e0d310) 📈 **System libraries**: 89.5% (+0.06%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `sceLibcBacktraceGetBufferSize_nid_postfix` | | libc | `sceLibcBacktraceSelf_nid_postfix` | </details>
github-actions[bot] commented 2026-10-17 09:46:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T09:46:16Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6334 core/libs/prx/libc/CMakeLists.txt L33
PR 6447 sceLibcBacktraceGetBufferSize_nid_postfix
sceLibcBacktraceSelf_nid_postfix
PR 6610 docs/dev/debt/libc.md L4
PR 7084 core/libs/prx/libc/src/Backtrace.cpp L1-4, L6-7, L11-12
core/libs/tests/GuestBacktrace.cpp
sceLibcBacktraceGetBufferSize_nid_postfix
sceLibcBacktraceSelf_nid_postfix
core/libs/tests/GuestBacktrace.cpp

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 5668 core/libs/prx/libc/CMakeLists.txt
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 6061 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6222 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6447 core/libs/prx/libc/src/Backtrace.cpp
PR 6565 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232446671 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7060#issuecomment-6232446671). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T09:46:16Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6334](https://www.github.com/boykopovar/AnyPS5/pull/6334) | `core/libs/prx/libc/CMakeLists.txt` [L33](https://github.com/boykopovar/AnyPS5/blob/05b235498adae3f312a9da3dfd48496d28cd66ff/core/libs/prx/libc/CMakeLists.txt#L33) | | | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | | `sceLibcBacktraceGetBufferSize_nid_postfix`<br>`sceLibcBacktraceSelf_nid_postfix` | | | [PR 6610](https://www.github.com/boykopovar/AnyPS5/pull/6610) | `docs/dev/debt/libc.md` [L4](https://github.com/boykopovar/AnyPS5/blob/05b235498adae3f312a9da3dfd48496d28cd66ff/docs/dev/debt/libc.md#L4) | | | | [PR 7084](https://www.github.com/boykopovar/AnyPS5/pull/7084) | `core/libs/prx/libc/src/Backtrace.cpp` [L1-4](https://github.com/boykopovar/AnyPS5/blob/05b235498adae3f312a9da3dfd48496d28cd66ff/core/libs/prx/libc/src/Backtrace.cpp#L1-L4), [L6-7](https://github.com/boykopovar/AnyPS5/blob/05b235498adae3f312a9da3dfd48496d28cd66ff/core/libs/prx/libc/src/Backtrace.cpp#L6-L7), [L11-12](https://github.com/boykopovar/AnyPS5/blob/05b235498adae3f312a9da3dfd48496d28cd66ff/core/libs/prx/libc/src/Backtrace.cpp#L11-L12)<br>`core/libs/tests/GuestBacktrace.cpp` | `sceLibcBacktraceGetBufferSize_nid_postfix`<br>`sceLibcBacktraceSelf_nid_postfix` | `core/libs/tests/GuestBacktrace.cpp` | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 5668](https://www.github.com/boykopovar/AnyPS5/pull/5668) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6061](https://www.github.com/boykopovar/AnyPS5/pull/6061) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libc/src/Backtrace.cpp` | | [PR 6565](https://www.github.com/boykopovar/AnyPS5/pull/6565) | `docs/dev/debt/libc.md` |
simonbbby commented 2026-10-17 12:24:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-17T12:24:03Z.


Independent Linux execution on exact head 2e0d310c91c7b8285b9b8df0b556921dc37fb046 (Ubuntu 24.04 x86-64, GCC 13.3).

The unchanged GuestBacktrace.cpp passes when compiled directly with the complete unchanged production Backtrace.cpp. I also linked a separate harness against that same production source and called it from actual dlopen shared libraries. There are no replacement unwind, dladdr, record-writing or export implementations. Test builds use -O2 -fno-omit-frame-pointer -rdynamic and -ldl.

11,600 additional cases pass: ten module filenames × four frame limits (0, 1, 2, -1) × 290 capacity/boundary cases.

  • Eight caller names of lengths 1–8 followed by .guest.prx exercise every record-padding residue; the reported module is the filename with that suffix removed. name.GUEST.PRX and name.guest.prx.extra remain unchanged.
  • For every capacity from 0 through 256, the harness walks the actual record chain, checks bounds, NUL termination, 8-byte rounding, next pointers, reserved words and the first caller's module offset against dladdr(trace_self).
  • All bytes after the last complete record retain their canary. Another 33 aligned capacities per limit end directly against a PROT_NONE page; none fault.
  • Once the queried size fits, Self's count and used bytes equal GetBufferSize's result.

Two targeted negative controls fail: disabling only .guest.prx stripping fails the caller-name/record-admission checks; admitting a record when capacity is one byte short fails record alignment exceeds capacity. The unmodified implementation passes both corresponding checks.

This covers real Linux host unwinding and serialization into synthetic buffers. It does not validate the inferred console signatures/layout/reserved field, relinked guest unwinding, the title run, other platforms, the full libc build, or the overlap with #6447.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233841133 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7060#issuecomment-6233841133). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-17T12:24:03Z. --- Independent Linux execution on exact head `2e0d310c91c7b8285b9b8df0b556921dc37fb046` (Ubuntu 24.04 x86-64, GCC 13.3). The unchanged `GuestBacktrace.cpp` passes when compiled directly with the complete unchanged production `Backtrace.cpp`. I also linked a separate harness against that same production source and called it from actual `dlopen` shared libraries. There are no replacement unwind, `dladdr`, record-writing or export implementations. Test builds use `-O2 -fno-omit-frame-pointer -rdynamic` and `-ldl`. **11,600 additional cases pass:** ten module filenames × four frame limits (0, 1, 2, -1) × 290 capacity/boundary cases. - Eight caller names of lengths 1–8 followed by `.guest.prx` exercise every record-padding residue; the reported module is the filename with that suffix removed. `name.GUEST.PRX` and `name.guest.prx.extra` remain unchanged. - For every capacity from 0 through 256, the harness walks the actual record chain, checks bounds, NUL termination, 8-byte rounding, next pointers, reserved words and the first caller's module offset against `dladdr(trace_self)`. - All bytes after the last complete record retain their canary. Another 33 aligned capacities per limit end directly against a `PROT_NONE` page; none fault. - Once the queried size fits, `Self`'s count and used bytes equal `GetBufferSize`'s result. Two targeted negative controls fail: disabling only `.guest.prx` stripping fails the caller-name/record-admission checks; admitting a record when capacity is one byte short fails `record alignment exceeds capacity`. The unmodified implementation passes both corresponding checks. This covers real Linux host unwinding and serialization into synthetic buffers. It does not validate the inferred console signatures/layout/reserved field, relinked guest unwinding, the title run, other platforms, the full libc build, or the overlap with #6447.
Aryansh1520 commented 2026-10-17 15:20:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-17T15:20:53Z.


This PR and two others implement the same two exports, sceLibcBacktraceSelf_nid_postfix and sceLibcBacktraceGetBufferSize_nid_postfix: #6447 and #7084. Only one implementation can merge, so the order needs deciding.

#7084 is the only one of the three that is currently mergeable. #6447 has merge conflicts and, per blawesom's comment, does not build yet.

@mashingaan @portalmaster137 which one should go first? Once that is decided I will either rebase this PR onto it and drop the duplicate exports, or close this PR in favour of it, whichever you prefer. This PR keeps the Linux port and the GuestBacktrace test either way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235652356 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7060#issuecomment-6235652356). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-17T15:20:53Z. --- This PR and two others implement the same two exports, `sceLibcBacktraceSelf_nid_postfix` and `sceLibcBacktraceGetBufferSize_nid_postfix`: #6447 and #7084. Only one implementation can merge, so the order needs deciding. #7084 is the only one of the three that is currently mergeable. #6447 has merge conflicts and, per blawesom's comment, does not build yet. @mashingaan @portalmaster137 which one should go first? Once that is decided I will either rebase this PR onto it and drop the duplicate exports, or close this PR in favour of it, whichever you prefer. This PR keeps the Linux port and the `GuestBacktrace` test either way.
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!7060
No description provided.