feat(sysmodule): answer IsCameraPreloaded and forward UnloadModuleByNameInternal #22362

Merged
zaryabzip merged 5 commits from upstream-pr/22362 into main 2026-11-26 02:13:04 +00:00
zaryabzip commented 2026-11-17 12:54:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-11-17T12:54:38Z.


What

sceSysmoduleIsCameraPreloaded returns 0 in a PS5 process. sceSysmoduleUnloadModuleByNameInternal forwards to sceKernelStopUnloadModule. On main both are parameterless declarations that throw.

Source. @BunnyFl's reading of libSceSysmodule.sprx (13.42) on #21866 (comment). It is disassembly only, not measured on a console.

  • sceSysmoduleIsCameraPreloaded(void) (0xcd0) asks sceKernelIsPs4Process(). In a PS5 process it returns 0 (xor eax,eax; ret) and reads no argument. Its PS4-process path (0x29b0) wasn't read.
  • sceSysmoduleUnloadModuleByNameInternal (0xba0) is a tail jump into sceKernelStopUnloadModule, with r8 moved to r9 and r8 set to 0. So (handle, args, argp, flags, result) becomes sceKernelStopUnloadModule(handle, args, argp, flags, NULL, result). It has no checks of its own and takes no name, despite its name.

Change (Export.cpp, Api.hpp, CMakeLists.txt). IsCameraPreloaded returns 0 unless sceKernelIsPs4Process() reports a PS4 process, where it throws. libSceSysmodule now links libkernel_sys for that call. UnloadModuleByNameInternal forwards with a null option.

Debt. Following the fragment rule, this adds docs/dev/debt/changes/feat-sysmodule-camera-preloaded.md. It takes the two names out of the five-export "no credible prototypes" entry and adds an entry citing the reading. The other three (IsCalledFromSysModule, MapLibcForLibkernel, PreloadModuleForLibkernel) stay as they are. The fragment folds cleanly in isolation.

Test (GuestSysmodule.cpp, ctest guest_sysmodule). New rows, placed just before the existing final sceKernelStopUnloadModule row so the test merges with #18184, which appends after that row:

  • UnloadModuleByNameInternal on handle 0x7fffffff returns what sceKernelStopUnloadModule returns for it, with the same result output;
  • IsCameraPreloaded() returns 0. The test process is not a PS4 title.

Tested

  • Windows, by my test session at 68d1761431. Windows 11 Home 25H2 (26200.9974), i7-11800H, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, BUILD_TESTING=ON, on main cb28e72762.
    • guest_sysmodule and guest_sysmodule-invalid-ids pass. The new libkernel_sys link builds with no warnings.
    • Control 1: main's Export.cpp with UnloadModuleByNameInternal given the branch's signature, plus the branch's header and test. It aborts (0xc0000409) with sceSysmoduleUnloadModuleByNameInternal not implemented, whose row comes first.
    • Control 2: the branch's Export.cpp with only IsCameraPreloaded's body put back to main's. It aborts with sceSysmoduleIsCameraPreloaded not implemented.
    • guest_sysmodule-invalid-ids passes under both controls.
  • Not run on macOS: the library needs too much of libkernel for the host harness. Only a compile check was done there.
  • Windows, by @kiwe147 (report), at c3f9593c5a applied with 28 other PRs on main fd4aeed483. Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, RTX 3080. guest_sysmodule passes. Of its nine whole-batch failures, four also fail on main and three are intermittent. The other three (guest_agc_driver_unknown, guest_load_ranges, tool_script_modes) weren't traced to a single PR. This is one combined tree, not this PR alone.
  • PS5 console, by @noisyweather (measurement), firmware 9.20, from a payload process rather than an application, where sceKernelIsPs4Process() is 0. IsCameraPreloaded() returned 0 on two calls. UnloadModuleByNameInternal on handles 0xffffffff, 0x7fffffff and 0x12345 returned 0x80020003 with the result untouched, the same as sceKernelStopUnloadModule(handle, 0, NULL, 0, NULL, &res), and a null result pointer was accepted. A real handle couldn't be tested, since the module load failed.

