feat(libkernel): implement sceKernelInternalMemoryGetModuleSegmentInfo #4524

Merged
jagrat04 merged 1 commit from upstream-pr/4524 into main 2026-10-13 00:52:34 +00:00
jagrat04 commented 2026-10-12 14:21:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-12T14:21:49Z.


What

Fixes #4173.

Carries screamm's implementation of sceKernelInternalMemoryGetModuleSegmentInfo rebased onto main.

libkernel exported sceKernelInternalMemoryGetModuleSegmentInfo as a stub (NotImplemented_nid_no_patch), which is imported by 44 audited titles bundling their own libc.prx (including Stremio Plus and PS5MC). Note that getsid from #4173 was previously implemented in #3493.

Implements sceKernelInternalMemoryGetModuleSegmentInfo (NID -YTW+qXc3CQ) in ModuleInfo.cpp. It fills InternalSegmentInfo with the address and size of the first segment of the main program (eboot.bin), returning 0 on success and throwing std::invalid_argument on null pointer, matching fpPS4. Technical debt is documented in TechnicalDebt.md.

Tested

  • python tools/check_conventions.py --base origin/main passed cleanly with 0 errors.
  • Unit tests added in core/libs/tests/GuestModuleInfo.cpp checking valid module segment retrieval against sceKernelGetModuleInfo and verifying nullptr throws std::invalid_argument.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4830755737 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4524). Originally posted by [jagrat04](https://github.com/jagrat04) on 2026-10-12T14:21:49Z. --- ### What Fixes #4173. Carries screamm's implementation of `sceKernelInternalMemoryGetModuleSegmentInfo` rebased onto `main`. `libkernel` exported `sceKernelInternalMemoryGetModuleSegmentInfo` as a stub (`NotImplemented_nid_no_patch`), which is imported by 44 audited titles bundling their own `libc.prx` (including Stremio Plus and PS5MC). Note that `getsid` from #4173 was previously implemented in #3493. Implements `sceKernelInternalMemoryGetModuleSegmentInfo` (NID `-YTW+qXc3CQ`) in `ModuleInfo.cpp`. It fills `InternalSegmentInfo` with the address and size of the first segment of the main program (`eboot.bin`), returning 0 on success and throwing `std::invalid_argument` on null pointer, matching fpPS4. Technical debt is documented in `TechnicalDebt.md`. ### Tested - `python tools/check_conventions.py --base origin/main` passed cleanly with 0 errors. - Unit tests added in `core/libs/tests/GuestModuleInfo.cpp` checking valid module segment retrieval against `sceKernelGetModuleInfo` and verifying `nullptr` throws `std::invalid_argument`. ### 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
github-actions[bot] commented 2026-10-12 14:27:31 +00:00 (Migrated from github.com)

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


Progress report (43e3a70 → ea03a22)

📈 System libraries: 87.89% (+0.02%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126279627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4524#issuecomment-6126279627). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T14:27:31Z. --- <!-- progress-report --> ### Progress report (43e3a70 → ea03a22) 📈 **System libraries**: 87.89% (+0.02%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix` | </details>
github-actions[bot] commented 2026-10-12 14:43:06 +00:00 (Migrated from github.com)

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


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
#4708 docs/dev/debt/libkernel.md L34-35
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126545388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4524#issuecomment-6126545388). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T14:43:06Z. --- <!-- 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 | |---|---|---|---| | #4708 | `docs/dev/debt/libkernel.md` [L34-35](https://github.com/boykopovar/AnyPS5/blob/758aca7373622aadc0926508d38b3d13786be1e4/docs/dev/debt/libkernel.md#L34-L35) | | |
Dextroid17 commented 2026-10-12 15:05:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T15:05:15Z.

Review: COMMENTED


Checked against the source #4173 cites, plus what this NID is doing in the title trees I hold. main still carries the stub and its // unknown signature.

From fpPS4 kernel/ps4_libkernel.pas (abridged — the record is a packed address: Pointer; size: QWORD, and the function is SysV_ABI_CDecl):

349  function ps4_sceKernelInternalMemoryGetModuleSegmentInfo(pOut: PInternalSegmentInfo): Integer;
350  begin
351    //pOut^.address:=nil;  //pOut^.size:=0;  //Result:=0;
354    Result := ps4_sceKernelGetLibkernelTextLocation(@pOut^.address, @pOut^.size)
355  end;
  • The 16-byte {address, size} result, the out-pointer-only signature and the "first segment of the main program" choice all match that. Of the three public sources I checked, fpPS4 is the only one with a plausible signature: shadPS4's table entry has no parameters because it is a generated stub, and the PS5SDK header writes void for every export in that block, including ones with known arguments. Neither argues against a parameter — they are silent.
  • The importer is the guest libc in the five title trees I hold: -YTW+qXc3CQ occurs in sce_module/libc.prx of Ghost of Yōtei (PPSA26344, dumped and decrypted, plus its .guest.prx), Trails in the Sky 2nd Chapter (PPSA35169), Wolverine (PPSA03671), Sons of Sparta (PPSA28997) and PPSA02929, and in no other module file there — not the 21 other .prx, the 18 .sprx, the one .elf, nor any of the five eboot.bin. So there is no title-specific importer in that set. It is still import evidence: I have no run in which this call executes, and no log line naming it.

Two things I would not want read as settled:

  1. Which range the answer describes. fpPS4's helper is named sceKernelGetLibkernelTextLocation, and its body reads Telf_file(ps4_program.ps4_app.prog).ModuleInfo.segmentInfo[0] after a nil guard — segment 0 of the application. So the carried implementation follows the cited code. What keeps the reading open is the helper's name, plus a NID→name entry for sceKernelGetLibkernelTextLocation (AmJ0mn2l4lM, a value that matches fpPS4's constant for that function) with nothing of that name in our libkernel. If the console's answer is libkernel's own text, segment 0 of the eboot is a different address.
  2. The added test cannot separate those readings. Require(segment.address == program.segments[0].address …), compared against sceKernelGetModuleInfo(self.id, …), compares the answer with itself whenever the test binary is the main program, so both readings pass. If a distinguishing case is worth having I am glad to write it as a patch against this PR; otherwise treat that as a limit of the test rather than a request.

One duplicate note, on the API's own data rather than a preference: the overlap bot on this PR already pairs #4193, with the same post-image blobs in ModuleInfo.cpp (90873a76b8..aa47f2cf6e), GuestModuleInfo.cpp (40eacdf818..dd99d92f30) and Module.cpp (f1d39a1ecd..d196d86131). #4193 was opened at 01:01Z against this PR's 14:21Z, so this is the later copy of the same commit — worth settling between their authors before a second review is spent.

Written with AI assistance.

Hermes Agent 🤖 at your service

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5492580652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4524#pullrequestreview-5492580652). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T15:05:15Z. **Review:** COMMENTED --- **Checked against the source #4173 cites, plus what this NID is doing in the title trees I hold.** `main` still carries the stub and its `// unknown signature`. From fpPS4 `kernel/ps4_libkernel.pas` (abridged — the record is a packed `address: Pointer; size: QWORD`, and the function is `SysV_ABI_CDecl`): ``` 349 function ps4_sceKernelInternalMemoryGetModuleSegmentInfo(pOut: PInternalSegmentInfo): Integer; 350 begin 351 //pOut^.address:=nil; //pOut^.size:=0; //Result:=0; 354 Result := ps4_sceKernelGetLibkernelTextLocation(@pOut^.address, @pOut^.size) 355 end; ``` - The 16-byte `{address, size}` result, the out-pointer-only signature and the "first segment of the main program" choice all match that. Of the three public sources I checked, fpPS4 is the only one with a plausible signature: shadPS4's table entry has no parameters because it is a generated stub, and the PS5SDK header writes `void` for every export in that block, including ones with known arguments. Neither argues against a parameter — they are silent. - The importer is the guest libc in the five title trees I hold: `-YTW+qXc3CQ` occurs in `sce_module/libc.prx` of Ghost of Yōtei (PPSA26344, dumped and decrypted, plus its `.guest.prx`), Trails in the Sky 2nd Chapter (PPSA35169), Wolverine (PPSA03671), Sons of Sparta (PPSA28997) and PPSA02929, and in no other module file there — not the 21 other `.prx`, the 18 `.sprx`, the one `.elf`, nor any of the five `eboot.bin`. So there is no title-specific importer in that set. It is still import evidence: I have no run in which this call executes, and no log line naming it. Two things I would not want read as settled: 1. **Which range the answer describes.** fpPS4's helper is named `sceKernelGetLibkernelTextLocation`, and its body reads `Telf_file(ps4_program.ps4_app.prog).ModuleInfo.segmentInfo[0]` after a nil guard — segment 0 of the *application*. So the carried implementation follows the cited code. What keeps the reading open is the helper's name, plus a NID→name entry for `sceKernelGetLibkernelTextLocation` (`AmJ0mn2l4lM`, a value that matches fpPS4's constant for that function) with nothing of that name in our libkernel. If the console's answer is libkernel's own text, segment 0 of the eboot is a different address. 2. **The added test cannot separate those readings.** `Require(segment.address == program.segments[0].address …)`, compared against `sceKernelGetModuleInfo(self.id, …)`, compares the answer with itself whenever the test binary is the main program, so both readings pass. If a distinguishing case is worth having I am glad to write it as a patch against this PR; otherwise treat that as a limit of the test rather than a request. One duplicate note, on the API's own data rather than a preference: the overlap bot on this PR already pairs #4193, with the same post-image blobs in `ModuleInfo.cpp` (`90873a76b8..aa47f2cf6e`), `GuestModuleInfo.cpp` (`40eacdf818..dd99d92f30`) and `Module.cpp` (`f1d39a1ecd..d196d86131`). #4193 was opened at 01:01Z against this PR's 14:21Z, so this is the later copy of the same commit — worth settling between their authors before a second review is spent. Written with AI assistance. Hermes Agent 🤖 at your service
jagrat04 commented 2026-10-12 23:00:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-12T23:00:52Z.


Rebased cleanly onto origin/main resolving merge conflicts:

  • Implemented sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix by calling sceKernelGetLibkernelTextLocation_nid_postfix directly (matching fpPS4's delegation to ps4_sceKernelGetLibkernelTextLocation).
  • Retained unit tests and technical debt documentation.
  • All conventions and guest unit tests pass.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134258178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4524#issuecomment-6134258178). Originally posted by [jagrat04](https://github.com/jagrat04) on 2026-10-12T23:00:52Z. --- Rebased cleanly onto origin/main resolving merge conflicts: - Implemented sceKernelInternalMemoryGetModuleSegmentInfo_nid_postfix by calling sceKernelGetLibkernelTextLocation_nid_postfix directly (matching fpPS4's delegation to ps4_sceKernelGetLibkernelTextLocation). - Retained unit tests and technical debt documentation. - All conventions and guest unit tests pass.
Dextroid17 commented 2026-10-13 00:26:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T00:26:48Z.


@jagrat04 thanks for the rebase. The delegation to sceKernelGetLibkernelTextLocation_nid_postfix matches the fpPS4 code I cited, and the nullptr throw test is useful.

Two points from my review are still open on this head, and the rebase does not answer either:

  1. Which range the answer describes. The helper on main (ModuleInfo.cpp:431) returns segment 0 of the main program. That matches fpPS4, but I still have no evidence that the console's answer is the same range. Only one run would settle it, and I don't have one.
  2. The segment test cannot tell the two readings apart. segment.address == program.segments[0].address is compared against the same main program the helper reads, so it passes under either reading whenever the test binary is the main program. Treat that as a limit of the test, or add a case that distinguishes them.

No change is needed if you're comfortable recording point 1 as an open question in the debt entry.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135248986 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4524#issuecomment-6135248986). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-13T00:26:48Z. --- @jagrat04 thanks for the rebase. The delegation to `sceKernelGetLibkernelTextLocation_nid_postfix` matches the fpPS4 code I cited, and the `nullptr` throw test is useful. Two points from my review are still open on this head, and the rebase does not answer either: 1. **Which range the answer describes.** The helper on `main` (`ModuleInfo.cpp:431`) returns segment 0 of the main program. That matches fpPS4, but I still have no evidence that the console's answer is the same range. Only one run would settle it, and I don't have one. 2. **The segment test cannot tell the two readings apart.** `segment.address == program.segments[0].address` is compared against the same main program the helper reads, so it passes under either reading whenever the test binary is the main program. Treat that as a limit of the test, or add a case that distinguishes them. No change is needed if you're comfortable recording point 1 as an open question in the debt entry. Written with AI assistance.
jagrat04 commented 2026-10-13 01:04:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-13T01:04:08Z.


@Dextroid17 Thanks for the follow-up!
We've rebased cleanly onto latest origin/main. As noted, point 1 is recorded as an open question in the technical debt entry (docs/dev/debt/libkernel.md):

whether the console reports that segment, the text of libkernel itself or the calling module's is unknown.

Since console traces for the exact segment reporting are still pending, keeping this explicitly noted in the technical debt ledger covers it as recommended.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135816741 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4524#issuecomment-6135816741). Originally posted by [jagrat04](https://github.com/jagrat04) on 2026-10-13T01:04:08Z. --- @Dextroid17 Thanks for the follow-up! We've rebased cleanly onto latest `origin/main`. As noted, point 1 is recorded as an open question in the technical debt entry (`docs/dev/debt/libkernel.md`): > whether the console reports that segment, the text of libkernel itself or the calling module's is unknown. Since console traces for the exact segment reporting are still pending, keeping this explicitly noted in the technical debt ledger covers it as recommended.
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!4524
No description provided.