feat(libkernel): implement module segment info export #4193

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/4193 into main
MarcZX10 commented 2026-10-12 01:01:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T01:01:29Z.


What

Carries screamm’s ready sceKernelInternalMemoryGetModuleSegmentInfo implementation as a focused PR, preserving the original commit author. It defines the 16-byte { address, size } result and returns the first segment reported by sceKernelGetModuleInfo for the main program.

The result shape and first-segment behavior are based on fpPS4. The console may instead report libkernel’s text or the caller’s module; no call has been observed, so that choice remains explicitly documented as unverified in TechnicalDebt. Null output and missing-main-program cases throw because their console behavior is also unknown. The export is imported by 44 catalog titles that bundle their own libc.prx.

Tested

  • Linux Release configure with GCC, BUILD_TESTING=ON, and ANYPS5_ENABLE_SPIRV_TOOLS=ON completed.
  • Built guest_module_info_tests with Ninja (127/127 steps).
  • ctest --test-dir /tmp/AnyPS5-4173-build -R '^guest_module_info$' --output-on-failure --timeout 60 passed (1/1); the test checks that the returned segment matches the first segment from sceKernelGetModuleInfo(self).
  • python3 tools/check_conventions.py --base upstream/main --head HEAD passed.
  • git diff --check passed.

Checklist

  • Based on current main; no other open PR implements the same function
  • 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (original commit co-authored by Claude; carried and validated with Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823701979 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4193). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T01:01:29Z. --- ### What Carries screamm’s ready `sceKernelInternalMemoryGetModuleSegmentInfo` implementation as a focused PR, preserving the original commit author. It defines the 16-byte `{ address, size }` result and returns the first segment reported by `sceKernelGetModuleInfo` for the main program. The result shape and first-segment behavior are based on fpPS4. The console may instead report libkernel’s text or the caller’s module; no call has been observed, so that choice remains explicitly documented as unverified in TechnicalDebt. Null output and missing-main-program cases throw because their console behavior is also unknown. The export is imported by 44 catalog titles that bundle their own `libc.prx`. ### Tested - Linux Release configure with GCC, `BUILD_TESTING=ON`, and `ANYPS5_ENABLE_SPIRV_TOOLS=ON` completed. - Built `guest_module_info_tests` with Ninja (127/127 steps). - `ctest --test-dir /tmp/AnyPS5-4173-build -R '^guest_module_info$' --output-on-failure --timeout 60` passed (1/1); the test checks that the returned segment matches the first segment from `sceKernelGetModuleInfo(self)`. - `python3 tools/check_conventions.py --base upstream/main --head HEAD` passed. - `git diff --check` passed. ### Checklist - [x] Based on current `main`; no other open PR implements the same function - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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 (original commit co-authored by Claude; carried and validated with Codex)
github-actions[bot] commented 2026-10-12 01:01:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T01:01:51Z.


Progress report (1acfa7f → 2664fb0)

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

✅ 1 implemented
Library Name
libkernel sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115901064 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4193#issuecomment-6115901064). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T01:01:51Z. --- <!-- progress-report --> ### Progress report (1acfa7f → 2664fb0) 📈 **System libraries**: 86.39% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix` | </details>
github-actions[bot] commented 2026-10-12 14:41:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T14:41:18Z.


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
#4524 sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126515199 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4193#issuecomment-6126515199). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T14:41:18Z. --- <!-- 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 | |---|---|---|---| | #4524 | | `sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix` | |
Dextroid17 commented 2026-10-12 21:14:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T21:14:18Z.

Review: COMMENTED


Linux build, an A/B control, a duplicate carry, and the rebase onto current main

I built this head on Linux and measured it. Nothing below is a request for a change I have not measured, and I have no PR against this path. Your Tested section is what made it cheap to check: it names the target, the test and the command.

Head 2664fb07e (parent 1acfa7f78). It no longer merges with main. #4567 (sceKernelGetLibkernelTextLocation) merged at 20:57Z and inserts at the same spot, so git merge-tree --write-tree pr-4193 upstream/main exits 1 (checked at 6d2f27986 and again at 7940cacd8) with content conflicts in core/libs/prx/libkernel/Module/src/ModuleInfo.cpp and core/libs/tests/GuestModuleInfo.cpp. Section 1 has a resolution that builds.

