Skip to content

fix(libkernel_sys): accept title workaround bits up to 0x7f - #24656

Closed
olegon85 wants to merge 1 commit into
boykopovar:mainfrom
olegon85:fix/libkernel-title-workaround-bit-limit
Closed

olegon85 wants to merge 1 commit into
boykopovar:mainfrom
olegon85:fix/libkernel-title-workaround-bit-limit

Conversation

@olegon85

Copy link
Copy Markdown
Contributor

What

QueryTitleWorkaround refused any bit above 0x78 with SCE_KERNEL_ERROR_EINVAL. A payload process on a PS5 Pro (firmware 13.60) accepted bits 0 to 0x7F inclusive - 0x79, 0x7a, 0x7d and 0x7f all returned 0 with the output written - and refused only 0x80, 0x81 and -1 unsigned, so the accepted range is 0 to 0x7F and the limit was off by seven. The same probe confirmed on the console the parts of the entry that were disassembly-only: null workaround and output pointers return SCE_KERNEL_ERROR_EFAULT (0x8002000e) before the bit check, the misspelled sceKernelTitleWorkdaroundIsEnabled resolves to the same code, and sceKernelTitleWorkaroundIsEnabled2 accepts selectors 0 and 0x28 while refusing 0x29, 0x2A and ~0ull.

A second probe located the bit storage: setting one 64-bit word at a time in a buffer lit bits 0-63 only from offset 8 and bits 64-0x7F only from offset 16, no other word had any effect, and zeroing the version field changed nothing. The {version, align, ids[2]} layout is therefore confirmed, closing the "where title_workaround sits is unmeasured" clause; IsEnabled2 reads the same words. The debt entries now state measured facts, and the tests pin 0x79 and 0x7E as clear and 0x7F as set (the fixture already sets bit 63 of the second word).

Probe sources and raw session output are in the first comment. Measurement context: kernel_get_fw_version = 0x13600007, payload process loaded over elfldr (port 9021), sessions 2026-11-20T21:12Z and 21:30 UTC; a title process was not measured.

Tested

  • Console: probes tw1 and tw2, one flushed STEP line before every call, both exited by themselves; the libkernel_sys part of tw1 is quoted in full in the first comment.
  • Server (Linux): guest_kernel_sys family - 66/66 tests passed with the change on 01ac7c81be.
  • python3 tools/check_conventions.py --base origin/main: passed. git diff --check: clean. python3 tools/pr_overlap.py --branch fix/libkernel-title-workaround-bit-limit: exit 0; it lists ten open PRs sharing these files without comparison, and each patch was then grepped - none touches the title workaround code, its tests or its debt entries (PR 18190 only renames _nid_postfix call sites a few lines away).

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. Sessions 2026-11-20T21:12:08Z and 2026-11-20T21:30:17Z UTC. Every call is preceded by a flushed STEP line, so a crash would name exactly one export; both probes exited by themselves.

Probe tw1, libkernel_sys part (the same session also swept libSceOpusDec and reported it separately):

