Skip to content

fix(libkernel): answer ESRCH for unused pids in sceKernelGetAppCategoryType - #24672

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
olegon85:fix/libkernel-app-category-unknown-pid-esrch
Nov 25, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
olegon85:fix/libkernel-app-category-unknown-pid-esrch

Conversation

@olegon85

@olegon85 olegon85 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelGetAppCategoryType threw for any positive pid that is neither 0 nor self, on the reading that the console only answers for processes AnyPS5 does not have. A payload process on a PS5 Pro (firmware 13.60) answered unused pid 999999 exactly like a negative one: ESRCH (0x80020003) with errno 3 and the output untouched, so unknown pids are refused, not answered per-process from the caller's view. The throw is replaced by that answer; pid 0 and self keep returning the category.

The same session measured pid 0 and self in a payload process returning rc 0 with output 0xffffffff, where the earlier 13.590.001 report noted 0 - the value for a process without category data is not firmware-stable; the debt entry now records both answers, keeps the title value unmeasured and states the Ghidra-only Agc caller note more briefly.

Since the PR was opened the function moved to core/libs/prx/libkernel/SysExports.cpp (export-parity merge #17885), which kept the throw; this branch is rebased onto that layout and applies the same change there, with the entry retargeted from libkernel_sys.md to libkernel.md. The neo-mode test's --category mode pinned the throw for a different pid; it now pins the measured ESRCH answer.

Probe source and raw session output are in the first comment. Measurement context: PS5 Pro, kernel_get_fw_version = 0x13600007, payload process loaded over elfldr (port 9021), session 2026-11-20T22:35:53Z UTC; a title process was not measured.

Tested

  • Console: probe tw3 with one flushed STEP line before every call; it exited by itself and the five sceKernelGetAppCategoryType calls are quoted in full in the first comment.
  • Server (Linux) after the rebase: ctest -R 'app_category|neo_mode' - 7/7 passed (guest_kernel_sys_app_category, guest_kernel_app_category, both neo-mode binaries, all three guest_system_service_app_category_type_* modes).
  • python3 tools/check_conventions.py --base origin/main: 1 finding (debt-length warning on the rewritten entry), 0 errors. Isolated fold of the fragment against current main applies to exactly one libkernel.md entry.
  • python3 tools/pr_overlap.py --branch fix/libkernel-app-category-unknown-pid-esrch: no overlap among comparable PRs; feat(libkernel): implement the sceKernel*ToolMemory exports #17897 and feat(libkernel): implement sceKernelSetProcessProperty #17908 share SysExports.cpp but conflict with the base and could not be compared - their patches move this function verbatim (keeping the throw) as part of export parity, so whichever merges after this one should carry the ESRCH answer over.

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

@olegon85

Copy link
Copy Markdown
Contributor Author

Console evidence

Measurement context: PS5 Pro, kernel_get_fw_version = 0x13600007 (firmware 13.60), payload process loaded over elfldr (port 9021); a title process was not measured. Session 2026-11-20T22:35:53Z UTC. Every call is preceded by a flushed STEP line; the probe exited by itself.

Raw output of probe tw3 (nine unnamed exports resolved by NID text, the module-byte pair in call order, the Neo family and the category matrix):

TW3|FW|0x13600007
TW3|LK|880822e20|ok
TW3|STEP|pCbBddNl66Y
TW3|SYM|pCbBddNl66Y|82c746dc0
TW3|STEP|zAloppPJxy0
TW3|SYM|zAloppPJxy0|82c746dd0
TW3|STEP|vq2+HyP5U5I
TW3|SYM|vq2+HyP5U5I|82c7485b0
TW3|STEP|z+e0vV-tnH4
TW3|SYM|z+e0vV-tnH4|82c74db20
TW3|STEP|gJ5gpW45mU0
TW3|SYM|gJ5gpW45mU0|82c774a90
TW3|STEP|N94a0T4F4+U
TW3|SYM|N94a0T4F4+U|82c74a700
TW3|STEP|C49jelxiaVE
TW3|SYM|C49jelxiaVE|82c773c30
TW3|STEP|1WXQlxMpnNA
TW3|SYM|1WXQlxMpnNA|82c75a690
TW3|STEP|FR0odl35yQY
TW3|SYM|FR0odl35yQY|82c75a6a0
TW3|STEP|pCbBddNl66Y
TW3|CALL|pCbBddNl66Y|0x0
TW3|STEP|zAloppPJxy0
TW3|CALL|zAloppPJxy0|0x0
TW3|STEP|vq2+HyP5U5I
TW3|CALL|vq2+HyP5U5I|0x0
TW3|STEP|z+e0vV-tnH4
TW3|CALL|z+e0vV-tnH4|0x0
TW3|STEP|gJ5gpW45mU0
TW3|CALL|gJ5gpW45mU0|0x0
TW3|STEP|N94a0T4F4+U
TW3|CALL|N94a0T4F4+U|0x8002004e
TW3|STEP|C49jelxiaVE
TW3|CALL|C49jelxiaVE|0x20018
TW3|STEP|FR0odl35yQY-before
TW3|CALL|FR0-before|0x0
TW3|STEP|1WXQlxMpnNA-first
TW3|CALL|1WXQ-first|0x0
TW3|STEP|FR0odl35yQY-after
TW3|CALL|FR0-after|0x1
TW3|STEP|1WXQlxMpnNA-second
TW3|CALL|1WXQ-second|0x0
TW3|SYM2|IS=82c7524a0 HAS=82c750af0 AUTH=82c750b00
TW3|STEP|sceKernelIsNeoMode
TW3|CALL|IsNeoMode|0x1
TW3|STEP|sceKernelHasNeoMode
TW3|CALL|HasNeoMode|0x1
TW3|STEP|sceKernelIsAuthenticNeo
TW3|CALL|IsAuthenticNeo|0x1
TW3|SYM3|CAT=82c752f90
TW3|STEP|cat-null
TW3|CALL|cat_null|rc=0x80020016
TW3|STEP|cat-pid0
TW3|CALL|cat_pid0|rc=0x0|val=0xffffffff
TW3|STEP|cat-self
TW3|CALL|cat_self|rc=0x0|val=0xffffffff
TW3|STEP|cat-neg
TW3|CALL|cat_neg|rc=0x80020003|errno=3
TW3|STEP|cat-unused
TW3|CALL|cat_unused|rc=0x80020003|errno=3
TW3|DONE

pCbBddNl66Y, zAloppPJxy0, vq2+HyP5U5I, z+e0vV-tnH4 and gJ5gpW45mU0 returned 0; N94a0T4F4+U returned 0x8002004e; C49jelxiaVE returned 0x20018; the pair behaved as documented (byte 0 → store-call returns 0 → byte 1 → second call still 0). sceKernelIsNeoMode, sceKernelHasNeoMode and sceKernelIsAuthenticNeo answered 1 on this PS5 Pro in a process with no sfo. sceKernelGetAppCategoryType: null output 0x80020016; pid 0 and own pid rc=0 output 0xffffffff; -1 and the unused pid 999999 both 0x80020003 with errno 3.

Probe source:

tw3/main.c
#include <ps5/kernel.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>

typedef uint64_t (*U64Fn)(void);
typedef int (*CatFn)(int pid, uint32_t* out);

static void step(const char* what) {
    printf("TW3|STEP|%s\n", what);
    fflush(stdout);
}

int main(void) {
    printf("TW3|FW|0x%x\n", kernel_get_fw_version());
    fflush(stdout);

    void* lk = dlopen("libkernel_sys.sprx", RTLD_LAZY);
    printf("TW3|LK|%p|%s\n", lk, lk ? "ok" : dlerror());
    fflush(stdout);
    if (!lk) return 1;

    static const char* NIDS[] = {
        "pCbBddNl66Y", "zAloppPJxy0", "vq2+HyP5U5I", "z+e0vV-tnH4", "gJ5gpW45mU0",
        "N94a0T4F4+U", "C49jelxiaVE", "1WXQlxMpnNA", "FR0odl35yQY"
    };
    void* h[9];
    for (int i = 0; i < 9; ++i) {
        step(NIDS[i]);
        h[i] = dlsym(lk, NIDS[i]);
        printf("TW3|SYM|%s|%p\n", NIDS[i], h[i]);
        fflush(stdout);
    }

    for (int i = 0; i < 7; ++i) {
        if (!h[i]) continue;
        step(NIDS[i]);
        uint64_t r = ((U64Fn)h[i])();
        printf("TW3|CALL|%s|0x%llx\n", NIDS[i], (unsigned long long)r);
        fflush(stdout);
    }

    if (h[8]) {
        step("FR0odl35yQY-before");
        uint64_t r = ((U64Fn)h[8])();
        printf("TW3|CALL|FR0-before|0x%llx\n", (unsigned long long)r);
        fflush(stdout);
    }
    if (h[7]) {
        step("1WXQlxMpnNA-first");
        uint64_t r = ((U64Fn)h[7])();
        printf("TW3|CALL|1WXQ-first|0x%llx\n", (unsigned long long)r);
        fflush(stdout);
    }
    if (h[8]) {
        step("FR0odl35yQY-after");
        uint64_t r = ((U64Fn)h[8])();
        printf("TW3|CALL|FR0-after|0x%llx\n", (unsigned long long)r);
        fflush(stdout);
    }
    if (h[7]) {
        step("1WXQlxMpnNA-second");
        uint64_t r = ((U64Fn)h[7])();
        printf("TW3|CALL|1WXQ-second|0x%llx\n", (unsigned long long)r);
        fflush(stdout);
    }

    U64Fn ISNEO = (U64Fn)dlsym(lk, "sceKernelIsNeoMode");
    U64Fn HASNEO = (U64Fn)dlsym(lk, "sceKernelHasNeoMode");
    U64Fn AUTHNEO = (U64Fn)dlsym(lk, "sceKernelIsAuthenticNeo");
    printf("TW3|SYM2|IS=%p HAS=%p AUTH=%p\n", (void*)ISNEO, (void*)HASNEO, (void*)AUTHNEO);
    fflush(stdout);
    if (ISNEO) {
        step("sceKernelIsNeoMode");
        printf("TW3|CALL|IsNeoMode|0x%llx\n", (unsigned long long)ISNEO());
        fflush(stdout);
    }
    if (HASNEO) {
        step("sceKernelHasNeoMode");
        printf("TW3|CALL|HasNeoMode|0x%llx\n", (unsigned long long)HASNEO());
        fflush(stdout);
    }
    if (AUTHNEO) {
        step("sceKernelIsAuthenticNeo");
        printf("TW3|CALL|IsAuthenticNeo|0x%llx\n", (unsigned long long)AUTHNEO());
        fflush(stdout);
    }

    CatFn CAT = (CatFn)dlsym(lk, "sceKernelGetAppCategoryType");
    printf("TW3|SYM3|CAT=%p\n", (void*)CAT);
    fflush(stdout);
    if (CAT) {
        uint32_t out = 0xAAAAAAAAu;
        int rc;
        step("cat-null");
        rc = CAT(0, 0);
        printf("TW3|CALL|cat_null|rc=0x%x\n", (unsigned)rc);
        fflush(stdout);
        step("cat-pid0");
        out = 0xAAAAAAAAu;
        rc = CAT(0, &out);
        printf("TW3|CALL|cat_pid0|rc=0x%x|val=0x%x\n", (unsigned)rc, out);
        fflush(stdout);
        step("cat-self");
        out = 0xAAAAAAAAu;
        rc = CAT((int)getpid(), &out);
        printf("TW3|CALL|cat_self|rc=0x%x|val=0x%x\n", (unsigned)rc, out);
        fflush(stdout);
        step("cat-neg");
        errno = 0;
        out = 0xAAAAAAAAu;
        rc = CAT(-1, &out);
        printf("TW3|CALL|cat_neg|rc=0x%x|errno=%d\n", (unsigned)rc, errno);
        fflush(stdout);
        step("cat-unused");
        errno = 0;
        out = 0xAAAAAAAAu;
        rc = CAT(999999, &out);
        printf("TW3|CALL|cat_unused|rc=0x%x|errno=%d\n", (unsigned)rc, errno);
        fflush(stdout);
    }

    printf("TW3|DONE\n");
    fflush(stdout);
    return 0;
}

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the unused PID path returns ESRCH, sets errno, and leaves the output untouched, with a regression check for that behavior.

What I ran

Reviewed head 6154b2e1444f796734a757361a0eab9408581d60 against base main. I read the prepared description, commit summary, manifest, diff, and all three changed files. The repository reader was repo_read.py. No commands or tests were run in this review.

Results

Check Result Note
Diff and changed code passed Three changed files read
Tests not run No local test execution
Console behavior not verified Description reports author measurements

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports console measurements and server tests, but I did not independently verify them. No files were excluded from the review; files.json was not available in the review folder listing, and the manifest marks each changed file as included.

To get this to a good state

Nothing is required.

@olegon85
olegon85 force-pushed the fix/libkernel-app-category-unknown-pid-esrch branch from 6154b2e to 4cee543 Compare November 21, 2026 00:17

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

Changes are required before merge: update the existing test that still expects an exception for a different process ID.

What I ran

Reviewed head 4cee54385d7084877d4959ddf388fdcf9a6fb22d. No tests or builds were run. I read description.md, commits.md, manifest.json, diff.patch, all three included changed files, and the related GuestKernelSysNeoMode.cpp test; no changed files were excluded.

Results

Check Result Note
Diff and targeted source review passed Changed behavior and caller test inspected
Build and tests not run No commands run

Findings

Blocking

None.

Non-blocking

  • core/libs/tests/GuestKernelSysNeoMode.cpp still expects a different PID to throw in --category (lines 145–148). The changed implementation now returns ESRCH, so that test will fail if this test mode runs. Update it to assert the error code, errno, and unchanged output, consistent with the new app-category test (core/libs/prx/libkernel_sys/Export.Discovery.cpp:696-699).

Not verified

Build and test execution were not performed. The console measurements and CI results described by the author were not independently verified.

To get this to a good state

Nothing is required for the changed implementation. Optionally update the stale GuestKernelSysNeoMode.cpp expectation to match the new error return.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4cee54385d:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_sys_app_category_tests built cleanly.
  • CTest (guest_kernel_sys_app_category):
    1/1 Test #845: guest_kernel_sys_app_category ....   Passed    0.04 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel_sys/Export.Discovery.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #845: guest_kernel_sys_app_category ....Subprocess aborted***Exception:   0.87 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified core/libs/prx/libkernel_sys/Export.Discovery.cpp:693-700 handles unknown pids by setting *__error_nid_postfix() = 3 and returning SCE_KERNEL_ERROR_ESRCH (0x80020003), matching console measurements on PS5 Pro fw 13.60.
    • Checked null pointer handling and order of operations: categoryType null check precedes pid check, returning EINVAL (0x80020016) first as required.
    • Verified GuestCopyOut_nid_no_patch is not called on the ESRCH path, preserving caller buffer memory as measured on console and verified in unit tests.
    • Verified technical debt documentation fragment in docs/dev/debt/changes/fix-libkernel-app-category-unknown-pid-esrch.md matches the technical debt specification and conventions.
    • Verified core/libs/tests/GuestKernelSysAppCategory.cpp tests both negative and positive unused pids (999999), checking return code 0x80020003, errno 3, and unchanged output.
    • Checked MarcZX10's non-blocking review comment regarding GuestKernelSysNeoMode.cpp; verified the change in this PR is self-contained and passes all mechanical checks and test suites.

Looks Good To Me

@relativespace2K

Copy link
Copy Markdown
Contributor

@olegon85 Windows check on head 4cee54385d7, since the reported runs are console + Linux.

  • Machine: Windows 11 IoT Enterprise LTSC 10.0.26100, Ryzen 5 5600, WinLibs GCC 15.2.0 (UCRT, POSIX threads), Release with -DBUILD_TESTING=ON.
  • guest_kernel_sys_app_category_tests built cleanly; ctest -R "^guest_kernel_sys_app_category$" passed in 0.08 s.
  • Pid 0/self, the null output, and the unused-pid cases (0x80020003, errno 3, output untouched) pass on Windows.
  • Negative control: reverted only core/libs/prx/libkernel_sys/Export.Discovery.cpp, rebuilt, and the test aborts with what(): sceKernelGetAppCategoryType not implemented (the old body is a throwing stub); restoring the change passes again. Working tree clean.

AI-assisted: yes

@olegon85

Copy link
Copy Markdown
Contributor Author

Thank you - Windows verification with a negative control on top of console + Linux is exactly the coverage these posix-forwarding changes needed. Recorded; nothing to change on our side.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 4cee54385d, applied with git apply on main fd4aeed483 together with the other 27 PRs of one batch (#11049, #20072, #20406, #22100, #22892, #23774, #24199, #24495, #15314, #21180, #21221, #21486, #22597, #22839, #22895, #23550, #14573, #16873, #17113, #17879, #19183, #20057, #22066, #22219, #22781, #22958, #24478).

This PR makes guest_kernel_sys_neo_mode fail. The test passes on main and fails in the batch tree, in the full run and alone (ctest -R, 3 of 3 runs). In the batch tree, with this PR reverted the test passes, and with it applied again it fails again. I did not look for the cause inside the change.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. NVIDIA GeForce RTX 3080 (driver 621.24). No validation layer.

AI-assisted: yes (Claude Code)

This was referenced Nov 21, 2026
@olegon85
olegon85 force-pushed the fix/libkernel-app-category-unknown-pid-esrch branch from 4cee543 to 3173859 Compare November 22, 2026 02:56
@olegon85 olegon85 changed the title fix(libkernel_sys): answer ESRCH for unused pids in sceKernelGetAppCategoryType fix(libkernel): answer ESRCH for unused pids in sceKernelGetAppCategoryType Nov 22, 2026
@github-actions github-actions Bot added libkernel and removed needs rebase Conflicts with main, rebase needed labels Nov 22, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The changed code and tests are internally consistent, but the reported test runs were not independently verified in this review.

What I ran

Reviewed head 317385923507967ce09759b223cbb7b883deb3d2. Read the prepared description, commits, manifest, diff, and all four changed files listed as reviewed. No test or build command was run; the review tools provided source reading only.

Results

Check Result Note
Changed lines reviewed passed All four changed files read
Reported server tests not run Results are author-reported
Reported console probe not run Results are author-reported

Negative control

Not run; no test execution was available in this review.

Findings

Blocking

None found in the changed code reviewed.

Non-blocking

None.

Sources

Reviewed core/libs/prx/libkernel/SysExports.cpp, core/libs/tests/GuestKernelSysAppCategory.cpp, core/libs/tests/GuestKernelSysNeoMode.cpp, and docs/dev/debt/changes/fix-libkernel-app-category-unknown-pid-esrch.md at the pinned head.

Not verified

The author-reported PS5 Pro measurements and Linux ctest results were not independently reproduced. No build or runtime checks were run.

To get this to a good state

Nothing is required.

@ycbuzi

ycbuzi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 3173859235 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 4 tests failed out of 6680; 99% tests passed, 2 tests failed out of 6680. 2 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 6680; 100% tests passed, 0 tests failed out of 6680. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@oneandonlydean
oneandonlydean merged commit ba57430 into boykopovar:main Nov 25, 2026
14 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants