Skip to content

docs(debt): record the measured scePthreadAttrGet returns - #18325

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/kernel-pthread-attrget-console
Nov 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/kernel-pthread-attrget-console

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

What

Two entries in docs/dev/debt/libkernel.md for scePthreadAttrGet said 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, scePthreadAttrGet returned 0x80020016 (EINVAL) for a null attribute pointer, and 0 for the calling thread, for pthread_self() and for a running scePthreadCreate thread. For the handle of a scePthreadCreate thread that had been joined it returned 0x80020003 (ESRCH). AnyPS5 returns the same (Attr.cpp), and GuestPthreadAttr.cpp already requires ESRCH for a joined thread and EINVAL for 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_version 0x11600005), 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.

Call PS5, payload process, firmware 11.60 AnyPS5 main (code and tests, not run) here
scePthreadAttrGet(scePthreadSelf(), attr) after scePthreadAttrInit 0 (line 3) 0 unchanged, entry states it
scePthreadAttrGet(scePthreadSelf(), NULL) 0x80020016 (EINVAL) (line 4) EINVAL unchanged, entry states it
scePthreadAttrGet(pthread_self(), attr) 0 (line 5) 0 unchanged
scePthreadAttrGet(running scePthreadCreate thread, attr) 0 (line 6) 0 unchanged, entry states it
scePthreadJoin(worker), then scePthreadAttrGet(worker, attr) 0, then 0x80020003 (ESRCH) (lines 7 and 8) ESRCH (GuestPthreadAttr.cpp) unchanged, entry states it

tools/check_conventions.py --base upstream/main passes 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 for scePthreadAttrGet. I merged this head and each of them with main (4d6043e08bc9) on 2026-11-11 at 07:44 UTC: 78 merge cleanly with main and with this head, and 35 already conflict with main without this pull request; none conflicts only with this head. Four open pull requests that change Attr.cpp or the thread code, #8041, #4563, #9938 and #16790, do not change the two entries edited here: #8041 and #4563 do not change libkernel.md at all, #9938 and #16790 change other entries of it, and #9938 already conflicts with main.

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 (documentation only)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

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>
@xXPBSXx

xXPBSXx commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256, 94041f579b8b) and its raw output from the run on 2026-11-11 at 03:01 UTC. The clock in the PROBE line is the console's own clock. The probe uses scePthreadAttrInit, scePthreadAttrGet, scePthreadAttrGetstacksize, scePthreadAttrDestroy, scePthreadSelf, scePthreadCreate and scePthreadJoin only, on threads it creates itself. A reference to an internal case sheet in the header comment was removed; the code is unchanged, and the build ID is the hash of the original file. The header comment also names pthread_attr_get_np and a detached thread that has exited, which this probe does not call; the raw output lists the cases that ran.

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;
}
stdout
PROBE	libkernel_attrget2	fw=0x11600005	build=94041f579b8b	pid=127	utc=2026-11-11T04:42:53Z
CASE	0	dlsym AttrGet,AttrInit,AttrDestroy,Getstacksize,Self,Create,Join (1 all)	1	0	yes
CASE	1.1	scePthreadAttrInit + scePthreadAttrGet(scePthreadSelf)	0	0	init=0 stacksize=2097152 signal=0
CASE	1.2	scePthreadAttrGet(scePthreadSelf, NULL attr)	-2147352554	0	init=-1 stacksize=0 signal=0
CASE	1.3	scePthreadAttrGet(pthread_self handle)	0	0	init=0 stacksize=2097152 signal=0
CASE	2.1	scePthreadAttrGet(running scePthreadCreate thread)	0	0	init=0 stacksize=65536 signal=0
CASE	3.0	scePthreadJoin(worker)	0	0	join=0
CASE	3.1	scePthreadAttrGet(joined scePthreadCreate handle)	-2147352573	0	init=0 stacksize=0 signal=0
END	7

AI-assisted (Claude Code).

@github-actions github-actions Bot added the docs label Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libkernel.md
PR 6149 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 9156 docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9389 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9938 docs/dev/debt/libkernel.md
PR 10442 docs/dev/debt/libkernel.md
PR 10558 docs/dev/debt/libkernel.md
PR 11215 docs/dev/debt/libkernel.md
PR 11625 docs/dev/debt/libkernel.md
PR 11628 docs/dev/debt/libkernel.md
PR 11661 docs/dev/debt/libkernel.md
PR 11689 docs/dev/debt/libkernel.md
PR 11698 docs/dev/debt/libkernel.md
PR 11896 docs/dev/debt/libkernel.md
PR 12682 docs/dev/debt/libkernel.md
PR 12688 docs/dev/debt/libkernel.md
PR 12700 docs/dev/debt/libkernel.md
PR 12965 docs/dev/debt/libkernel.md
PR 14103 docs/dev/debt/libkernel.md
PR 14108 docs/dev/debt/libkernel.md
PR 14128 docs/dev/debt/libkernel.md
PR 14212 docs/dev/debt/libkernel.md
PR 14497 docs/dev/debt/libkernel.md
PR 14756 docs/dev/debt/libkernel.md
PR 15037 docs/dev/debt/libkernel.md
PR 15040 docs/dev/debt/libkernel.md
PR 15041 docs/dev/debt/libkernel.md
PR 15095 docs/dev/debt/libkernel.md
PR 15524 docs/dev/debt/libkernel.md
PR 15567 docs/dev/debt/libkernel.md
PR 15571 docs/dev/debt/libkernel.md
PR 17216 docs/dev/debt/libkernel.md
PR 17220 docs/dev/debt/libkernel.md
PR 17223 docs/dev/debt/libkernel.md
PR 17228 docs/dev/debt/libkernel.md
PR 17257 docs/dev/debt/libkernel.md
PR 17584 docs/dev/debt/libkernel.md
PR 17585 docs/dev/debt/libkernel.md
PR 17609 docs/dev/debt/libkernel.md
PR 17867 docs/dev/debt/libkernel.md
PR 18035 docs/dev/debt/libkernel.md
PR 18197 docs/dev/debt/libkernel.md
PR 18515 docs/dev/debt/libkernel.md
PR 18542 docs/dev/debt/libkernel.md
PR 18547 docs/dev/debt/libkernel.md
PR 18548 docs/dev/debt/libkernel.md

@oneandonlydean
oneandonlydean merged commit 62ab7ea into boykopovar:main Nov 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants