feat(libkernel): implement sceKernelGetModuleInfoFromAddr on Windows #1188

Merged
MathiasDevelopes merged 2 commits from upstream-pr/1188 into main 2026-10-09 21:22:47 +00:00
MathiasDevelopes commented 2026-10-07 16:48:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-07T16:48:07Z.


What

sceKernelGetModuleInfoFromAddr was not implemented on Windows: it called NotImplemented_nid_no_patch, so any title whose libc.prx asks which module an address belongs to aborted at startup.

On Windows the module is now the PE image that holds the address (VirtualQuery, MEM_IMAGE):

  • name: the image file name without .guest.prx, as on Linux
  • id: the sceKernelLoadStartModule handle from the dynamic loader, otherwise a stable id from the same range (ModuleIdForImage_nid_no_patch, as on Linux)
  • segments: for an image the relinker produced, its .elfN sections (the ELF load pages); for any other image, its first 4 sections with memory access. Protection comes from the section characteristics
  • eh_frame: for a relinked image, the eh_frame_hdr whose RVA the relinker records in .ehmeta, with its size computed from the header encodings and table; for a host image, the .ehfram section that configure_windows_unwind produces, without an eh_frame_hdr
  • TLS fields, init_proc_addr and fini_proc_addr stay 0; ref_count is 1. Addresses outside any image return SCE_KERNEL_ERROR_ESRCH

The eh_frame_hdr/eh_frame decoding (pointer encodings, record walk) is shared between the Linux and Windows paths instead of being duplicated. The Linux path behaves the same, and its eh_frame_ptr decoding now accepts every standard encoding instead of only 0x1b, 0x03 and 0x00.

guest_module_info now runs on Windows too. The fixture and test binary go through configure_windows_unwind, and only the eh_frame_hdr check stays Linux-only. The TechnicalDebt entry describes the Windows behaviour instead of saying "Not implemented on Windows".

Tested

  • Windows 11, MinGW-w64 GCC (winlibs), Release: guest_module_info and guest_dynamic_loader pass
  • tools/check_conventions.py --base main passes
  • PPSA14632 (relinked, Windows): previously aborted at startup on this call; with this change it boots to the loading screen
  • Linux: not built locally. The Linux path was only refactored to use the shared helpers, so CI should confirm it

Checklist

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4775718718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-07T16:48:07Z. --- ### What `sceKernelGetModuleInfoFromAddr` was not implemented on Windows: it called `NotImplemented_nid_no_patch`, so any title whose `libc.prx` asks which module an address belongs to aborted at startup. On Windows the module is now the PE image that holds the address (`VirtualQuery`, `MEM_IMAGE`): - **name**: the image file name without `.guest.prx`, as on Linux - **id**: the `sceKernelLoadStartModule` handle from the dynamic loader, otherwise a stable id from the same range (`ModuleIdForImage_nid_no_patch`, as on Linux) - **segments**: for an image the relinker produced, its `.elfN` sections (the ELF load pages); for any other image, its first 4 sections with memory access. Protection comes from the section characteristics - **eh_frame**: for a relinked image, the eh_frame_hdr whose RVA the relinker records in `.ehmeta`, with its size computed from the header encodings and table; for a host image, the `.ehfram` section that `configure_windows_unwind` produces, without an eh_frame_hdr - TLS fields, `init_proc_addr` and `fini_proc_addr` stay 0; `ref_count` is 1. Addresses outside any image return `SCE_KERNEL_ERROR_ESRCH` The eh_frame_hdr/eh_frame decoding (pointer encodings, record walk) is shared between the Linux and Windows paths instead of being duplicated. The Linux path behaves the same, and its eh_frame_ptr decoding now accepts every standard encoding instead of only `0x1b`, `0x03` and `0x00`. `guest_module_info` now runs on Windows too. The fixture and test binary go through `configure_windows_unwind`, and only the eh_frame_hdr check stays Linux-only. The TechnicalDebt entry describes the Windows behaviour instead of saying "Not implemented on Windows". ### Tested - Windows 11, MinGW-w64 GCC (winlibs), Release: `guest_module_info` and `guest_dynamic_loader` pass - `tools/check_conventions.py --base main` passes - PPSA14632 (relinked, Windows): previously aborted at startup on this call; with this change it boots to the loading screen - Linux: not built locally. The Linux path was only refactored to use the shared helpers, so CI should confirm it ### 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)](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)](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
copilot-pull-request-reviewer[bot] commented 2026-10-07 16:48:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-07T16:48:13Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5445514465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188#pullrequestreview-5445514465). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-07T16:48:13Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
github-actions[bot] commented 2026-10-07 17:15:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T17:15:13Z.


Progress report (bc1fbe8 → 9abc931)