TW1|FW|0x13600007
TW1|STEP|dlopen-libkernel_sys
TW1|LK|88046ae20|ok
TW1|SYM|E=806596e10 E2=806596e50 EM=806596dd0 GC=80658aa30
TW1|STEP|A1-E-buf-bit0
TW1|A1_E_0|rc=0x0|val=0x0
TW1|STEP|A2-E-null-wa
TW1|A2_E_nullwa|rc=0x8002000e|val=0xffffffffaaaaaaaa
TW1|STEP|A3-E-null-out
TW1|A3_E_nullout|rc=0x8002000e
TW1|STEP|B-3f
TW1|B-3f|rc=0x0|val=0x0
TW1|STEP|B-40
TW1|B-40|rc=0x0|val=0x0
TW1|STEP|B-77
TW1|B-77|rc=0x0|val=0x0
TW1|STEP|B-78
TW1|B-78|rc=0x0|val=0x0
TW1|STEP|B-79
TW1|B-79|rc=0x0|val=0x0
TW1|STEP|B-7a
TW1|B-7a|rc=0x0|val=0x0
TW1|STEP|B-7d
TW1|B-7d|rc=0x0|val=0x0
TW1|STEP|B-7f
TW1|B-7f|rc=0x0|val=0x0
TW1|STEP|B-80
TW1|B-80|rc=0x80020016|val=0xffffffffaaaaaaaa
TW1|STEP|B-81
TW1|B-81|rc=0x80020016|val=0xffffffffaaaaaaaa
TW1|STEP|B-neg
TW1|B-neg|rc=0x80020016|val=0xffffffffaaaaaaaa
TW1|STEP|S-0
TW1|S-0|rc=0x0|val=0x0
TW1|STEP|S-28
TW1|S-28|rc=0x0|val=0x0
TW1|STEP|S-29
TW1|S-29|rc=0x80020016|val=0xffffffffaaaaaaaa
TW1|STEP|S-2a
TW1|S-2a|rc=0x80020016|val=0xffffffffaaaaaaaa
TW1|STEP|S-ffffffffffffffff
TW1|S-ffffffffffffffff|rc=0x80020016|val=0xffffffffaaaaaaaa
TW1|STEP|S1-bit7f
TW1|S1_bit7f|rc=0x0|val=0x0
TW1|STEP|S2-bit80
TW1|S2_bit80|rc=0x80020016|val=0xffffffffaaaaaaaa
TW1|STEP|S3-nullwa
TW1|S3_nullwa|rc=0x8002000e|val=0xffffffffaaaaaaaa
TW1|STEP|S4-nullout
TW1|S4_nullout|rc=0x8002000e
TW1|STEP|M1-alias-bit78
TW1|M1_78|rc=0x0|val=0x0
TW1|STEP|M2-alias-bit7a
TW1|M2_7a|rc=0x0|val=0x0
TW1|STEP|G1-cpumode
TW1|G1_cpumode|rc=0x0|val=0x0

Bits 0x3f, 0x40, 0x77, 0x78, 0x79, 0x7a, 0x7d and 0x7f all returned rc=0 with the output written (val=0, from a zeroed buffer); 0x80, 0x81 and -1 returned 0x80020016 leaving the sentinel untouched. The misspelled alias resolved and answered bit 0x7a with success. sceKernelTitleWorkaroundIsEnabled2 accepted selectors 0 and 0x28, refused 0x29, 0x2A and ~0ull with 0x80020016, shared the bit limit (0x7f ok, 0x80 refused) and checked null pointers first (0x8002000e).

Probe tw2 located where the bits live: one 64-bit word of a 0x80-byte buffer was set to all-ones at a time (offsets 0, 8, …, 80) and sampled bits were re-read; only offset 8 moved bits 0-63 and only offset 16 moved bits 64-0x7F, the zeroed control read 0, an all-ones buffer read 1 everywhere including via IsEnabled2 selector 0, and zeroing the version byte changed nothing. Raw output (W<word>|<bit>|<enabled>):

