feat(libkernel_sys): implement sceKernelTitleWorkaroundIsEnabled and sceKernelGetProcessType #9040

Merged
YossiYad merged 5 commits from upstream-pr/9040 into main 2026-10-23 11:33:16 +00:00
YossiYad commented 2026-10-21 10:35:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-21T10:35:28Z.


What

Two libkernel_sys calls threw. They now follow shadPS4's kernel.cpp:

  • sceKernelTitleWorkaroundIsEnabled(workaround, bit, enabled) reads bit bit of the {s32 version, s32 align, u64 ids[2]} block a title gets from sceKernelGetAppInfo and writes 0 or 1. A null block or output is EFAULT, and a bit of 0x3A or more is EINVAL (shadPS4 notes that this limit moves between firmwares). shadPS4 compares the bit signed, so a negative bit indexes before ids; here the compare is unsigned and a negative bit is EINVAL too.
  • sceKernelGetProcessType(pid) returns 0 (big application) for the title's own pid, -1 and 0, and ESRCH for any other pid, using the same pid that sceKernelGetAppInfo checks.

The misspelled sceKernelTitleWorkdaroundIsEnabled export (NID GST42pfUfMc) is left throwing: shadPS4 registers only 1yca4VvfcNA. Neither result is measured on a PS5; the debt entries say so.

Tested

Linux (Fedora 44, GCC, Ninja, -DBUILD_TESTING=ON), based on main 2abfb1beb4:

  • guest_kernel_sys (core/libs/tests/GuestKernelSys.cpp) gains CheckProcessQueries: null block and null output, bits 0x3A, 63 and -1 refused with the output untouched, bits 3 and 0x39 set and 4 and 0x38 clear, and the four pid cases. It aborts on main, and fails with each of these changes: a signed bit compare, a limit of 0x3B, a 5-bit shift mask, dropping the -1 pid, returning 0 for a foreign pid, and no null check on the output.
  • Full ctest: 1784 of 1792 pass. The 8 failures fail the same way on main on this machine and do not link libkernel_sys: application_heap_scripting, application_heap_lazy, agc_driver_guest_memory_lifetime, agc_driver_image_array_window_past_layer_limit, agc_driver_tessellation and the three net_dontwait_blocking_* cases.
  • tools/progress.py --compare: libraries +0.03%, 2 functions implemented, none lost.
  • tools/check_conventions.py --base upstream/main passes. tools/pr_overlap.py finds no PR with the same exports; #6525, #8457, #8531 and #8987 edit lines next to this PR's test and debt additions.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4950188660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9040). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-21T10:35:28Z. --- ### What Two libkernel_sys calls threw. They now follow [shadPS4's kernel.cpp](https://github.com/shadps4-emu/shadPS4/blob/a808e76/src/core/libraries/kernel/kernel.cpp): - `sceKernelTitleWorkaroundIsEnabled(workaround, bit, enabled)` reads bit `bit` of the `{s32 version, s32 align, u64 ids[2]}` block a title gets from `sceKernelGetAppInfo` and writes 0 or 1. A null block or output is `EFAULT`, and a bit of 0x3A or more is `EINVAL` (shadPS4 notes that this limit moves between firmwares). shadPS4 compares the bit signed, so a negative bit indexes before `ids`; here the compare is unsigned and a negative bit is `EINVAL` too. - `sceKernelGetProcessType(pid)` returns 0 (big application) for the title's own pid, -1 and 0, and `ESRCH` for any other pid, using the same pid that `sceKernelGetAppInfo` checks. The misspelled `sceKernelTitleWorkdaroundIsEnabled` export (NID `GST42pfUfMc`) is left throwing: shadPS4 registers only `1yca4VvfcNA`. Neither result is measured on a PS5; the debt entries say so. ### Tested Linux (Fedora 44, GCC, Ninja, `-DBUILD_TESTING=ON`), based on `main` `2abfb1beb4`: - `guest_kernel_sys` (`core/libs/tests/GuestKernelSys.cpp`) gains `CheckProcessQueries`: null block and null output, bits 0x3A, 63 and -1 refused with the output untouched, bits 3 and 0x39 set and 4 and 0x38 clear, and the four pid cases. It aborts on `main`, and fails with each of these changes: a signed bit compare, a limit of 0x3B, a 5-bit shift mask, dropping the -1 pid, returning 0 for a foreign pid, and no null check on the output. - Full `ctest`: 1784 of 1792 pass. The 8 failures fail the same way on `main` on this machine and do not link libkernel_sys: `application_heap_scripting`, `application_heap_lazy`, `agc_driver_guest_memory_lifetime`, `agc_driver_image_array_window_past_layer_limit`, `agc_driver_tessellation` and the three `net_dontwait_blocking_*` cases. - `tools/progress.py --compare`: libraries +0.03%, 2 functions implemented, none lost. - `tools/check_conventions.py --base upstream/main` passes. `tools/pr_overlap.py` finds no PR with the same exports; #6525, #8457, #8531 and #8987 edit lines next to this PR's test and debt additions. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-22 04:12:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T04:12:29Z.

