perf(libkernel): look up unwind mappings with PROCMAP_QUERY #3227

Merged
GustavoGamarra95 merged 3 commits from upstream-pr/3227 into main 2026-10-11 07:18:50 +00:00
GustavoGamarra95 commented 2026-10-11 02:08:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-11T02:08:25Z.


What

On Linux, sceKernelGetModuleInfoForUnwind (libkernel) and sceSysmoduleGetModuleInfoForUnwind (libSceSysmodule) opened /proc/self/maps and scanned it line by line with sscanf on every call. Unity IL2CPP titles call them on each stack walk. God of War Sons of Sparta (PPSA28997) has about 900 mappings, and 16 of 19 eu-stack samples of its main thread were in that scan.

  • New header prx/libc/include/specifics/linux/HostMapping.hpp asks the kernel for the mapping that covers an address with the PROCMAP_QUERY ioctl (Linux 6.11), on one /proc/self/maps descriptor opened once. It uses the same probe and the same APS5_NO_PROCMAP_QUERY switch as GuestMemory.cpp. Older kernels, and the switch, keep the line scan.
  • Both functions use it, and the copy of the scan in libSceSysmodule goes away. They return the same start, end and path as before, except that a path containing a space is no longer cut at the first space.
  • sceSysmoduleGetModuleInfoForUnwind had no test. GuestSysmodule.cpp now compares it with an independent read of /proc/self/maps for code, the stack and an anonymous page, and checks that an unmapped address throws. On Linux the test runs a second time with APS5_NO_PROCMAP_QUERY (guest_sysmodule_maps_scan), so the line scan stays covered.

Tested

  • Arch Linux, kernel 7.2.9 (CachyOS), Ryzen 5 7535HS, RTX 3050 Laptop (NVIDIA 615.78.08), GCC 16.2.1, Release, on main d31b57a4: ctest 752/753 passed. The failure is agc_driver_dcc_keys_first_write, which fails on main on this GPU too. The unwind tests pass with and without APS5_NO_PROCMAP_QUERY.
  • God of War Sons of Sparta (PPSA28997), 80 s of intro and title screens with MangoHud, FPS counted from the frame timestamps: 10.8 before, 59.5 after (the display rate). Running the title on Linux also needs #1482 and #1431, which this change does not depend on. During gameplay the title is still well below 60 FPS for another reason, which this PR does not address.

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:4815942559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3227). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-11T02:08:25Z. --- ### What On Linux, `sceKernelGetModuleInfoForUnwind` (libkernel) and `sceSysmoduleGetModuleInfoForUnwind` (libSceSysmodule) opened `/proc/self/maps` and scanned it line by line with `sscanf` on every call. Unity IL2CPP titles call them on each stack walk. God of War Sons of Sparta (PPSA28997) has about 900 mappings, and 16 of 19 `eu-stack` samples of its main thread were in that scan. - New header `prx/libc/include/specifics/linux/HostMapping.hpp` asks the kernel for the mapping that covers an address with the `PROCMAP_QUERY` ioctl (Linux 6.11), on one `/proc/self/maps` descriptor opened once. It uses the same probe and the same `APS5_NO_PROCMAP_QUERY` switch as `GuestMemory.cpp`. Older kernels, and the switch, keep the line scan. - Both functions use it, and the copy of the scan in libSceSysmodule goes away. They return the same start, end and path as before, except that a path containing a space is no longer cut at the first space. - `sceSysmoduleGetModuleInfoForUnwind` had no test. `GuestSysmodule.cpp` now compares it with an independent read of `/proc/self/maps` for code, the stack and an anonymous page, and checks that an unmapped address throws. On Linux the test runs a second time with `APS5_NO_PROCMAP_QUERY` (`guest_sysmodule_maps_scan`), so the line scan stays covered. ### Tested - Arch Linux, kernel 7.2.9 (CachyOS), Ryzen 5 7535HS, RTX 3050 Laptop (NVIDIA 615.78.08), GCC 16.2.1, Release, on `main` d31b57a4: `ctest` 752/753 passed. The failure is `agc_driver_dcc_keys_first_write`, which fails on `main` on this GPU too. The unwind tests pass with and without `APS5_NO_PROCMAP_QUERY`. - God of War Sons of Sparta (PPSA28997), 80 s of intro and title screens with MangoHud, FPS counted from the frame timestamps: 10.8 before, 59.5 after (the display rate). Running the title on Linux also needs #1482 and #1431, which this change does not depend on. During gameplay the title is still well below 60 FPS for another reason, which this PR does not address. ### Checklist - [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)
github-actions[bot] commented 2026-10-11 02:08:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T02:08:34Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104481092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3227#issuecomment-6104481092). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T02:08:34Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
github-actions[bot] commented 2026-10-11 05:30:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T05:30:21Z.


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
#2541 core/libs/tests/GuestSysmodule.cpp L19-20, L39
#3041 core/libs/prx/libSceSysmodule/CMakeLists.txt L8-9
core/libs/tests/GuestSysmodule.cpp L3, L10, L39
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105847361 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3227#issuecomment-6105847361). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T05:30:21Z. --- <!-- 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 | |---|---|---|---| | #2541 | `core/libs/tests/GuestSysmodule.cpp` [L19-20](https://github.com/boykopovar/AnyPS5/blob/d508b44a20563a795a8c8ccdf6c4726d23e12c57/core/libs/tests/GuestSysmodule.cpp#L19-L20), [L39](https://github.com/boykopovar/AnyPS5/blob/d508b44a20563a795a8c8ccdf6c4726d23e12c57/core/libs/tests/GuestSysmodule.cpp#L39) | | | | #3041 | `core/libs/prx/libSceSysmodule/CMakeLists.txt` [L8-9](https://github.com/boykopovar/AnyPS5/blob/d508b44a20563a795a8c8ccdf6c4726d23e12c57/core/libs/prx/libSceSysmodule/CMakeLists.txt#L8-L9)<br>`core/libs/tests/GuestSysmodule.cpp` [L3](https://github.com/boykopovar/AnyPS5/blob/d508b44a20563a795a8c8ccdf6c4726d23e12c57/core/libs/tests/GuestSysmodule.cpp#L3), [L10](https://github.com/boykopovar/AnyPS5/blob/d508b44a20563a795a8c8ccdf6c4726d23e12c57/core/libs/tests/GuestSysmodule.cpp#L10), [L39](https://github.com/boykopovar/AnyPS5/blob/d508b44a20563a795a8c8ccdf6c4726d23e12c57/core/libs/tests/GuestSysmodule.cpp#L39) | | |
adriadam10 commented 2026-10-11 07:18:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:18:47Z.