Debt interaction with #23240 (Thimo188, MapLibcForLibkernel and PreloadModuleForLibkernel). The code merges cleanly. The fragment feat-sysmodule-is-called-from-sysmodule.md, which this branch deletes in the maintainer's main merge c3f9593c5a, is edited there. Whichever lands second drops the two-name MapLibcForLibkernel and PreloadModuleForLibkernel entry from this PR's fragment; the details are in my comment there.

git merge-tree finds no conflict with main or with any open PR that merges with main, including #18184.

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: none
  • Fixes: none (part of #21866; IsCalledFromSysModule, MapLibcForLibkernel and PreloadModuleForLibkernel need libkernel and preload code that wasn't read)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5357213734 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22362). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-11-17T12:54:38Z. --- ### What `sceSysmoduleIsCameraPreloaded` returns 0 in a PS5 process. `sceSysmoduleUnloadModuleByNameInternal` forwards to `sceKernelStopUnloadModule`. On `main` both are parameterless declarations that throw. **Source.** @BunnyFl's reading of `libSceSysmodule.sprx` (13.42) on #21866 ([comment](https://github.com/boykopovar/AnyPS5/issues/21866#issuecomment-6942648672)). It is disassembly only, not measured on a console. - `sceSysmoduleIsCameraPreloaded(void)` (`0xcd0`) asks `sceKernelIsPs4Process()`. In a PS5 process it returns 0 (`xor eax,eax; ret`) and reads no argument. Its PS4-process path (`0x29b0`) wasn't read. - `sceSysmoduleUnloadModuleByNameInternal` (`0xba0`) is a tail jump into `sceKernelStopUnloadModule`, with `r8` moved to `r9` and `r8` set to 0. So `(handle, args, argp, flags, result)` becomes `sceKernelStopUnloadModule(handle, args, argp, flags, NULL, result)`. It has no checks of its own and takes no name, despite its name. **Change** (`Export.cpp`, `Api.hpp`, `CMakeLists.txt`). `IsCameraPreloaded` returns 0 unless `sceKernelIsPs4Process()` reports a PS4 process, where it throws. `libSceSysmodule` now links `libkernel_sys` for that call. `UnloadModuleByNameInternal` forwards with a null option. **Debt.** Following the fragment rule, this adds `docs/dev/debt/changes/feat-sysmodule-camera-preloaded.md`. It takes the two names out of the five-export "no credible prototypes" entry and adds an entry citing the reading. The other three (`IsCalledFromSysModule`, `MapLibcForLibkernel`, `PreloadModuleForLibkernel`) stay as they are. The fragment folds cleanly in isolation. **Test** (`GuestSysmodule.cpp`, ctest `guest_sysmodule`). New rows, placed just before the existing final `sceKernelStopUnloadModule` row so the test merges with #18184, which appends after that row: - `UnloadModuleByNameInternal` on handle `0x7fffffff` returns what `sceKernelStopUnloadModule` returns for it, with the same result output; - `IsCameraPreloaded()` returns 0. The test process is not a PS4 title. ### Tested - **Windows, by my test session** at `68d1761431`. Windows 11 Home 25H2 (26200.9974), i7-11800H, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, `BUILD_TESTING=ON`, on `main` `cb28e72762`. - `guest_sysmodule` and `guest_sysmodule-invalid-ids` pass. The new `libkernel_sys` link builds with no warnings. - Control 1: `main`'s `Export.cpp` with `UnloadModuleByNameInternal` given the branch's signature, plus the branch's header and test. It aborts (`0xc0000409`) with `sceSysmoduleUnloadModuleByNameInternal not implemented`, whose row comes first. - Control 2: the branch's `Export.cpp` with only `IsCameraPreloaded`'s body put back to `main`'s. It aborts with `sceSysmoduleIsCameraPreloaded not implemented`. - `guest_sysmodule-invalid-ids` passes under both controls. - Not run on macOS: the library needs too much of libkernel for the host harness. Only a compile check was done there. - **Windows, by @kiwe147** ([report](https://github.com/boykopovar/AnyPS5/pull/22362#issuecomment-7062826307)), at `c3f9593c5a` applied with 28 other PRs on `main` `fd4aeed483`. Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, RTX 3080. `guest_sysmodule` passes. Of its nine whole-batch failures, four also fail on `main` and three are intermittent. The other three (`guest_agc_driver_unknown`, `guest_load_ranges`, `tool_script_modes`) weren't traced to a single PR. This is one combined tree, not this PR alone. - **PS5 console, by @noisyweather** ([measurement](https://github.com/boykopovar/AnyPS5/issues/21866#issuecomment-7074266697)), firmware 9.20, from a payload process rather than an application, where `sceKernelIsPs4Process()` is 0. `IsCameraPreloaded()` returned 0 on two calls. `UnloadModuleByNameInternal` on handles `0xffffffff`, `0x7fffffff` and `0x12345` returned `0x80020003` with the result untouched, the same as `sceKernelStopUnloadModule(handle, 0, NULL, 0, NULL, &res)`, and a null result pointer was accepted. A real handle couldn't be tested, since the module load failed. **Debt interaction with #23240** (Thimo188, `MapLibcForLibkernel` and `PreloadModuleForLibkernel`). The code merges cleanly. The fragment `feat-sysmodule-is-called-from-sysmodule.md`, which this branch deletes in the maintainer's main merge `c3f9593c5a`, is edited there. Whichever lands second drops the two-name `MapLibcForLibkernel and PreloadModuleForLibkernel` entry from this PR's fragment; the details are in [my comment there](https://github.com/boykopovar/AnyPS5/pull/23240). `git merge-tree` finds no conflict with `main` or with any open PR that merges with `main`, including #18184. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none (part of #21866; IsCalledFromSysModule, MapLibcForLibkernel and PreloadModuleForLibkernel need libkernel and preload code that wasn't read) - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-17 13:20:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T13:20:45Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 68d1761431:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_sysmodule_tests built cleanly.
  • CTest (guest_sysmodule, guest_sysmodule_maps_scan):
    1/2 Test #4890: guest_sysmodule_maps_scan ........   Passed    0.05 sec
    2/2 Test #4889: guest_sysmodule ..................   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceSysmodule/Export.cpp, core/libs/prx/libSceSysmodule/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceSysmodule/Export.cpp: verified sceSysmoduleIsCameraPreloaded returns 0 for PS5 processes and throws NotImplemented for PS4 processes matching libkernel sceKernelIsPs4Process semantics
    • core/libs/prx/libSceSysmodule/Export.cpp: verified sceSysmoduleUnloadModuleByNameInternal correctly maps (handle, args, argp, flags, res) to sceKernelStopUnloadModule(handle, args, argp, flags, nullptr, res)
    • core/libs/prx/libSceSysmodule/include/Api.hpp: verified signature and ABI declarations match implementation and APS5_VABI calling convention
    • docs/dev/debt/changes/feat-sysmodule-camera-preloaded.md: checked technical debt fragment formatting, removal, and addition sections against AGENTS.md rules
    • core/libs/tests/GuestSysmodule.cpp: verified unit tests exercise both functions and assert expected return codes and output values without state contamination

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5939212686 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22362#pullrequestreview-5939212686). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T13:20:45Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `68d1761431`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_sysmodule_tests` built cleanly. - **CTest** (`guest_sysmodule`, `guest_sysmodule_maps_scan`): ``` 1/2 Test #4890: guest_sysmodule_maps_scan ........ Passed 0.05 sec 2/2 Test #4889: guest_sysmodule .................. Passed 0.05 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceSysmodule/Export.cpp`, `core/libs/prx/libSceSysmodule/include/Api.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceSysmodule/Export.cpp: verified sceSysmoduleIsCameraPreloaded returns 0 for PS5 processes and throws NotImplemented for PS4 processes matching libkernel sceKernelIsPs4Process semantics - core/libs/prx/libSceSysmodule/Export.cpp: verified sceSysmoduleUnloadModuleByNameInternal correctly maps (handle, args, argp, flags, res) to sceKernelStopUnloadModule(handle, args, argp, flags, nullptr, res) - core/libs/prx/libSceSysmodule/include/Api.hpp: verified signature and ABI declarations match implementation and APS5_VABI calling convention - docs/dev/debt/changes/feat-sysmodule-camera-preloaded.md: checked technical debt fragment formatting, removal, and addition sections against AGENTS.md rules - core/libs/tests/GuestSysmodule.cpp: verified unit tests exercise both functions and assert expected return codes and output values without state contamination Looks Good To Me
MarcZX10 commented 2026-11-22 08:26:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:26:29Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and tests support merging at the reviewed head.

What I ran

Reviewed head c3f9593c5aa8085a72552ea230bb659619a47f78. I read the prepared description, commits, manifest, diff, all included changed files, and the kernel unload implementation. No build or tests were run in this review; platform results in the description are author- or contributor-reported.

Results

Check Result Note
Changed code review passed Five included files read
Deleted debt fragment not applicable Deletion recorded in manifest
Build and tests in this review not run Reported runs were not reproduced

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not read the deleted debt fragment, files excluded by preparation rules, or unrelated repository files. I did not run tests or verify console behavior. The description reports Windows test results and PS5 measurements, but those were not reproduced here.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011218923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22362#pullrequestreview-6011218923). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T08:26:29Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and tests support merging at the reviewed head. ## What I ran Reviewed head `c3f9593c5aa8085a72552ea230bb659619a47f78`. I read the prepared description, commits, manifest, diff, all included changed files, and the kernel unload implementation. No build or tests were run in this review; platform results in the description are author- or contributor-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Five included files read | | Deleted debt fragment | not applicable | Deletion recorded in manifest | | Build and tests in this review | not run | Reported runs were not reproduced | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not read the deleted debt fragment, files excluded by preparation rules, or unrelated repository files. I did not run tests or verify console behavior. The description reports Windows test results and PS5 measurements, but those were not reproduced here. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 14:47:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:47:58Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed code blocks merging; the implementation follows the described forwarding and PS5 return behavior, with the PS4 path intentionally left unimplemented.

What I ran

Reviewed head 16bbdee2f713bd4dcbecfe0b69a108381fb198f7. Read the prepared description, commits, diff, manifest, all five included changed files, and targeted implementation and caller context using repo_read.py. No build or tests were run in this review.

Results

Check Result Note
Source review passed Changed implementation and test rows inspected
Build and tests not run Only author and reporter results supplied

Findings

Blocking

None.

Non-blocking

None.

Not verified

The deleted file docs/dev/debt/changes/feat-sysmodule-is-called-from-sysmodule.md was excluded because it has no added text; its prior contents are visible in the prepared diff. Build/test reports in the description are author- or reporter-supplied and were not independently reproduced. PS4-process behavior for sceSysmoduleIsCameraPreloaded remains unverified as stated in the change documentation.

To get this to a good state

Nothing is required.

Sources

The change's behavior is documented in docs/dev/debt/changes/feat-sysmodule-camera-preloaded.md; the forwarding implementation is at core/libs/prx/libSceSysmodule/Export.cpp:469-470, and sceKernelStopUnloadModule is declared and implemented with the matching argument order.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6059838030 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22362#pullrequestreview-6059838030). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T14:47:58Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed code blocks merging; the implementation follows the described forwarding and PS5 return behavior, with the PS4 path intentionally left unimplemented. ## What I ran Reviewed head `16bbdee2f713bd4dcbecfe0b69a108381fb198f7`. Read the prepared description, commits, diff, manifest, all five included changed files, and targeted implementation and caller context using `repo_read.py`. No build or tests were run in this review. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Changed implementation and test rows inspected | | Build and tests | not run | Only author and reporter results supplied | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The deleted file `docs/dev/debt/changes/feat-sysmodule-is-called-from-sysmodule.md` was excluded because it has no added text; its prior contents are visible in the prepared diff. Build/test reports in the description are author- or reporter-supplied and were not independently reproduced. PS4-process behavior for `sceSysmoduleIsCameraPreloaded` remains unverified as stated in the change documentation. ## To get this to a good state Nothing is required. ## Sources The change's behavior is documented in `docs/dev/debt/changes/feat-sysmodule-camera-preloaded.md`; the forwarding implementation is at `core/libs/prx/libSceSysmodule/Export.cpp:469-470`, and `sceKernelStopUnloadModule` is declared and implemented with the matching argument order.
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!22362
No description provided.