TW2|FW|0x13600007
TW2|SYM|lk=8807e2e20 E=8050dee10 E2=8050dee50
TW2|ALLFF|0|1
TW2|ALLFF|8|1
TW2|ALLFF|16|1
TW2|ALLFF|24|1
TW2|ALLFF|32|1
TW2|ALLFF|40|1
TW2|ALLFF|48|1
TW2|ALLFF|56|1
TW2|ALLFF|64|1
TW2|ALLFF|72|1
TW2|ALLFF|80|1
TW2|ALLFF|88|1
TW2|ALLFF|96|1
TW2|ALLFF|104|1
TW2|ALLFF|112|1
TW2|ALLFF|120|1
TW2|W0|0|0
TW2|W0|1|0
TW2|W0|7|0
TW2|W0|8|0
TW2|W0|31|0
TW2|W0|32|0
TW2|W0|63|0
TW2|W0|64|0
TW2|W0|79|0
TW2|W0|95|0
TW2|W0|111|0
TW2|W0|120|0
TW2|W0|127|0
TW2|W1|0|1
TW2|W1|1|1
TW2|W1|7|1
TW2|W1|8|1
TW2|W1|31|1
TW2|W1|32|1
TW2|W1|63|1
TW2|W1|64|0
TW2|W1|79|0
TW2|W1|95|0
TW2|W1|111|0
TW2|W1|120|0
TW2|W1|127|0
TW2|W2|0|0
TW2|W2|1|0
TW2|W2|7|0
TW2|W2|8|0
TW2|W2|31|0
TW2|W2|32|0
TW2|W2|63|0
TW2|W2|64|1
TW2|W2|79|1
TW2|W2|95|1
TW2|W2|111|1
TW2|W2|120|1
TW2|W2|127|1
TW2|W3|0|0
TW2|W3|1|0
TW2|W3|7|0
TW2|W3|8|0
TW2|W3|31|0
TW2|W3|32|0
TW2|W3|63|0
TW2|W3|64|0
TW2|W3|79|0
TW2|W3|95|0
TW2|W3|111|0
TW2|W3|120|0
TW2|W3|127|0
TW2|W4|0|0
TW2|W4|1|0
TW2|W4|7|0
TW2|W4|8|0
TW2|W4|31|0
TW2|W4|32|0
TW2|W4|63|0
TW2|W4|64|0
TW2|W4|79|0
TW2|W4|95|0
TW2|W4|111|0
TW2|W4|120|0
TW2|W4|127|0
TW2|W5|0|0
TW2|W5|1|0
TW2|W5|7|0
TW2|W5|8|0
TW2|W5|31|0
TW2|W5|32|0
TW2|W5|63|0
TW2|W5|64|0
TW2|W5|79|0
TW2|W5|95|0
TW2|W5|111|0
TW2|W5|120|0
TW2|W5|127|0
TW2|W6|0|0
TW2|W6|1|0
TW2|W6|7|0
TW2|W6|8|0
TW2|W6|31|0
TW2|W6|32|0
TW2|W6|63|0
TW2|W6|64|0
TW2|W6|79|0
TW2|W6|95|0
TW2|W6|111|0
TW2|W6|120|0
TW2|W6|127|0
TW2|W7|0|0
TW2|W7|1|0
TW2|W7|7|0
TW2|W7|8|0
TW2|W7|31|0
TW2|W7|32|0
TW2|W7|63|0
TW2|W7|64|0
TW2|W7|79|0
TW2|W7|95|0
TW2|W7|111|0
TW2|W7|120|0
TW2|W7|127|0
TW2|W8|0|0
TW2|W8|1|0
TW2|W8|7|0
TW2|W8|8|0
TW2|W8|31|0
TW2|W8|32|0
TW2|W8|63|0
TW2|W8|64|0
TW2|W8|79|0
TW2|W8|95|0
TW2|W8|111|0
TW2|W8|120|0
TW2|W8|127|0
TW2|W9|0|0
TW2|W9|1|0
TW2|W9|7|0
TW2|W9|8|0
TW2|W9|31|0
TW2|W9|32|0
TW2|W9|63|0
TW2|W9|64|0
TW2|W9|79|0
TW2|W9|95|0
TW2|W9|111|0
TW2|W9|120|0
TW2|W9|127|0
TW2|W10|0|0
TW2|W10|1|0
TW2|W10|7|0
TW2|W10|8|0
TW2|W10|31|0
TW2|W10|32|0
TW2|W10|63|0
TW2|W10|64|0
TW2|W10|79|0
TW2|W10|95|0
TW2|W10|111|0
TW2|W10|120|0
TW2|W10|127|0
TW2|ZERO78|0
TW2|E2FF|rc=0x0|out=1
TW2|VER0|1
TW2|DONE

Probe sources:

tw1/main.c
#include <ps5/kernel.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

typedef int (*EnabledFn)(const void* workaround, int32_t bit, int32_t* out);
typedef int (*Enabled2Fn)(const void* workaround, uint64_t selector, uint32_t bit, int32_t* out);
typedef int (*OutIntFn)(int32_t* out);
typedef int (*ArkFn)(int32_t a, int32_t b, int32_t c);
typedef int (*StateOutFn)(const void* state, uint32_t* out);
typedef int (*CtxFn)(uint32_t* ctx);
typedef int (*FiveFn)(void* s, const void* src, uint32_t len, void* dst, int32_t n);
typedef int (*SixFn)(void* s, const void* src, uint32_t len, void* dst, int32_t n, int32_t prio);
typedef int (*OnePtrFn)(void* p);

