Repository navigation
docs(debt): record the development mode and GetKqueueFromEqueue results on firmware 11.60 - #22821
Conversation
…ts on firmware 11.60 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe source (built with ps5-payload-sdk v0.45; probe.c/* __sys_namedobj_create, __sys_namedobj_delete, __sys_is_development_mode and sceKernelGetKqueueFromEqueue, payload process, firmware 11.60 (debt
libkernel_sys.md entries: __sys_namedobj_create is not measured on a console, it fails with EAGAIN once ids 1 to 65535 are live, released ids are reused
lowest first (RPCSX), the name fails with EINVAL when null, ENAMETOOLONG from 32 characters and EFAULT when unreadable; __sys_namedobj_delete: deleting a
live id with another type than it was created with throws in AnyPS5 (fpPS4 answers ESRCH, RPCSX deletes it), both compare the low 16 bits of the type and
answer ESRCH for an id that is not live; __sys_is_development_mode fixes development mode to disabled (0), console return values and nonzero mode bits
unmeasured; sceKernelGetKqueueFromEqueue writes the descriptor with GuestCopyOut, an unwritable kq returns EINVAL like a null one, console behaviour on
unmapped memory unmeasured). Prototypes from the repo: int __sys_namedobj_create(const char* name, void* object, uint32_t type) returning an id above
0 or -1 with errno, int __sys_namedobj_delete(uint32_t id, uint32_t type), uint64_t __sys_is_development_mode(void), int
sceKernelGetKqueueFromEqueue(void* eq, int* kq), sceKernelCreateEqueue(void** eq, const char* name), sceKernelDeleteEqueue(void* eq). The names are looked up with
dlsym in libkernel.sprx, then in the global scope; a missing export is the result for its cases. The 65535 limit is NOT measured and no sweep of many ids is
made: at most 6 ids are made. __sys_is_development_mode is called 100 times (are all results equal, the result as hex) and once with three bogus register
arguments through a differently typed pointer. Namedobj cases: create "n2_17_a" and "n2_17_b" with type 1 (the ids, whether the second is the first plus one), delete
the first, create "n2_17_c" (is the lowest id reused), delete the second with the type 2 (return code and errno, whether it was deleted: a following delete with type 1
answers), delete of id 0, 0x7fffffff and a never used id, the type compare of the low 16 bits (create with type 1, delete with type 0x10001), the name empty, of 31, 32
and 255 characters (return code and errno), then single guarded calls with the name NULL and 0x1. Every id made is deleted at the end. Equeue cases:
sceKernelCreateEqueue, sceKernelGetKqueueFromEqueue twice (the descriptor valid by fstat and fcntl F_GETFD, the same twice), the kq pointer NULL and 0x1, the eq pointer NULL and 0x1, and a
stale equeue after sceKernelDeleteEqueue; the pointer cases last, single calls, only while the previous one did not fault. A fault is caught by a guard (one hit
per case, more than eight end the probe with _exit(125)); a fault is a result. Nothing is written to a file, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h> /* only for kernel_get_fw_version() */
#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static volatile int g_handle = -1;
static int (*volatile g_setmargins)(int, int, int) = 0; /* unused here */
static void reset_rate(void) {
if (g_setmargins && g_handle >= 0) g_setmargins(g_handle, 0, 0);
}
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
reset_rate();
_exit(124);
}
/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
as a second safeguard. */
static void* probe_watchdog(void* arg) {
static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
unsigned left = PROBE_MAX_S;
(void)arg;
while (left) left = sleep(left);
(void)!write(1, msg, sizeof msg - 1);
reset_rate();
_exit(124);
return 0;
}
static void probe_watchdog_start(void) {
pthread_t t;
if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}
static int cases = 0;
static void probe_header(void) {
char utc[32];
time_t now = time(0);
probe_watchdog_start();
struct tm tmv;
gmtime_r(&now, &tmv);
strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
getpid(), utc);
fflush(stdout);
}
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
fflush(stdout);
cases++;
}
static void probe_end(void) {
printf("END\t%d\n", cases);
fflush(stdout);
}
#include <fcntl.h>
#include <setjmp.h>
#include <sys/stat.h>
typedef int (*fn_create)(const char*, void*, unsigned);
typedef int (*fn_delete)(unsigned, unsigned);
typedef unsigned long long (*fn_dev)(void);
typedef long (*fn_dev3)(long, long, long);
typedef int (*fn_getkq)(void*, int*);
typedef int (*fn_ceq)(void**, const char*);
typedef int (*fn_deq)(void*);
static sigjmp_buf guard_env;
static volatile int guard_sig = 0, guard_active = 0, guard_hits = 0;
static void guard_handler(int s) {
static const char msg[] = "FAULT\tguard\n";
guard_sig = s;
if (!guard_active || ++guard_hits > 8) { (void)!write(1, msg, sizeof msg - 1); _exit(125); }
guard_active = 0;
siglongjmp(guard_env, 1);
}
static int ids[8], idt[8], nid = 0;
int main(void) {
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = guard_handler;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
char extra[260], id[16], label[100];
errno = 0;
void* lk = dlopen("libkernel.sprx", RTLD_LAZY);
probe_case("0", "load libkernel.sprx", lk ? 0 : -1, errno, lk ? "loaded" : dlerror());
if (!lk) { probe_end(); return 0; }
fn_create f_cr = (fn_create)(dlsym(lk, "__sys_namedobj_create") ? dlsym(lk, "__sys_namedobj_create") : dlsym(RTLD_DEFAULT, "__sys_namedobj_create"));
fn_delete f_del = (fn_delete)(dlsym(lk, "__sys_namedobj_delete") ? dlsym(lk, "__sys_namedobj_delete") : dlsym(RTLD_DEFAULT, "__sys_namedobj_delete"));
fn_dev f_dev = (fn_dev)(dlsym(lk, "__sys_is_development_mode") ? dlsym(lk, "__sys_is_development_mode") : dlsym(RTLD_DEFAULT, "__sys_is_development_mode"));
fn_getkq f_kq = (fn_getkq)(dlsym(lk, "sceKernelGetKqueueFromEqueue") ? dlsym(lk, "sceKernelGetKqueueFromEqueue") : dlsym(RTLD_DEFAULT, "sceKernelGetKqueueFromEqueue"));
fn_ceq f_ceq = (fn_ceq)(dlsym(lk, "sceKernelCreateEqueue") ? dlsym(lk, "sceKernelCreateEqueue") : dlsym(RTLD_DEFAULT, "sceKernelCreateEqueue"));
fn_deq f_deq = (fn_deq)(dlsym(lk, "sceKernelDeleteEqueue") ? dlsym(lk, "sceKernelDeleteEqueue") : dlsym(RTLD_DEFAULT, "sceKernelDeleteEqueue"));
snprintf(extra, sizeof extra, "namedobj_create=%d namedobj_delete=%d is_development_mode=%d GetKqueueFromEqueue=%d CreateEqueue=%d DeleteEqueue=%d", f_cr != 0, f_del != 0,
f_dev != 0, f_kq != 0, f_ceq != 0, f_deq != 0);
probe_case("0b", "dlsym of the functions", 0, 0, extra);
/* b) development mode */
if (f_dev) {
unsigned long long first = f_dev();
int same = 1;
for (int i = 0; i < 99; ++i) if (f_dev() != first) same = 0;
fn_dev3 d3 = (fn_dev3)f_dev;
long bogus = d3(1, 2, 3);
snprintf(extra, sizeof extra, "value=0x%llx all_100_equal=%d with_bogus_arguments_equal=%d", first, same, (unsigned long long)bogus == first);
probe_case("1", "__sys_is_development_mode() x100 and with three bogus arguments", 0, 0, extra);
}
/* c) namedobj */
if (f_cr && f_del) {
int a, b, c, r, e;
errno = 0;
a = f_cr("n2_17_a", 0, 1);
e = errno;
if (a > 0) { ids[nid] = a; idt[nid++] = 1; }
snprintf(extra, sizeof extra, "id=%d errno=%d", a, a > 0 ? 0 : e);
probe_case("2.1", "__sys_namedobj_create(\"n2_17_a\", NULL, 1)", a, e, extra);
errno = 0;
b = f_cr("n2_17_b", 0, 1);
e = errno;
if (b > 0) { ids[nid] = b; idt[nid++] = 1; }
snprintf(extra, sizeof extra, "id=%d errno=%d second_is_first_plus_1=%d", b, b > 0 ? 0 : e, b == a + 1);
probe_case("2.2", "__sys_namedobj_create(\"n2_17_b\", NULL, 1)", b, e, extra);
errno = 0;
r = f_del(a, 1);
e = errno;
if (r == 0) for (int i = 0; i < nid; ++i) if (ids[i] == a) ids[i] = 0;
snprintf(extra, sizeof extra, "rc=%d errno=%d", r, e);
probe_case("2.3", "__sys_namedobj_delete(first id, 1)", r, e, extra);
errno = 0;
c = f_cr("n2_17_c", 0, 1);
e = errno;
if (c > 0) { ids[nid] = c; idt[nid++] = 1; }
snprintf(extra, sizeof extra, "id=%d errno=%d reused_lowest_id=%d", c, c > 0 ? 0 : e, c == a);
probe_case("2.4", "__sys_namedobj_create(\"n2_17_c\", NULL, 1) after deleting the first", c, e, extra);
errno = 0;
r = f_del(b, 2);
e = errno;
snprintf(extra, sizeof extra, "rc=%d errno=%d", r, e);
probe_case("2.5", "__sys_namedobj_delete(second id, type 2) wrong type", r, e, extra);
errno = 0;
int r2 = f_del(b, 1);
int e2 = errno;
if (r2 == 0) for (int i = 0; i < nid; ++i) if (ids[i] == b) ids[i] = 0;
snprintf(extra, sizeof extra, "rc=%d errno=%d (rc 0 means the wrong-type delete before did not remove it)", r2, e2);
probe_case("2.6", "__sys_namedobj_delete(second id, type 1) afterwards", r2, e2, extra);
errno = 0;
r = f_del(b, 1);
snprintf(extra, sizeof extra, "rc=%d errno=%d", r, errno);
probe_case("2.7", "__sys_namedobj_delete(second id, 1) again", r, errno, extra);
unsigned dids[3] = {0, 0x7fffffff, 60000};
for (int i = 0; i < 3; ++i) {
errno = 0;
r = f_del(dids[i], 1);
snprintf(id, sizeof id, "2.%d", 8 + i);
snprintf(label, sizeof label, "__sys_namedobj_delete(id %u, 1)", dids[i]);
snprintf(extra, sizeof extra, "rc=%d errno=%d", r, errno);
probe_case(id, label, r, errno, extra);
}
errno = 0;
int t = f_cr("n2_17_t", 0, 1);
e = errno;
if (t > 0) { ids[nid] = t; idt[nid++] = 1; }
errno = 0;
r = t > 0 ? f_del(t, 0x10001) : -1;
e = errno;
if (r == 0) for (int i = 0; i < nid; ++i) if (ids[i] == t) ids[i] = 0;
snprintf(extra, sizeof extra, "create_id=%d delete_rc=%d errno=%d (rc 0: the low 16 bits of the type are compared)", t, r, e);
probe_case("2.11", "create with type 1, delete with type 0x10001", r, e, extra);
/* d) names */
char nm[260];
int ln[4] = {0, 31, 32, 255};
for (int i = 0; i < 4; ++i) {
memset(nm, 'n', sizeof nm);
nm[ln[i]] = 0;
errno = 0;
int x = f_cr(nm, 0, 1);
e = errno;
if (x > 0) { ids[nid] = x; idt[nid++] = 1; }
snprintf(id, sizeof id, "3.%d", i + 1);
snprintf(label, sizeof label, "__sys_namedobj_create(name of %d characters, NULL, 1)", ln[i]);
snprintf(extra, sizeof extra, "id=%d errno=%d", x, x > 0 ? 0 : e);
probe_case(id, label, x, e, extra);
}
}
/* e) equeue */
void* eq = 0;
int have_eq = 0;
if (f_ceq && f_kq) {
errno = 0;
int r = f_ceq(&eq, "n2_17");
have_eq = r == 0 && eq != 0;
snprintf(extra, sizeof extra, "rc=0x%08x equeue_made=%d", (unsigned)r, have_eq);
probe_case("4.1", "sceKernelCreateEqueue", r, errno, extra);
}
if (have_eq) {
int k1 = -12345, k2 = -12345;
errno = 0;
int r = f_kq(eq, &k1);
int e = errno;
int r2 = f_kq(eq, &k2);
struct stat st;
int fs = k1 >= 0 ? fstat(k1, &st) : -1;
int fl = k1 >= 0 ? fcntl(k1, F_GETFD) : -1;
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d kq_ge_0=%d second_rc=0x%08x same_descriptor_twice=%d fstat_rc=%d F_GETFD=%d", (unsigned)r, e, k1 >= 0, (unsigned)r2, k1 == k2, fs, fl);
probe_case("4.2", "sceKernelGetKqueueFromEqueue(eq, &kq) twice", r, e, extra);
}
if (f_kq) {
struct { const char* tag; int kind; } pc[] = {{"kq NULL", 0}, {"kq 0x1", 1}, {"eq NULL", 2}, {"eq 0x1", 3}, {"stale eq after sceKernelDeleteEqueue", 4}};
int stopped = 0;
for (int i = 0; i < 5 && !stopped; ++i) {
if (pc[i].kind == 0 || pc[i].kind == 1) { if (!have_eq) continue; }
if (pc[i].kind == 4) {
if (!have_eq || !f_deq) continue;
f_deq(eq);
have_eq = 0;
}
int k = -12345;
guard_sig = 0;
int r = -1, e = 0;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
switch (pc[i].kind) {
case 0: r = f_kq(eq, 0); break;
case 1: r = f_kq(eq, (int*)0x1); break;
case 2: r = f_kq(0, &k); break;
case 3: r = f_kq((void*)0x1, &k); break;
default: r = f_kq(eq, &k); break;
}
e = errno;
guard_active = 0;
} else {
stopped = 1;
}
snprintf(id, sizeof id, "5.%d", i + 1);
snprintf(label, sizeof label, "sceKernelGetKqueueFromEqueue(%s)", pc[i].tag);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d fault_signal=%d", (unsigned)r, e, (int)guard_sig);
probe_case(id, label, r, e, extra);
}
if (stopped) probe_case("5.9", "pointer cases stopped after the first fault", 0, 0, "remaining pointer cases skipped by design");
}
if (have_eq && f_deq) f_deq(eq);
/* names NULL and 0x1, single guarded calls, last */
if (f_cr) {
int stopped = 0;
const char* tn[2] = {"NULL", "0x1"};
for (int i = 0; i < 2 && !stopped; ++i) {
guard_sig = 0;
int r = -1, e = 0;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = f_cr(i == 0 ? (const char*)0 : (const char*)0x1, 0, 1);
e = errno;
guard_active = 0;
if (r > 0) { ids[nid] = r; idt[nid++] = 1; }
} else {
stopped = 1;
}
snprintf(id, sizeof id, "6.%d", i + 1);
snprintf(label, sizeof label, "__sys_namedobj_create(name %s, NULL, 1)", tn[i]);
snprintf(extra, sizeof extra, "rc=%d errno=%d fault_signal=%d", r, e, (int)guard_sig);
probe_case(id, label, r, e, extra);
}
}
/* cleanup */
if (f_del) {
int removed = 0, tried = 0;
for (int i = 0; i < nid; ++i) {
if (ids[i] <= 0) continue;
tried++;
if (f_del((unsigned)ids[i], (unsigned)idt[i]) == 0) removed++;
}
snprintf(extra, sizeof extra, "ids_still_live_to_remove=%d removed=%d", tried, removed);
probe_case("9", "cleanup: __sys_namedobj_delete of every id still live", removed == tried ? 0 : -1, 0, extra);
}
probe_end();
return 0;
}stdoutAI-assisted (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The documentation fragment accurately records the stated firmware 11.60 observations and the existing host-safety behavior; the full changed file was read.
What I ran
Reviewed head 05a023a1196de28431e5f44e1497a9e71d07f094. Read the prepared description, commits, manifest, diff, README, the complete changed fragment, and the debt-fragment instructions in docs/dev/TechnicalDebt.md. No tests or commands were run.
Results
| Check | Result | Note |
|---|---|---|
| Changed lines read | passed | All 9 added lines |
| Documentation claims | not run | Firmware observations supplied by author |
| Automated checks | not run | No checks run during this review |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The console measurements, emulator behavior, and claimed convention-check result were not independently verified. No other repository files were read; files.json was not available in the prepared folder listing. The only changed file is included in the manifest and was read in full.
To get this to a good state
Nothing is required.
What
The
__sys_is_development_modeentry indocs/dev/debt/libkernel_sys.mdsays that AnyPS5 fixes development mode to disabled (0) and that "console return values and nonzero mode bits are unmeasured"; thesceKernelGetKqueueFromEqueueentry says that an unwritablekqreturnsEINVALhere as a host-safety fallback and that "console behaviour on unmapped memory is unmeasured". A probe has now called both inlibkernel.sprxfrom a payload process on firmware 11.60. The pull request replaces those two sentences through a debt fragment, as the contribution rules ask; no code changes. The probe also measured__sys_namedobj_createand__sys_namedobj_delete; those results are in a separate pull request.__sys_is_development_modereturned 0 in 100 calls and also 0 when called once with three bogus register arguments (case 1, line 4).sceKernelGetKqueueFromEqueueon an equeue made withsceKernelCreateEqueuereturned 0 and a descriptor that is valid forfstatand the same on a second call (cases 4.1 and 4.2, lines 20 and 21); with a nullkqit returned0x80020016(SCE_KERNEL_ERROR_EINVAL) witherrnountouched and no fault (5.1, line 22); with the pointer 0x1 the process raisedSIGSEGV(5.2, line 23), and the probe stopped its pointer cases there by design (line 24).AnyPS5 agrees on the first two:
__sys_is_development_modereturns 0 (libkernel_sys/AdditionalExports.cpp, lines 102 to 104, testGuestKernelSysDevelopmentMode, lines 20 to 22), andsceKernelGetKqueueFromEqueuereturnsSCE_KERNEL_ERROR_EINVALfor a nullkq(libkernel_sys/Export.Discovery.cpp, line 924; testGuestKernelSys, line 1109). It differs on an unwritable pointer: the console faults withSIGSEGV, and AnyPS5 returnsEINVALand keepserrno(lines 925 to 929; test lines 1111 and 1112). That difference stays: the entry already calls it a host-safety fallback, and a fault would be the emulation of a crash. This pull request records it and changes no behaviour. The emulator itself was not run for this pull request.Not measured: nonzero development mode bits (the payload ran with mode 0), which descriptor number the console returns for
kq(only that it is valid and stable), theeqpointer cases and a stale equeue (not run after the first fault), and a title process.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr) that loadslibkernel.sprxand takes the functions withdlsym(line 3 shows all six it uses were found), on 2026-11-18 at 07:06 UTC. A title process may differ. The cases for these two functions are 1, 4.1 to 5.2 (lines 4 and 20 to 24); the others in the raw output concern__sys_namedobj_createand__sys_namedobj_deleteand are not used here.main(code read, not run)__sys_is_development_mode()x100, and with bogus argumentssceKernelGetKqueueFromEqueue(eq, &kq)twicekqnull0x80020016,errnountouched (line 22)0x80020016kq0x1SIGSEGV(line 23)0x80020016,errnokepttools/check_conventions.py --base upstream/mainpasses with no error and no warning (the two entries are now 901 and 465 characters, up from 815 and 359). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against these calls, a title process, other firmware, and the cases listed above as not measured.Overlap: the other open pull requests that change the file of this branch (the fragment
docs/dev/debt/changes/docs-libkernel-sys-devmode-kq-console-1160.md, a new file),core/libs/prx/libkernel_sys/AdditionalExports.cpp,core/libs/prx/libkernel_sys/Export.Discovery.cpporcore/libs/tests/GuestKernelSys.cpp, which the entries and the text name, or the two debt entries__sys_is_development_modeandsceKernelGetKqueueFromEqueue, found by reading the changed files of all 1754 open pull requests at about 10:03 to 10:19 UTC, by reading what they change indocs/dev/debt/libkernel_sys.mdand the fragments underdocs/dev/debt/changes/for__sys_is_development_modeandsceKernelGetKqueueFromEqueue, and by searching their titles and branch names for the same names (one hit, #21989), were checked on 2026-11-18 at about 10:33 UTC againstmaincb8ce41f775together with this head; the branch is based onf8c535ab8c6, an ancestor of it, merges intomainwithout a conflict, andtools/debt_fold.py --checkapplies the changed fragment together with every other fragment onmainwithout an error. Twenty-five pull requests list one of the code files orlibkernel_sys.md, most of them for other functions or entries; as this branch adds only a fragment, none of them conflicts only with this change. #21989 moves the body of__sys_is_development_modeintoGuestIsDevelopmentMode_nid_no_patchinAdditionalExports.cpp(the line numbers cited here would change, not the value 0) and has a fragment for thelibkernel_webentries; #21726 (refuse a stale equeue handle) has a fragment that changes thelibkernelentry ofsceKernelCreateEqueue and sceKernelGetKqueueFromEqueue, not thelibkernel_sysentry of this branch; #15037 carries the__sys_is_development_modeentry as an unchanged context line. None of them changes a line of the two entries of this branch. The merged result was not built or run; this is a documentation change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)