1. Rebase: keep both functions

Both sides are additions, so the resolution keeps main's whole sceKernelGetLibkernelTextLocation_nid_postfix and this PR's whole export (the two conflict hunks in ModuleInfo.cpp interleave inside the function bodies, so taking both sides of each hunk blindly would give one mangled function), and in the test keeps both blocks. I resolved it that way on top of main 5efd09afc, initialised the new submodules (3rdparty/libusb-cmake, 3rdparty/tracy), and rebuilt (binary newer than the source; nothing else in the 200-odd files from main needed touching):

nm -D --defined-only build/core/libs/libs/unpatched/libkernel.prx | grep -E 'InternalMemoryGetModuleSegmentInfo|GetLibkernelTextLocation'
00000000000ad520 T sceKernelGetLibkernelTextLocation_nid_postfix
00000000000ad620 T sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix
ctest --test-dir build -R '^guest_module_info$'      # Passed 1/1; 10 direct runs, exit 0 each

One thing the rebase makes visible: the two bodies run the same lookup (GuestImages, the same Fill/dl_iterate_phdr search, segments[0], return 0) and differ only in the signature, the null-argument check, the message text, and how the result is stored (two out-parameters with a cast, against one {address, size} struct). fpPS4 defines this export as a call to sceKernelGetLibkernelTextLocation (ps4_libkernel.pas:349-355), so having it call the one already on main is an option, if you want a single body.

2. On the pre-rebase head: it builds, its test passes, and the test needs the change

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \
  -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build --target guest_module_info_tests --parallel 16   # 132 steps
ctest --test-dir build -R '^guest_module_info$' --timeout 60         # Passed 1/1, 0.00 s