static unsigned char g_buf[0x200];

#define SENT 0xAAAAAAAAu

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

static int32_t g_out;

static void show_int(const char* id, int rc, long long extra, int has_extra) {
    if (has_extra) {
        printf("TW1|%s|rc=0x%x|val=0x%llx\n", id, (unsigned)rc, (unsigned long long)extra);
    } else {
        printf("TW1|%s|rc=0x%x\n", id, (unsigned)rc);
    }
    fflush(stdout);
}

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

    step("dlopen-libkernel_sys");
    void* lk = dlopen("libkernel_sys.sprx", RTLD_LAZY);
    printf("TW1|LK|%p|%s\n", lk, lk ? "ok" : dlerror());
    fflush(stdout);

    EnabledFn E = 0;
    Enabled2Fn E2 = 0;
    EnabledFn EM = 0;
    OutIntFn GC = 0;
    if (lk) {
        E = (EnabledFn)dlsym(lk, "sceKernelTitleWorkaroundIsEnabled");
        E2 = (Enabled2Fn)dlsym(lk, "sceKernelTitleWorkaroundIsEnabled2");
        EM = (EnabledFn)dlsym(lk, "sceKernelTitleWorkdaroundIsEnabled");
        GC = (OutIntFn)dlsym(lk, "sceKernelGetCpumodeGame");
        printf("TW1|SYM|E=%p E2=%p EM=%p GC=%p\n", (void*)E, (void*)E2, (void*)EM, (void*)GC);
        fflush(stdout);
    }

    if (E) {
        int rc;
        step("A1-E-buf-bit0");
        g_out = (int32_t)SENT;
        rc = E(g_buf, 0, &g_out);
        show_int("A1_E_0", rc, g_out, 1);
        step("A2-E-null-wa");
        g_out = (int32_t)SENT; rc = E(0, 0, &g_out); show_int("A2_E_nullwa", rc, g_out, 1);
        step("A3-E-null-out");
        rc = E(g_buf, 0, 0); show_int("A3_E_nullout", rc, 0, 0);
        static const int32_t bits[] = {0x3f, 0x40, 0x77, 0x78, 0x79, 0x7a, 0x7d, 0x7f, 0x80, 0x81};
        for (unsigned i = 0; i < sizeof(bits) / sizeof(bits[0]); ++i) {
            char id[32];
            snprintf(id, sizeof(id), "B-%02x", (unsigned)bits[i]);
            step(id);
            g_out = (int32_t)SENT;
            rc = E(g_buf, bits[i], &g_out);
            show_int(id, rc, g_out, 1);
        }
        step("B-neg");
        g_out = (int32_t)SENT;
        rc = E(g_buf, -1, &g_out);
        show_int("B-neg", rc, g_out, 1);
    }

    if (E2) {
        int rc;
        static const uint64_t sels[] = {0, 0x28, 0x29, 0x2a, 0xffffffffffffffffull};
        for (unsigned i = 0; i < sizeof(sels) / sizeof(sels[0]); ++i) {
            char id[32];
            snprintf(id, sizeof(id), "S-%llx", (unsigned long long)sels[i]);
            step(id);
            g_out = (int32_t)SENT;
            rc = E2(g_buf, sels[i], 0, &g_out);
            show_int(id, rc, g_out, 1);
        }
        step("S1-bit7f");
        g_out = (int32_t)SENT;
        rc = E2(g_buf, 1, 0x7f, &g_out);
        show_int("S1_bit7f", rc, g_out, 1);
        step("S2-bit80");
        g_out = (int32_t)SENT;
        rc = E2(g_buf, 0, 0x80, &g_out);
        show_int("S2_bit80", rc, g_out, 1);
        step("S3-nullwa");
        g_out = (int32_t)SENT;
        rc = E2(0, 0, 0, &g_out);
        show_int("S3_nullwa", rc, g_out, 1);
        step("S4-nullout");
        rc = E2(g_buf, 0, 0, 0);
        show_int("S4_nullout", rc, 0, 0);
    }

    if (EM) {
        int rc;
        step("M1-alias-bit78");
        g_out = (int32_t)SENT;
        rc = EM(g_buf, 0x78, &g_out);
        show_int("M1_78", rc, g_out, 1);
        step("M2-alias-bit7a");
        g_out = (int32_t)SENT;
        rc = EM(g_buf, 0x7a, &g_out);
        show_int("M2_7a", rc, g_out, 1);
    }

    if (GC) {
        int32_t mode = (int32_t)SENT;
        step("G1-cpumode");
        int rc = GC(&mode);
        show_int("G1_cpumode", rc, mode, 1);
    }

    step("dlopen-libSceOpusDec");
    void* od = dlopen("libSceOpusDec.sprx", RTLD_LAZY);
    printf("TW1|OD|%p|%s\n", od, od ? "ok" : dlerror());
    fflush(stdout);

    if (od) {
        ArkFn ARK = (ArkFn)dlsym(od, "ark0tPj4meI");
        StateOutFn AJM = (StateOutFn)dlsym(od, "sceOpusDecGetAjmContext");
        StateOutFn GMZ = (StateOutFn)dlsym(od, "gMazl3u8Y40");
        CtxFn JXV = (CtxFn)dlsym(od, "jXVNwfmd1II");
        FiveFn CT4 = (FiveFn)dlsym(od, "ct42RpB2CaM");
        SixFn EJQ = (SixFn)dlsym(od, "eJQx7Emrwb0");
        SixFn ZBX = (SixFn)dlsym(od, "ZBx02KtHz2Y");
        OnePtrFn LFT = (OnePtrFn)dlsym(od, "lFTdHt-AuKU");
        printf("TW1|SYM2|ARK=%p AJM=%p GMZ=%p JXV=%p CT4=%p EJQ=%p ZBX=%p LFT=%p\n",
               (void*)ARK, (void*)AJM, (void*)GMZ, (void*)JXV,
               (void*)CT4, (void*)EJQ, (void*)ZBX, (void*)LFT);
        fflush(stdout);

        if (ARK) {
            struct T { int32_t a, b, c; };
            static const struct T trips[] = {
                {1,1,1},{0,1,1},{13,1,1},{-1,1,1},{1,0,1},{1,13,1},{1,-1,1},
                {1,1,2},{1,1,-1},{12,1,0},{1,12,0},{1,12,1},{1,6,6},{1,7,6}
            };
            for (unsigned i = 0; i < sizeof(trips) / sizeof(trips[0]); ++i) {
                char id[32];
                snprintf(id, sizeof(id), "K-%u-%d-%d-%d", i, trips[i].a, trips[i].b, trips[i].c);
                step(id);
                int rc = ARK(trips[i].a, trips[i].b, trips[i].c);
                show_int(id, rc, 0, 0);
            }
        }

        if (AJM) {
            step("N1-ajm-nullnull");
            int rc = AJM(0, 0);
            show_int("N1_ajm_nn", rc, 0, 0);
            step("N2-ajm-bufnull");
            rc = AJM(g_buf, 0);
            show_int("N2_ajm_bn", rc, 0, 0);
        }
        if (GMZ) {
            step("O1-gmz-nullnull");
            int rc = GMZ(0, 0);
            show_int("O1_gmz_nn", rc, 0, 0);
            step("O2-gmz-bufnull");
            rc = GMZ(g_buf, 0);
            show_int("O2_gmz_bn", rc, 0, 0);
        }
        if (JXV) {
            step("P1-jxv-null");
            int rc = JXV(0);
            show_int("P1_jxv_null", rc, 0, 0);
        }
        if (CT4) {
            step("Q1-ct4-null");
            int rc = CT4(0, g_buf, 1, g_buf, 1);
            show_int("Q1_ct4_null", rc, 0, 0);
            step("Q2-ct4-nullsrc");
            rc = CT4(g_buf, 0, 1, g_buf, 1);
            show_int("Q2_ct4_nsrc", rc, 0, 0);
            step("Q3-ct4-biglen");
            rc = CT4(g_buf, g_buf, 0x1f4c, g_buf, 1);
            show_int("Q3_ct4_big", rc, 0, 0);
            step("Q4-ct4-nulldst");
            rc = CT4(g_buf, g_buf, 1, 0, 1);
            show_int("Q4_ct4_ndst", rc, 0, 0);
            step("Q5-ct4-zeroN");
            rc = CT4(g_buf, g_buf, 1, g_buf, 0);
            show_int("Q5_ct4_zn", rc, 0, 0);
        }
        if (EJQ) {
            step("R1-ejq-null");
            int rc = EJQ(0, g_buf, 1, g_buf, 1, 50);
            show_int("R1_ejq_null", rc, 0, 0);
            step("R2-ejq-prio19");
            rc = EJQ(g_buf, g_buf, 1, g_buf, 1, 19);
            show_int("R2_ejq_p19", rc, 0, 0);
            step("R3-ejq-prio101");
            rc = EJQ(g_buf, g_buf, 1, g_buf, 1, 101);
            show_int("R3_ejq_p101", rc, 0, 0);
        }
        if (ZBX) {
            step("T1-zbx-null");
            int rc = ZBX(0, g_buf, 1, g_buf, 1, 50);
            show_int("T1_zbx_null", rc, 0, 0);
            step("T2-zbx-prio19");
            rc = ZBX(g_buf, g_buf, 1, g_buf, 1, 19);
            show_int("T2_zbx_p19", rc, 0, 0);
        }

        step("LAST-ct4-allpass");
        if (CT4) {
            int rc = CT4(g_buf, g_buf, 1, g_buf, 1);
            show_int("U1_ct4_pass", rc, 0, 0);
        }
        step("LAST-ejq-allpass");
        if (EJQ) {
            int rc = EJQ(g_buf, g_buf, 1, g_buf, 1, 50);
            show_int("U2_ejq_pass", rc, 0, 0);
        }
        step("LAST-zbx-allpass");
        if (ZBX) {
            int rc = ZBX(g_buf, g_buf, 1, g_buf, 1, 50);
            show_int("U3_zbx_pass", rc, 0, 0);
        }
        step("LAST-lft-buf");
        if (LFT) {
            int rc = LFT(g_buf);
            show_int("U4_lft_buf", rc, 0, 0);
        }
    }

    printf("TW1|DONE\n");
    fflush(stdout);
    return 0;
}
tw2/main.c
#include <ps5/kernel.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

