Repository navigation
docs(debt): record the measured scePthreadAttrGet returns - #18325
Conversation
Null attribute, joined thread handle, calling thread and a running scePthreadCreate thread, measured on a PS5 payload process (firmware 11.60). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe source (built with ps5-payload-sdk v0.45; probe.c#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: on timeout the runner can only close the connection, not end the process on the console.
The probe ends itself after at most PROBE_MAX_S seconds (the build script sets timeout - 10 s). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
}
/* Watchdog thread: alarm()/SIGALRM does not help when the main thread cannot be scheduled (a CPU mask without a usable
core) or hangs in a blocking call. The thread is created before any mask is changed, 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);
_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);
}
/* CASE: id, description of the call, return value as long, errno (0 if not set), extra (hex/bytes). */
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);
}
/* Probe F: pthread_attr_get_np and scePthreadAttrGet for a running thread, a joined thread, an ended detached thread and a
null attribute on firmware 11.60 (the attribute is set up with scePthreadAttrInit and the Sce thread calls are used). Each call runs under a fault guard. The watchdog thread above ends the
process if a call hangs. Only the own threads of this probe are used; the attribute values are printed as raw numbers. */
#include <dlfcn.h>
#include <setjmp.h>
#include <sched.h>
static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static void guard_handler(int s) {
guard_sig = s;
siglongjmp(guard_env, 1);
}
typedef int (*attr_init_fn)(void*);
typedef int (*sce_attr_get_fn)(pthread_t, void*);
typedef int (*get_np_fn)(pthread_t, void*);
typedef int (*getstack_fn)(void*, size_t*);
static volatile int release_flag = 0;
static volatile int started = 0;
static void* worker(void* arg) {
(void)arg;
started = 1;
while(!release_flag) usleep(1000);
return 0;
}
static void* quick(void* arg) {
(void)arg;
started = 1;
return 0;
}
typedef int (*sce_init_fn)(void*);
typedef int (*sce_destroy_fn)(void*);
static unsigned char abuf[512];
static void gcase(const char* id, const char* call, sce_attr_get_fn sce, sce_init_fn init, sce_destroy_fn destroy, getstack_fn gs, pthread_t th, int null_attr) {
int r = -1, ri = -1, e;
size_t stack = 0;
char ex[100];
memset(abuf, 0, sizeof abuf);
void* attr = null_attr ? 0 : (void*)abuf;
errno = 0;
guard_sig = 0;
if(sigsetjmp(guard_env, 1) == 0) {
if(attr) ri = init(attr);
r = sce(th, attr);
if(r == 0 && attr && gs) gs(attr, &stack);
if(attr && destroy) destroy(attr);
}
e = errno;
snprintf(ex, sizeof ex, "init=%d stacksize=%zu signal=%d", ri, stack, (int)guard_sig);
probe_case(id, call, guard_sig ? -1 : r, e, ex);
}
typedef int (*sce_create_fn)(pthread_t*, const void*, void* (*)(void*), void*, const char*);
typedef int (*sce_join_fn)(pthread_t, void**);
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = guard_handler;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
sigaction(SIGABRT, &sa, 0);
sce_attr_get_fn sce = (sce_attr_get_fn)dlsym(RTLD_DEFAULT, "scePthreadAttrGet");
sce_init_fn init = (sce_init_fn)dlsym(RTLD_DEFAULT, "scePthreadAttrInit");
sce_destroy_fn destroy = (sce_destroy_fn)dlsym(RTLD_DEFAULT, "scePthreadAttrDestroy");
getstack_fn gs = (getstack_fn)dlsym(RTLD_DEFAULT, "scePthreadAttrGetstacksize");
void* self_sym = dlsym(RTLD_DEFAULT, "scePthreadSelf");
sce_create_fn create = (sce_create_fn)dlsym(RTLD_DEFAULT, "scePthreadCreate");
sce_join_fn join = (sce_join_fn)dlsym(RTLD_DEFAULT, "scePthreadJoin");
int ok = sce && init && destroy && gs && self_sym && create && join;
probe_case("0", "dlsym AttrGet,AttrInit,AttrDestroy,Getstacksize,Self,Create,Join (1 all)", ok, 0, ok ? "yes" : "no");
if(!ok) {
probe_end();
return 0;
}
pthread_t (*self_fn)(void) = (pthread_t (*)(void))self_sym;
pthread_t self = self_fn();
gcase("1.1", "scePthreadAttrInit + scePthreadAttrGet(scePthreadSelf)", sce, init, destroy, gs, self, 0);
gcase("1.2", "scePthreadAttrGet(scePthreadSelf, NULL attr)", sce, init, destroy, gs, self, 1);
gcase("1.3", "scePthreadAttrGet(pthread_self handle)", sce, init, destroy, gs, pthread_self(), 0);
pthread_t t = 0;
release_flag = 0;
started = 0;
int cr = create(&t, 0, worker, 0, "probe_worker");
if(cr != 0) {
probe_case("2.0", "scePthreadCreate worker", cr, errno, "failed");
probe_end();
return 0;
}
for(int i = 0; i < 200 && !started; i++) usleep(1000);
gcase("2.1", "scePthreadAttrGet(running scePthreadCreate thread)", sce, init, destroy, gs, t, 0);
release_flag = 1;
int jr = join(t, 0);
char ex[40];
snprintf(ex, sizeof ex, "join=%d", jr);
probe_case("3.0", "scePthreadJoin(worker)", jr, 0, ex);
gcase("3.1", "scePthreadAttrGet(joined scePthreadCreate handle)", sce, init, destroy, gs, t, 0);
probe_end();
return 0;
}stdoutAI-assisted (Claude Code). |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
What
Two entries in
docs/dev/debt/libkernel.mdforscePthreadAttrGetsaid that a null attribute and the answer for a thread that has ended were not measured. A probe on a PS5 now has, and the two entries state it. Only these two lines change; no code does, because the behaviour already matches and the tests already pin it.On the console,
scePthreadAttrGetreturned0x80020016(EINVAL) for a null attribute pointer, and 0 for the calling thread, forpthread_self()and for a runningscePthreadCreatethread. For the handle of ascePthreadCreatethread that had been joined it returned0x80020003(ESRCH). AnyPS5 returns the same (Attr.cpp), andGuestPthreadAttr.cppalready requiresESRCHfor a joined thread andEINVALfor a null attribute. The entry for a detached thread that has exited stays open: the probe did not reach it, and the entry now says so.The values come from a payload process on firmware 11.60. The older values in the first entry (4 with the creator's policy for an inheriting thread, and the others) were measured on firmware 13.60 and are not repeated here; a title process may differ.
Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-11 at 03:01 UTC. A title process may differ. The cases are 1.1 to 3.1, lines 3 to 8 of the raw output in the first comment.main(code and tests, not run)scePthreadAttrGet(scePthreadSelf(), attr)afterscePthreadAttrInitscePthreadAttrGet(scePthreadSelf(), NULL)EINVAL) (line 4)EINVALscePthreadAttrGet(pthread_self(), attr)scePthreadAttrGet(running scePthreadCreate thread, attr)scePthreadJoin(worker), thenscePthreadAttrGet(worker, attr)ESRCH) (lines 7 and 8)ESRCH(GuestPthreadAttr.cpp)tools/check_conventions.py --base upstream/mainpasses with no error and no warning; the first entry is 990 characters. The probe source and its raw output are in the first comment. Not tested: Windows, macOS, the CI runner, a title process, any other firmware,pthread_attr_get_np, a detached thread that has exited, and the stack size the console reports for a created thread (65536 for the running thread in line 6, where AnyPS5 reports its default thread stack size of 1048576); that last difference is not part of this change.Overlap: 113 open pull requests change
docs/dev/debt/libkernel.md, and none of them changes an entry forscePthreadAttrGet. I merged this head and each of them withmain(4d6043e08bc9) on 2026-11-11 at 07:44 UTC: 78 merge cleanly withmainand with this head, and 35 already conflict withmainwithout this pull request; none conflicts only with this head. Four open pull requests that changeAttr.cppor the thread code, #8041, #4563, #9938 and #16790, do not change the two entries edited here: #8041 and #4563 do not changelibkernel.mdat all, #9938 and #16790 change other entries of it, and #9938 already conflicts withmain.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code