(-DFFMPEG_PREBUILT_DIR points at a sibling clone's already-unpacked ffmpeg-9ac4cfd195f1.) Ten consecutive direct runs, invoked the way ctest invokes it (argument libguest_module_fixture.so, working directory build/core/libs/prx/libkernel), exit 0 each.

Control: implementation reverted to the parent (the // unknown signature stub back at core/libs/prx/libkernel/Module/src/Module.cpp:244-249, the definition gone from core/libs/prx/libkernel/Module/src/ModuleInfo.cpp), test kept. The test aborts, exit 134, and ctest reports 0% tests passed, 1 tests failed out of 1: the stub's NotImplemented_nid_no_patch throws out of main.

Two mutations of my own: info.segments[1] in place of segments[0] at :445 aborts 134, and std::runtime_error in place of std::invalid_argument at :432 aborts 134. A marker on the :105 assertion confirmed it is the one that fires for the first. That assertion compares the export with sceKernelGetModuleInfo for the same main program, and the pre-existing Require(handles.front() == self.id) at core/libs/tests/GuestModuleInfo.cpp:72 is what pins that the first guest image is the main program.

3. #4524 is the same patch, and merging both breaks the build

Compared blob for blob against bacf50be4:

ModuleInfo.cpp       7b6f9a5aa016    identical
Module.cpp           d196d8613163    identical
GuestModuleInfo.cpp  4eaf583a606e    identical
debt/libkernel.md    81d33f58ac87    identical
SceTypes.hpp         793fc2d76d2c vs 92f8cdb584e1   <- the only difference

The only difference in SceTypes.hpp is where the six-line InternalSegmentInfo sits. git merge-tree --write-tree pr-4193 pr-4524 exits 0 with no conflict, and the merged tree declares the struct twice, at core/libs/SceTypes.hpp:233 and :289:

$ git merge --no-commit --no-ff pr-4524      # "Automatic merge went well"
core/libs/SceTypes.hpp:289:8: error: redefinition of 'struct InternalSegmentInfo'

The overlap bot already lists #4524 for the shared export; what it cannot show is that the merged tree fails to compile. #4524 conflicts with main in the same two files. For context rather than as a recommendation: this PR is the earlier one (01:01:29Z against 14:21:49Z) and keeps screamm's authorship (2664fb07e), while bacf50be4 is authored by jagrat Singh. Which one closes is for the two of you.

4. What segments[0] is, and a dependency worth knowing

Fill (core/libs/prx/libkernel/Module/src/ModuleInfo.cpp:125-132) records the first PT_LOAD in program-header order. fpPS4's body (pinned 04cefd43e6, ps4_libkernel.pas:338-339) returns the eboot's first segment, which on the four eboots in rea-work/unwrapped (PPSA03671, PPSA26344, PPSA28997, PPSA35169) is the text: p_offset 0x4000, vaddr 0, flags E. #4567 was merged as matching that behaviour (the merger: "first segment of the main program, 0 on success … same behaviour"), with the console's own value left recorded as unverified in its debt entry.

For current relinker output the first PT_LOAD is that text: core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp:196-206 pushes the kept title loads first and the offset-0 header block last among the PT_LOADs. Program headers from readelf -lW on relinked executables here: run-trails/app.elf (PPSA35169), run-gow/app.elf (PPSA28997) and run-wolv/app.elf (PPSA03671), all relinked 2026-10-12, start with off 0x4000 vaddr 0x0 (the title text) and have the 0x350-byte block at off 0x0 as the seventh PT_LOAD. The exception is an older relink: run/app.elf (PPSA26344, 2026-10-09) leads with a 0x318-byte R block at p_offset 0. I read program headers only; I did not call the export against these executables.

So the answer depends on the relinker keeping that block out of first place. The tree already has a rule for skipping it, p_offset == 0 (ModuleInfo.cpp:197, in AddGuestSegmentBytes), if you ever want it not to. This applies equally to the sibling already on main.

5. Null output pointer: a convention question

Three older exports in this file return the library's own error for a null output pointer:

ModuleInfo.cpp:360   if (!info) return SCE_KERNEL_ERROR_EFAULT;                 # sceKernelGetModuleInfo
ModuleInfo.cpp:381   if (!handles || !actual) return SCE_KERNEL_ERROR_EFAULT;   # sceKernelGetModuleList
ModuleInfo.cpp:395   if (!info) return SCE_KERNEL_ERROR_EFAULT;                 # sceKernelGetModuleInfoFromAddr

This export throws std::invalid_argument at :432, and :106 pins the throw. So does the sibling #4567 just put on main (sceKernelGetLibkernelTextLocation: null argument). Both conventions are now in the file, and the debt entry notes that a null result throws, in an entry that lists the console's behaviour as unknown, so this is a question and not a finding.

6. The title bar

Your body is straight about this: no call observed, the console's value unverified, the import list as the only evidence. I can corroborate the kind: tools/nid_names.py maps the name to -YTW+qXc3CQ, and that literal occurs exactly once in the sce_module/libc.prx of each of the five title trees on this box (PPSA02929, PPSA26344, PPSA03671, PPSA28997, PPSA35169), counted with grep -a -o. That is an import, not a call. The audit's figure of 44 I cannot check from here.

What I could not check: the Windows arm (Fill(address) at :437), the console's own value, and any title reaching the call.

AI-assisted review; every number above comes from a command run here.

Hermes Agent 🤖 at your service

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5496002497 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4193#pullrequestreview-5496002497). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T21:14:18Z. **Review:** COMMENTED --- **Linux build, an A/B control, a duplicate carry, and the rebase onto current `main`** I built this head on Linux and measured it. Nothing below is a request for a change I have not measured, and I have no PR against this path. Your *Tested* section is what made it cheap to check: it names the target, the test and the command. Head `2664fb07e` (parent `1acfa7f78`). **It no longer merges with `main`.** #4567 (`sceKernelGetLibkernelTextLocation`) merged at 20:57Z and inserts at the same spot, so `git merge-tree --write-tree pr-4193 upstream/main` exits 1 (checked at `6d2f27986` and again at `7940cacd8`) with content conflicts in `core/libs/prx/libkernel/Module/src/ModuleInfo.cpp` and `core/libs/tests/GuestModuleInfo.cpp`. Section 1 has a resolution that builds. **1. Rebase: keep both functions** Both sides are additions, so the resolution keeps main's whole `sceKernelGetLibkernelTextLocation_nid_postfix` and this PR's whole export (the two conflict hunks in `ModuleInfo.cpp` interleave inside the function bodies, so taking both sides of each hunk blindly would give one mangled function), and in the test keeps both blocks. I resolved it that way on top of `main` `5efd09afc`, initialised the new submodules (`3rdparty/libusb-cmake`, `3rdparty/tracy`), and rebuilt (binary newer than the source; nothing else in the 200-odd files from `main` needed touching): ``` nm -D --defined-only build/core/libs/libs/unpatched/libkernel.prx | grep -E 'InternalMemoryGetModuleSegmentInfo|GetLibkernelTextLocation' 00000000000ad520 T sceKernelGetLibkernelTextLocation_nid_postfix 00000000000ad620 T sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix ctest --test-dir build -R '^guest_module_info$' # Passed 1/1; 10 direct runs, exit 0 each ``` One thing the rebase makes visible: the two bodies run the same lookup (`GuestImages`, the same `Fill`/`dl_iterate_phdr` search, `segments[0]`, return 0) and differ only in the signature, the null-argument check, the message text, and how the result is stored (two out-parameters with a cast, against one `{address, size}` struct). fpPS4 defines this export as a call to `sceKernelGetLibkernelTextLocation` (`ps4_libkernel.pas:349-355`), so having it call the one already on `main` is an option, if you want a single body. **2. On the pre-rebase head: it builds, its test passes, and the test needs the change** ``` cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \ -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DANYPS5_ENABLE_SPIRV_TOOLS=ON cmake --build build --target guest_module_info_tests --parallel 16 # 132 steps ctest --test-dir build -R '^guest_module_info$' --timeout 60 # Passed 1/1, 0.00 s ``` (`-DFFMPEG_PREBUILT_DIR` points at a sibling clone's already-unpacked `ffmpeg-9ac4cfd195f1`.) Ten consecutive direct runs, invoked the way `ctest` invokes it (argument `libguest_module_fixture.so`, working directory `build/core/libs/prx/libkernel`), exit 0 each. **Control**: implementation reverted to the parent (the `// unknown signature` stub back at `core/libs/prx/libkernel/Module/src/Module.cpp:244-249`, the definition gone from `core/libs/prx/libkernel/Module/src/ModuleInfo.cpp`), test kept. The test **aborts**, exit 134, and `ctest` reports `0% tests passed, 1 tests failed out of 1`: the stub's `NotImplemented_nid_no_patch` throws out of `main`. **Two mutations of my own**: `info.segments[1]` in place of `segments[0]` at `:445` aborts 134, and `std::runtime_error` in place of `std::invalid_argument` at `:432` aborts 134. A marker on the `:105` assertion confirmed it is the one that fires for the first. That assertion compares the export with `sceKernelGetModuleInfo` for the same main program, and the pre-existing `Require(handles.front() == self.id)` at `core/libs/tests/GuestModuleInfo.cpp:72` is what pins that the first guest image is the main program. **3. #4524 is the same patch, and merging both breaks the build** Compared blob for blob against `bacf50be4`: ``` ModuleInfo.cpp 7b6f9a5aa016 identical Module.cpp d196d8613163 identical GuestModuleInfo.cpp 4eaf583a606e identical debt/libkernel.md 81d33f58ac87 identical SceTypes.hpp 793fc2d76d2c vs 92f8cdb584e1 <- the only difference ``` The only difference in `SceTypes.hpp` is where the six-line `InternalSegmentInfo` sits. `git merge-tree --write-tree pr-4193 pr-4524` exits **0** with no conflict, and the merged tree declares the struct twice, at `core/libs/SceTypes.hpp:233` and `:289`: ``` $ git merge --no-commit --no-ff pr-4524 # "Automatic merge went well" core/libs/SceTypes.hpp:289:8: error: redefinition of 'struct InternalSegmentInfo' ``` The overlap bot already lists #4524 for the shared export; what it cannot show is that the merged tree fails to compile. #4524 conflicts with `main` in the same two files. For context rather than as a recommendation: this PR is the earlier one (01:01:29Z against 14:21:49Z) and keeps screamm's authorship (`2664fb07e`), while `bacf50be4` is authored by jagrat Singh. Which one closes is for the two of you. **4. What `segments[0]` is, and a dependency worth knowing** `Fill` (`core/libs/prx/libkernel/Module/src/ModuleInfo.cpp:125-132`) records the **first `PT_LOAD` in program-header order**. fpPS4's body (pinned `04cefd43e6`, `ps4_libkernel.pas:338-339`) returns the eboot's first segment, which on the four eboots in `rea-work/unwrapped` (PPSA03671, PPSA26344, PPSA28997, PPSA35169) is the text: `p_offset 0x4000, vaddr 0, flags E`. #4567 was merged as matching that behaviour (the merger: "first segment of the main program, 0 on success … same behaviour"), with the console's own value left recorded as unverified in its debt entry. For current relinker output the first `PT_LOAD` is that text: `core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp:196-206` pushes the kept title loads first and the offset-0 header block last among the `PT_LOAD`s. Program headers from `readelf -lW` on relinked executables here: `run-trails/app.elf` (PPSA35169), `run-gow/app.elf` (PPSA28997) and `run-wolv/app.elf` (PPSA03671), all relinked 2026-10-12, start with `off 0x4000 vaddr 0x0` (the title text) and have the `0x350`-byte block at `off 0x0` as the seventh `PT_LOAD`. The exception is an older relink: `run/app.elf` (PPSA26344, 2026-10-09) leads with a `0x318`-byte `R` block at `p_offset 0`. I read program headers only; I did not call the export against these executables. So the answer depends on the relinker keeping that block out of first place. The tree already has a rule for skipping it, `p_offset == 0` (`ModuleInfo.cpp:197`, in `AddGuestSegmentBytes`), if you ever want it not to. This applies equally to the sibling already on `main`. **5. Null output pointer: a convention question** Three older exports in this file return the library's own error for a null output pointer: ``` ModuleInfo.cpp:360 if (!info) return SCE_KERNEL_ERROR_EFAULT; # sceKernelGetModuleInfo ModuleInfo.cpp:381 if (!handles || !actual) return SCE_KERNEL_ERROR_EFAULT; # sceKernelGetModuleList ModuleInfo.cpp:395 if (!info) return SCE_KERNEL_ERROR_EFAULT; # sceKernelGetModuleInfoFromAddr ``` This export throws `std::invalid_argument` at `:432`, and `:106` pins the throw. So does the sibling #4567 just put on `main` (`sceKernelGetLibkernelTextLocation: null argument`). Both conventions are now in the file, and the debt entry notes that a null result throws, in an entry that lists the console's behaviour as unknown, so this is a question and not a finding. **6. The title bar** Your body is straight about this: no call observed, the console's value unverified, the import list as the only evidence. I can corroborate the kind: `tools/nid_names.py` maps the name to `-YTW+qXc3CQ`, and that literal occurs exactly once in the `sce_module/libc.prx` of each of the five title trees on this box (PPSA02929, PPSA26344, PPSA03671, PPSA28997, PPSA35169), counted with `grep -a -o`. That is an import, not a call. The audit's figure of 44 I cannot check from here. **What I could not check**: the Windows arm (`Fill(address)` at `:437`), the console's own value, and any title reaching the call. AI-assisted review; every number above comes from a command run here. Hermes Agent 🤖 at your service
oneandonlydean commented 2026-10-13 00:36:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:36:01Z.


Closing: #4524 implements the same export on top of sceKernelGetLibkernelTextLocation (#4567) and merges cleanly, while this one conflicts with main in ModuleInfo.cpp and GuestModuleInfo.cpp.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135368133 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4193#issuecomment-6135368133). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:36:01Z. --- Closing: #4524 implements the same export on top of `sceKernelGetLibkernelTextLocation` (#4567) and merges cleanly, while this one conflicts with main in `ModuleInfo.cpp` and `GuestModuleInfo.cpp`.

Pull request closed

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!4193
No description provided.