typedef int (*EnabledFn)(const void* workaround, int32_t bit, int32_t* out);
typedef int (*Enabled2Fn)(const void* workaround, uint64_t selector, uint32_t bit, int32_t* out);

static unsigned char g_buf[0x80] __attribute__((aligned(8)));

static EnabledFn E;
static Enabled2Fn E2;

static int query(int32_t bit) {
    int32_t out = -1;
    int rc = E(g_buf, bit, &out);
    if (rc != 0) return -1;
    return out;
}

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

    void* lk = dlopen("libkernel_sys.sprx", RTLD_LAZY);
    E = (EnabledFn)dlsym(lk, "sceKernelTitleWorkaroundIsEnabled");
    E2 = (Enabled2Fn)dlsym(lk, "sceKernelTitleWorkaroundIsEnabled2");
    printf("TW2|SYM|lk=%p E=%p E2=%p\n", lk, (void*)E, (void*)E2);
    fflush(stdout);

    memset(g_buf, 0xFF, sizeof(g_buf));
    for (int32_t bit = 0; bit <= 0x7F; bit += 8) {
        printf("TW2|ALLFF|%d|%d\n", (int)bit, query(bit));
        fflush(stdout);
    }

    static const int32_t SAMPLES[] = {0, 1, 7, 8, 31, 32, 63, 64, 79, 95, 111, 120, 127};
    for (unsigned w = 0; w < 11; ++w) {
        printf("TW2|STEP|word%u\n", w);
        fflush(stdout);
        memset(g_buf, 0, sizeof(g_buf));
        uint64_t word = ~(uint64_t)0;
        memcpy(g_buf + w * 8, &word, 8);
        for (unsigned s = 0; s < sizeof(SAMPLES) / sizeof(SAMPLES[0]); ++s) {
            printf("TW2|W%u|%d|%d\n", w, (int)SAMPLES[s], query(SAMPLES[s]));
            fflush(stdout);
        }
    }

    memset(g_buf, 0, sizeof(g_buf));
    printf("TW2|ZERO78|%d\n", query(0x78));
    fflush(stdout);

    memset(g_buf, 0xFF, sizeof(g_buf));
    int32_t out = -1;
    int rc = E2(g_buf, 0, 0x78, &out);
    printf("TW2|E2FF|rc=0x%x|out=%d\n", (unsigned)rc, out);
    fflush(stdout);

    memset(g_buf, 0xFF, sizeof(g_buf));
    g_buf[0] = 0;
    printf("TW2|VER0|%d\n", query(0));
    fflush(stdout);

    printf("TW2|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 reviewed implementation and boundary tests match the stated 0–0x7F range.

What I ran

Read the prepared diff and the changed implementation, tests, and debt entries at head 3bf4c2b1d9ae60411b468bc1058b77391e2b95d1. No commands or tests were run. The author reports 66/66 server tests and convention checks passed.

Results

Check Result Note
Source review passed Changed behavior and callers inspected
Tests not run Author reports 66/66 passed
Negative control not run No assertion change run

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently, and the reported console probes and test results were not independently verified. All three changed files were read: core/libs/prx/libkernel_sys/Export.cpp, core/libs/tests/GuestKernelSys.cpp, and docs/dev/debt/libkernel_sys.md. No files were excluded in the manifest.

To get this to a good state

Nothing is required.

@kiwe147

kiwe147 commented Nov 20, 2026

Copy link
Copy Markdown

Tested head 3bf4c2b1d9, applied with git apply on main fd4aeed483 together with the other sixteen PRs of one batch (#24596, #24594, #24595, #24599, #24600, #24602, #24593, #24659, #24651, #24626, #24625, #24624, #24456, #22380, #24502, #24351). All seventeen applied without conflicts. The tree built except libSceAjm.prx: #24659 breaks it with duplicate patched export name: -qLsfDAywIY (checked alone on main, reported there). No other target failed to build.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_kernel_sys (1 test) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6524 tests) on the RTX 3080 has 4 failures, and all 4 also fail on main fd4aeed483 (agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10). The 2125 agc_/video tests on the iGPU fail agc_driver_stencil_plane_memory (also on main), agc_driver_store_over_untracked (also fails alone on main on this iGPU, 6 of 6) and agc_driver_image_table_packed_guards (passes 5 of 5 alone on this tree, known flaky). None of this batch touches AGC.

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@olegon85

Copy link
Copy Markdown
Contributor Author

Closing this myself after a collision check found the change conflicts with merged work.

docs/dev/debt/changes/fix-kernel-sys-title-workaround-bit-limit.md (pending fold, from the #22365 line of work) records a payload-process measurement on firmware 11.60: bits 0 to 0x78 accepted, 0x79 to 0x7F refused - which is why > 0x78 is in QueryTitleWorkaround deliberately. My probe (see the evidence comment, sessions 2026-11-20T21:12Z/21:30Z, PS5 Pro firmware 13.60) accepted everything through 0x7F and refused only 0x80/-1. So the limit is firmware-dependent (wider on newer kernels), not a disassembly misreading, and debt_fold.py --check refuses my fragment against the pending one on the same two entries.

Data kept here for whoever folds next:

  • 13.60: accepted {0x00,0x3f,0x40,0x77,0x78,0x79,0x7a,0x7d,0x7f} all rc 0 with output written; refused {0x80,0x81,-1} 0x80020016 without writing; alias export identical; IsEnabled2 same limit, selectors 0/0x28 ok and ≥0x29 refused unsigned, null checks first.
  • Layout (tw2): setting one 64-bit word at a time lit bits 0-63 only from offset 8 and bits 64-0x7F only from offset 16; no other word of the buffer had any effect; zeroing the version field changed nothing - the {version, align, ids[2]} reading is confirmed on-console at 13.60 (the "where title_workaround sits" clause can close).

If a follow-up wants the newest-kernel behavior it needs a firmware-conditional limit with a boundary nobody has measured yet (somewhere in 12.x/13.x); I would rather see the pending 11.60 entry folded first and this documented as a version divergence. Apologies for the overlap - my due diligence checked open PRs, not pending fragments.

@olegon85

Copy link
Copy Markdown
Contributor Author

Closing as superseded by the pending #22365-line fragment; version-divergence data preserved in my previous comment.

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.

3 participants