Review: COMMENTED


Checked against main 6ef5a1c4c and shadPS4 a808e76 src/core/libraries/kernel/kernel.{cpp,h}:

  • sceKernelTitleWorkaroundIsEnabled matches shadPS4's decompiled bit test (EFAULT for null, EINVAL for bit >= 0x3A, ids[bit>>6] >> (bit&0x3F) & 1), and the unsigned bound check for negative bits is a sensible, documented deviation. sceKernelGetProcessType matches shadPS4 exactly (own pid, -1 and 0 give 0, anything else gives ESRCH).
  • shadPS4 says most callers pass the title_workaround block from sceKernelGetAppInfo, and its sceKernelGetAppInfo zero-fills the whole OrbisKernelAppInfo. Main's sceKernelGetAppInfo (core/libs/prx/libkernel/System/src/Process.cpp:282-295) only writes app_id and the title ID and deliberately leaves the rest untouched; GuestAppInfo.cpp asserts that and docs/dev/debt/libkernel.md documents it.
  • So a title doing sceKernelGetAppInfo(getpid(), &info) on a stack struct and then sceKernelTitleWorkaroundIsEnabled(&info.title_workaround, n, &r) now gets 0 back with whatever stack bits were there, so workarounds are enabled at random, where before this PR it threw. Could the new docs/dev/debt/libkernel_sys.md entry for sceKernelTitleWorkaroundIsEnabled record that its input is not populated on this platform? If a title motivated this, which call site is it, and where does its block come from?
  • Both behaviours are from a PS4 emulator and unmeasured on PS5, as the debt entries already say.
  • Builds on Windows (WinLibs GCC 15.2.0 r7, full BUILD_TESTING=ON build) merged onto main 6ef5a1c4c; the only failing step is the existing ImageArrayWindowPastLayerLimit.cpp alignment error that #8310 fixes. Not run here: this machine's Smart App Control blocks freshly built test executables.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609168513 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9040#pullrequestreview-5609168513). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T04:12:29Z. **Review:** COMMENTED --- Checked against main 6ef5a1c4c and shadPS4 a808e76 `src/core/libraries/kernel/kernel.{cpp,h}`: - `sceKernelTitleWorkaroundIsEnabled` matches shadPS4's decompiled bit test (EFAULT for null, EINVAL for bit >= 0x3A, `ids[bit>>6] >> (bit&0x3F) & 1`), and the unsigned bound check for negative bits is a sensible, documented deviation. `sceKernelGetProcessType` matches shadPS4 exactly (own pid, -1 and 0 give 0, anything else gives ESRCH). - shadPS4 says most callers pass the `title_workaround` block from `sceKernelGetAppInfo`, and its `sceKernelGetAppInfo` zero-fills the whole `OrbisKernelAppInfo`. Main's `sceKernelGetAppInfo` (`core/libs/prx/libkernel/System/src/Process.cpp:282-295`) only writes `app_id` and the title ID and deliberately leaves the rest untouched; `GuestAppInfo.cpp` asserts that and `docs/dev/debt/libkernel.md` documents it. - So a title doing `sceKernelGetAppInfo(getpid(), &info)` on a stack struct and then `sceKernelTitleWorkaroundIsEnabled(&info.title_workaround, n, &r)` now gets 0 back with whatever stack bits were there, so workarounds are enabled at random, where before this PR it threw. Could the new `docs/dev/debt/libkernel_sys.md` entry for `sceKernelTitleWorkaroundIsEnabled` record that its input is not populated on this platform? If a title motivated this, which call site is it, and where does its block come from? - Both behaviours are from a PS4 emulator and unmeasured on PS5, as the debt entries already say. - Builds on Windows (WinLibs GCC 15.2.0 r7, full `BUILD_TESTING=ON` build) merged onto main 6ef5a1c4c; the only failing step is the existing `ImageArrayWindowPastLayerLimit.cpp` alignment error that #8310 fixes. Not run here: this machine's Smart App Control blocks freshly built test executables. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