Checked the diff, guest_sysmodule and guest_sysmodule_maps_scan (both pass; the new test pins equivalence with /proc/self/maps for code, stack, anonymous and unmapped addresses, with and without APS5_NO_PROCMAP_QUERY). Returned start/end/path match the old scan. Merging once CI is green.

Non-blocking: the procmap_query struct and the probe duplicate GuestMemory.cpp; worth sharing in a follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106606546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3227#issuecomment-6106606546). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:18:47Z. --- Checked the diff, `guest_sysmodule` and `guest_sysmodule_maps_scan` (both pass; the new test pins equivalence with `/proc/self/maps` for code, stack, anonymous and unmapped addresses, with and without `APS5_NO_PROCMAP_QUERY`). Returned start/end/path match the old scan. Merging once CI is green. Non-blocking: the `procmap_query` struct and the probe duplicate `GuestMemory.cpp`; worth sharing in a follow-up.
GustavoGamarra95 commented 2026-10-12 00:18:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T00:18:43Z.


@adriadam10 Thanks for the review. The follow-up is done: #3454 moves the procmap_query struct and the probe into a shared header, and GuestMemory.cpp uses it now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115518248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3227#issuecomment-6115518248). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-12T00:18:43Z. --- @adriadam10 Thanks for the review. The follow-up is done: #3454 moves the procmap_query struct and the probe into a shared header, and GuestMemory.cpp uses it now.
GustavoGamarra95 commented 2026-10-12 12:43:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T12:43:33Z.


Thanks for the review. The follow-up is done: #3454 moves the procmap_query struct and the probe into a shared header, and GuestMemory.cpp uses it now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124496861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3227#issuecomment-6124496861). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-12T12:43:33Z. --- Thanks for the review. The follow-up is done: #3454 moves the `procmap_query` struct and the probe into a shared header, and GuestMemory.cpp uses it now.
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!3227
No description provided.