fix(libkernel): write the module handles before failing a null count as measured on a PS5 #11224

Merged
orezraey merged 1 commit from upstream-pr/11224 into main 2026-10-26 22:04:13 +00:00
orezraey commented 2026-10-25 22:08:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T22:08:54Z.


What

sceKernelGetModuleList and its variants (List2, ListInternal, which share FillModuleList) now write the handles before they fail a null actual pointer with EFAULT, as a retail PS5 (firmware 13.60) does. Before, they returned EFAULT without writing anything. Measured with a homebrew probe from a payload process; the source and console log are in this gist (pmodlist).

On the console, for both sceKernelGetModuleList and sceKernelGetModuleList2:

  • Full buffer. Returns 0 with actual 1 and one handle, 0 ("eboot.bin").
  • Count 0. Returns ENOMEM, writing neither actual nor any handle.
  • Null actual. Returns EFAULT after writing handle 0 into the buffer. This is the change.
  • Null handle array. Returns EFAULT with actual untouched.
  • sceKernelGetModuleInfo2. EPERM for libkernel's handle, EINVAL for a size of 0, EFAULT for a null info and ESRCH for a bad handle, as here.

The debt entry asked whether the console writes any handles when it fails, and now records that. It also starts with what still differs. On the console the payload's lists contain only its main program, as handle 0, though libkernel (handle 1) and libSceLibcInternal (handle 2) are loaded. AnyPS5 lists every loaded .prx, with its own ids. A payload is not a title, so that part is recorded rather than changed.

Before and after

sceKernelGetModuleList / List2 PS5 AnyPS5 before AnyPS5 now
null actual EFAULT, handles written EFAULT, nothing written EFAULT, handles written
full buffer 0, actual and handles written the same the same
count 0 ENOMEM, nothing written the same the same
null handle array EFAULT, actual untouched the same the same
handles listed only the main program (payload) every loaded .prx every loaded .prx (debt)

Tested

Windows 11, WinLibs GCC 15.2, full build. The 26 tests matching module pass 3 times out of 3. guest_module_info and guest_kernel_sys_module_internal now check that a null actual returns EFAULT and still fills the buffer with the same handles a successful call returns. tools/check_conventions.py passes.

Head 19f56c530a on main f2c8e1dda4.

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: #10552 (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009205932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11224). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T22:08:54Z. --- ### What `sceKernelGetModuleList` and its variants (`List2`, `ListInternal`, which share `FillModuleList`) now write the handles before they fail a null `actual` pointer with `EFAULT`, as a retail PS5 (firmware 13.60) does. Before, they returned `EFAULT` without writing anything. Measured with a homebrew probe from a payload process; the source and console log are in [this gist](https://gist.github.com/orezraey/295adb3ea094f5ce094b093f5874e69a) (`pmodlist`). On the console, for both `sceKernelGetModuleList` and `sceKernelGetModuleList2`: - **Full buffer.** Returns 0 with `actual` 1 and one handle, 0 ("eboot.bin"). - **Count 0.** Returns `ENOMEM`, writing neither `actual` nor any handle. - **Null `actual`.** Returns `EFAULT` after writing handle 0 into the buffer. This is the change. - **Null handle array.** Returns `EFAULT` with `actual` untouched. - **`sceKernelGetModuleInfo2`.** `EPERM` for libkernel's handle, `EINVAL` for a size of 0, `EFAULT` for a null info and `ESRCH` for a bad handle, as here. The debt entry asked whether the console writes any handles when it fails, and now records that. It also starts with what still differs. On the console the payload's lists contain only its main program, as handle 0, though libkernel (handle 1) and libSceLibcInternal (handle 2) are loaded. AnyPS5 lists every loaded `.prx`, with its own ids. A payload is not a title, so that part is recorded rather than changed. **Before and after** | `sceKernelGetModuleList` / `List2` | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | null `actual` | `EFAULT`, handles written | `EFAULT`, nothing written | `EFAULT`, handles written | | full buffer | 0, `actual` and handles written | the same | the same | | count 0 | `ENOMEM`, nothing written | the same | the same | | null handle array | `EFAULT`, `actual` untouched | the same | the same | | handles listed | only the main program (payload) | every loaded `.prx` | every loaded `.prx` (debt) | ### Tested <!-- 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. --> Windows 11, WinLibs GCC 15.2, full build. The 26 tests matching `module` pass 3 times out of 3. `guest_module_info` and `guest_kernel_sys_module_internal` now check that a null `actual` returns `EFAULT` and still fills the buffer with the same handles a successful call returns. `tools/check_conventions.py` passes. Head `19f56c530a` on `main` `f2c8e1dda4`. ### 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 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: #10552 (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 22:15:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:15:18Z.

Review: APPROVED


Reviewed exact head 19f56c530a02e073ae055f0aa4973d4864f39666, the linked firmware 13.60 probe source/log, FillModuleList callers, and the added tests. The order now matches the measured cases: reject a null handle array first, write up to count handles, return ENOMEM without touching actual when the list does not fit, then return EFAULT for null actual after a full list has been written. The probe records those behaviors for both list exports, and the tests assert that a null actual leaves the same handle array as a successful call.

Current-main git diff --check and conventions pass; the debt-length warning is non-failing. The merge preview against current main is clean. Hosted eligibility, conventions, intake, labels and report pass; product build jobs are skipped by path policy. The 26 focused module tests (three runs) and Windows full build are author-reported against main f2c8e1dda4; I did not rerun them locally. No defect found in the reviewed change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645617095 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11224#pullrequestreview-5645617095). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:15:18Z. **Review:** APPROVED --- Reviewed exact head `19f56c530a02e073ae055f0aa4973d4864f39666`, the linked firmware 13.60 probe source/log, `FillModuleList` callers, and the added tests. The order now matches the measured cases: reject a null handle array first, write up to `count` handles, return `ENOMEM` without touching `actual` when the list does not fit, then return `EFAULT` for null `actual` after a full list has been written. The probe records those behaviors for both list exports, and the tests assert that a null `actual` leaves the same handle array as a successful call. Current-main `git diff --check` and conventions pass; the debt-length warning is non-failing. The merge preview against current main is clean. Hosted eligibility, conventions, intake, labels and report pass; product build jobs are skipped by path policy. The 26 focused module tests (three runs) and Windows full build are author-reported against `main` `f2c8e1dda4`; I did not rerun them locally. No defect found in the reviewed change.
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!11224
No description provided.