YossiYad commented 2026-10-22 05:21:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-22T05:21:50Z.


@harisibrar1 thanks, that's a real gap. The sceKernelTitleWorkaroundIsEnabled debt entry now says that titles usually pass the title_workaround block of sceKernelGetAppInfo, that sceKernelGetAppInfo doesn't write that block here, and that the bits read are whatever the caller's memory held.

No title motivated this. The two calls were among the throwing libkernel_sys exports that shadPS4 already covers, so the PR says Unblocks: none. I left sceKernelGetAppInfo alone because the size problem that keeps it from writing past the title ID is its own topic.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333396774 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9040#issuecomment-6333396774). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-22T05:21:50Z. --- @harisibrar1 thanks, that's a real gap. The `sceKernelTitleWorkaroundIsEnabled` debt entry now says that titles usually pass the `title_workaround` block of `sceKernelGetAppInfo`, that `sceKernelGetAppInfo` doesn't write that block here, and that the bits read are whatever the caller's memory held. No title motivated this. The two calls were among the throwing libkernel_sys exports that shadPS4 already covers, so the PR says Unblocks: none. I left `sceKernelGetAppInfo` alone because the size problem that keeps it from writing past the title ID is its own topic.
harisibrar1 commented 2026-10-22 05:31:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T05:31:37Z.

Review: APPROVED


Rechecked be12c45d7: the sceKernelTitleWorkaroundIsEnabled debt entry now records that titles usually pass the title_workaround block from sceKernelGetAppInfo, that this platform doesn't write that block, and that the bits read are whatever the caller's memory held. That covers my point, and keeping the sceKernelGetAppInfo size question as its own topic makes sense. The change since my review is documentation only.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609668544 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9040#pullrequestreview-5609668544). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T05:31:37Z. **Review:** APPROVED --- Rechecked be12c45d7: the `sceKernelTitleWorkaroundIsEnabled` debt entry now records that titles usually pass the `title_workaround` block from `sceKernelGetAppInfo`, that this platform doesn't write that block, and that the bits read are whatever the caller's memory held. That covers my point, and keeping the `sceKernelGetAppInfo` size question as its own topic makes sense. The change since my review is documentation only. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
YossiYad commented 2026-10-22 12:58:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-22T12:58:47Z.


Rebased onto main 8b3a6ba88 after #9279 (head e99e0d93a). The conflicts were #9279's code and debt entry next to this PR's; I kept both, and this PR's lines are unchanged. guest_kernel_sys passes 3 of 3.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341341107 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9040#issuecomment-6341341107). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-22T12:58:47Z. --- Rebased onto `main` `8b3a6ba88` after #9279 (head `e99e0d93a`). The conflicts were #9279's code and debt entry next to this PR's; I kept both, and this PR's lines are unchanged. `guest_kernel_sys` passes 3 of 3.
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!9040
No description provided.