📈 System libraries: 85.25% (+0.03%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelGetModuleInfoFromAddr
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6042971463 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188#issuecomment-6042971463). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T17:15:13Z. --- <!-- progress-report --> ### Progress report (bc1fbe8 → 9abc931) 📈 **System libraries**: 85.25% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelGetModuleInfoFromAddr` | </details>
MathiasDevelopes commented 2026-10-08 05:51:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-08T05:51:37Z.


Rebased onto main. Since #1188 was opened, sceKernelGetModuleInfoForUnwind in Module.cpp got its own Windows .ehmeta / eh_frame_hdr parsing, so this PR now does the same work separately in ModuleInfo.cpp. The two also handle bad tables a little differently (NotImplemented there, throw or full support here).

Should this be a follow up PR or should i do the work here? @adriadam10 @oneandonlydean

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6053321188 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188#issuecomment-6053321188). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-08T05:51:37Z. --- Rebased onto main. Since #1188 was opened, `sceKernelGetModuleInfoForUnwind` in `Module.cpp` got its own Windows `.ehmeta` / eh_frame_hdr parsing, so this PR now does the same work separately in `ModuleInfo.cpp`. The two also handle bad tables a little differently (NotImplemented there, throw or full support here). Should this be a follow up PR or should i do the work here? @adriadam10 @oneandonlydean
oneandonlydean commented 2026-10-08 06:37:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T06:37:15Z.


Here, please. Move the .ehmeta / eh_frame_hdr parsing into one helper that both sceKernelGetModuleInfoForUnwind and sceKernelGetModuleInfoFromAddr call, so bad tables are handled one way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054010277 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188#issuecomment-6054010277). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T06:37:15Z. --- Here, please. Move the `.ehmeta` / eh_frame_hdr parsing into one helper that both `sceKernelGetModuleInfoForUnwind` and `sceKernelGetModuleInfoFromAddr` call, so bad tables are handled one way.
MathiasDevelopes commented 2026-10-08 07:01:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-08T07:01:20Z.


@oneandonlydean Done in 9abc931a. Both sceKernelGetModuleInfoForUnwind and sceKernelGetModuleInfoFromAddr now parse .ehmeta, the eh_frame_hdr and eh_frame through one shared header, Module/EhFrame.hpp.

Both calls now throw on the same bad tables: a version other than 1, an indirect or non-absptr/pcrel encoding, a 64-bit record length, or anything outside the image.

What changes per call:

  • FromAddr: now throws on 64-bit record lengths and indirect encodings, which it accepted before.
  • ForUnwind: now also accepts udata2/sdata2 and checks that the FDE table is inside the image.
  • Reported sizes are the same as before. ForUnwind still leaves out the terminator, and FromAddr still counts it.

Tested: guest_module_info passes on Linux, the Windows path compiles with MinGW, and the GuestUnwindModuleInfo cases pass against the shared parser. The full Windows tests haven't been run locally, so Windows CI will be the check for those.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054414942 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188#issuecomment-6054414942). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-08T07:01:20Z. --- @oneandonlydean Done in 9abc931a. Both `sceKernelGetModuleInfoForUnwind` and `sceKernelGetModuleInfoFromAddr` now parse `.ehmeta`, the eh_frame_hdr and eh_frame through one shared header, `Module/EhFrame.hpp`. Both calls now throw on the same bad tables: a version other than 1, an indirect or non-absptr/pcrel encoding, a 64-bit record length, or anything outside the image. What changes per call: - FromAddr: now throws on 64-bit record lengths and indirect encodings, which it accepted before. - ForUnwind: now also accepts udata2/sdata2 and checks that the FDE table is inside the image. - Reported sizes are the same as before. ForUnwind still leaves out the terminator, and FromAddr still counts it. Tested: `guest_module_info` passes on Linux, the Windows path compiles with MinGW, and the `GuestUnwindModuleInfo` cases pass against the shared parser. The full Windows tests haven't been run locally, so Windows CI will be the check for those.
github-actions[bot] commented 2026-10-08 10:04:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T10:04:26Z.


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
#1498 core/libs/prx/libkernel/Module/src/ModuleInfo.cpp L11, L167-169
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6057473812 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188#issuecomment-6057473812). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T10:04:26Z. --- <!-- 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 | |---|---|---|---| | #1498 | `core/libs/prx/libkernel/Module/src/ModuleInfo.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/33a9199af185fe2942b37df16e27a53c4bf268fd/core/libs/prx/libkernel/Module/src/ModuleInfo.cpp#L11), [L167-169](https://github.com/boykopovar/AnyPS5/blob/33a9199af185fe2942b37df16e27a53c4bf268fd/core/libs/prx/libkernel/Module/src/ModuleInfo.cpp#L167-L169) | | |
adriadam10 commented 2026-10-09 21:22:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:22:43Z.


Checked on Linux (merged onto current main): build and full ctest green (522/522, guest_module_info and guest_dynamic_loader included). Windows CI on this head runs guest_module_info green. The shared EhFrame.hpp addresses Dean's request, TechnicalDebt matches the new behaviour, no conflicts. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089482045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1188#issuecomment-6089482045). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:22:43Z. --- Checked on Linux (merged onto current main): build and full ctest green (522/522, `guest_module_info` and `guest_dynamic_loader` included). Windows CI on this head runs `guest_module_info` green. The shared `EhFrame.hpp` addresses Dean's request, TechnicalDebt matches the new behaviour, no conflicts. 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!1188
No description provided.