Skip to content

fix(libkernel): answer scePthreadGetname with ESRCH for a null thread and EFAULT for a null buffer as the console does - #28210

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:fix/libkernel-getname-null-esrch-efault
Dec 5, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:fix/libkernel-getname-null-esrch-efault

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What

scePthreadGetname answered a null thread and a null buffer with SCE_KERNEL_ERROR_EINVAL (core/libs/prx/libkernel/Pthread/src/Thread.cpp:1646 on the base ffc6f26b0786). A PS5 (firmware 11.60, payload process; a title process may differ) returned 0x80020003 (ESRCH) for a null thread and 0x8002000e (EFAULT, errno 14) for a null buffer, in two runs whose outputs are equal line for line except the PROBE line (cases e.1 and e.2, lines 14 and 15 of the raw output in the first comment). On the same console pthread_getname_np returned 3 for a null thread and 14 for a null buffer (cases e.3 and e.4, lines 16 and 17), and pthread_getname_np_nid_postfix here already answers those two cases that way (core/libs/prx/libkernel/Pthread/Posix/Thread.cpp:488 and :489 on the base).

The fix commit (0b4a4c6fd9c, Thread.cpp, 2 lines added and 1 removed) answers a null thread with SCE_KERNEL_ERROR_ESRCH and, after it, a null buffer with SCE_KERNEL_ERROR_EFAULT (Thread.cpp:1646 and :1647); a thread that is not null is handled as before. The test commit (db305311061, GuestPthreadGetname.cpp, 2 lines added and 2 removed) expects ESRCH and EFAULT where it expected EINVAL (GuestPthreadGetname.cpp:62 and :70). The debt commit (91876d5c22b, fix-libkernel-getname-null-console.md, 5 lines added and 0 removed) adds the fragment that changes the entry scePthreadGetname, pthread_getname_np buffer to the measured results; the entry is 902 characters with its list marker.

Not measured and not claimed: the order of the checks when the thread and the buffer are both null (here the thread is checked first; neither order was measured), a title process, and a partial write before a failure. 39 of 56 local title run folders import scePthreadGetname, in the executable or in a bundled module (3 of them in the executable itself), and 1 imports pthread_getname_np; an import is not a call, so title use is not established. Counted on 2026-11-29 at 03:56 UTC from the import registries in the newest local run folder of each of the 56 titles.

Tested

Windows 10 Pro (10.0.19045), MinGW-W64 GCC 15.2.0 (WinLibs), CMake with Ninja, Release, BUILD_TESTING=ON, ccache, one machine, both arms on main ffc6f26. Red: with the test commit alone (db30531), guest_pthread_getname_tests ended with FATAL: abort() (SIGABRT) (exit 127). Green: with the fix and the debt commit (91876d5c22bc, the head of this branch) the same test returned 0 in three of three runs. The five neighbouring tests guest_pthread_handle_after_exit_tests, guest_pthread_rename_tests, guest_kernel_sys_thread_defaults_tests, guest_pthread_second_join_tests and guest_posix_thread_name_tests returned 0 in both arms. The red arm ran once (the abort comes from the two changed Require lines). Against a fresh main ea39f12 (fetched on 2026-11-29): tools/debt_fold.py --check exits with 0; tools/check_conventions.py --base upstream/main reports no findings; git merge-tree of the head with that main is clean. The builds ran on main ffc6f26, not on ea39f12. Not tested: other operating systems, a run of this code on a PS5, a title.

Overlap: counted on 2026-11-29 from the 2133 open pull requests (file lists from the GitHub API, the pull requests with 100 or more files read in full through the files API; the 1345 pull requests that change a file under docs/dev/debt/, core/libs/prx/libkernel/Pthread/, GuestPthreadGetname.cpp or libkernel.md, or have pthread, getname, thread name or libkernel in the title or branch name, had their patches of the files under docs/dev/debt/ and of the files with libkernel or Pthread in the path searched for scePthreadGetname, pthread_getname_np, PthreadGetname, the fragment name and the text getname, from 04:10 to 05:40 UTC, main at ea39f127f401 at the start). No open pull request changes the fragment docs/dev/debt/changes/fix-libkernel-getname-null-console.md or the entry scePthreadGetname, pthread_getname_np buffer at docs/dev/debt/libkernel.md:445, and of the 175 commits on main since ffc6f26b0786 (the base of this branch; up to 859a238b8c73) only one, #27554, changed a file under core/libs/prx/libkernel/Pthread/ (Posix/Sem.cpp); none changed Pthread/src/Thread.cpp, core/libs/tests/GuestPthreadGetname.cpp or libkernel.md. 24 of the open pull requests change a file named Thread.cpp or the test file GuestPthreadGetname.cpp: 8 of them merge cleanly with this head, and the other 16 conflict with main alone in as many files, so none because of this change. #21571 (fix(libkernel): look the thread up before the name in pthread renames) is the closest: it changes scePthreadRename in the same Thread.cpp (a hunk at about line 1608; this change is at :1646 and :1647), the rename checks in GuestPthreadGetname.cpp (about line 81; this change is at :62 and :70) and its own fragment, which has other entries; it merges cleanly with this head. #18190 (feat(libs): mirror libkernel exports through libkernel_sys) adds scePthreadGetname_nid_no_patch to provider files and removes pthread_getname_np_nid_postfix from Posix/Thread.cpp, the function whose lines :488 and :489 this text cites for the base; it conflicts with this head in 1 file and with main alone in 1 file, so not because of this change, and #18112 (... libkernel_web) only declares pthread_getname_np_nid_no_patch and merges cleanly. Other patches only call the functions: #21464, #12642 and #12130 (scePthreadGetname in GuestPthreadSuspend.cpp) and #28064 and #23953 (pthread_getname_np_nid_postfix in tests); the other hits of getname are other functions (getnameinfo, ucnv_getName, uloc_getName, getNamedItem, GetNamedPipeHandleState and similar). The merges of this head with each of the 95 pull requests that change a file under core/libs/prx/libkernel/Pthread/, GuestPthreadGetname.cpp or libkernel.md or have a searched name were made with git merge-tree from 04:10 to 05:40 UTC: 42 are clean; the other 53 already conflict with main alone, in at least as many files as with this head, so none of them conflicts because of this change. The count was repeated for the 36 pull requests that were opened or updated since 04:10 UTC (of the 2135 open pull requests, from 06:08 to 06:11 UTC; 29 of them were patch-scanned for the same names): one hit, #21464 (a call of scePthreadGetname), which now merges cleanly with this head. A merge of this head into main at 859a238b8c73 was checked at 06:09 UTC and is clean. This pull request does not depend on any of them (Depends on: none).

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (no graphics change)
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Retrieving a thread’s name now reports a missing thread separately from an invalid output buffer, returning the corresponding error for each case instead of the same generic error.
    • Updated checks confirm the reported errors for both null-argument cases.

xXPBSXx and others added 3 commits November 29, 2026 02:52
…r a null thread and a null buffer

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… and EFAULT for a null buffer as the console does

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ead_getname_np for bad arguments

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (PROBE_BUILD is the first 12 hex digits of the SHA-256 of the original source file; the source is posted verbatim except that an internal label at the start of the long comment on line 87 was removed, the code is unchanged) and the complete raw output of the first of two runs that this pull request cites by line number (line 1 is the PROBE line); the second run is posted after it. The utc in a PROBE line is the console's own clock, about 1 h 42 min ahead of real UTC; the first run started at 00:29 UTC and the second at 00:59 UTC on 2026-11-29. The probe loads libkernel.sprx with dlopen, takes the functions with dlsym, and uses prototypes it assumes (scePthreadGetname(void*, char*), pthread_getname_np(void*, char*, size_t)). In each CASE line the columns are the case, the call, the return value as a decimal, the errno and the details; rc= in the details is the return value in hex.

libkernel scePthreadGetname and pthread_getname_np with bad arguments: probe.c (build 2ada3b4f45e3)
#include <errno.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);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  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);
}
#include <dlfcn.h>
#include <setjmp.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/mman.h>

static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static volatile int guard_active = 0;
static volatile int guard_hits = 0;
static void guard_handler(int s) {
  static const char msg[] = "FAULT\tprobe guard: fault outside a guarded call or too many faults\n";
  if(!guard_active || ++guard_hits > 8) {
    (void)!write(1, msg, sizeof msg - 1);
    _exit(125);
  }
  guard_sig = s;
  guard_active = 0;
  siglongjmp(guard_env, 1);
}
static void guard_arm(void) {
  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);
  sigaction(SIGILL, &sa, 0);
  sigaction(SIGTRAP, &sa, 0);
  sigaction(SIGFPE, &sa, 0);
}
#define CALL(rvar, evar, expr) do { errno = 0; guard_sig = 0; rvar = -1; if(sigsetjmp(guard_env, 1) == 0) { guard_active = 1; rvar = (expr); } guard_active = 0; evar = errno; } while(0)

/* scePthreadGetname and pthread_getname_np with a bad buffer on firmware 11.60 (Debt libkernel.md:445 'The console's behaviour with a bad buffer was not measured ... The buffer is assumed to hold the 32 bytes of the longest name'; AnyPS5 libkernel/Pthread/src/Thread.cpp:1627-1640 and Posix/Thread.cpp:482-488).
   ASSUMED prototypes (as used by the earlier name probe of run 2026-11-08T175455Z): void* scePthreadSelf(void); int scePthreadRename(void*, const char*); int scePthreadGetname(void*, char*); int pthread_getname_np(void*, char*, size_t). Everything runs on the own thread and own memory: a static area of 256 bytes with a 0xAA canary pattern (target buffer of 64 bytes at offset 96, 16 canary bytes before and after the target are checked), own anonymous pages (mmap, 0x4000 bytes, none or read-only); no file access, no module loading, no module info.
   Case 0.dlopen.1/2: two dlopen attempts of libkernel.sprx (NULL ends the run). Case 1.ctrl: control sceKernelGetCurrentCpu and negative control by dlsym; case 2: dlsym of the four names (any missing ends the run as a name stage). Case 3: scePthreadRename(self, aps5getname) as the control of the name (return only; the rename path is covered by earlier runs).
   Non-faulting cases first: a.1 scePthreadGetname(self, 64-byte target): return, the name text, number of changed target bytes (12 expected for the name and its terminator), canary before and after intact; a.2 to a.6 pthread_getname_np(self, target, length) with length 64, 4, 0, 12 and 11 (each: return, text, changed bytes, canary); e.1 scePthreadGetname(NULL thread, target); e.2 scePthreadGetname(self, NULL buffer); e.3 pthread_getname_np(NULL thread, target, 64); e.4 pthread_getname_np(self, NULL, 64) (return and signal).
   Faulting cases last, each with a note before the call, each guarded (SIGSEGV, SIGBUS, SIGABRT, SIGILL, SIGTRAP, SIGFPE); the run ENDS at the first signal (the name lock of the runtime may be held; the rest goes to a separate probe P2b): f.1 and f.2 buffer 0x10 for scePthreadGetname and pthread_getname_np; f.3 and f.4 buffer on an own PROT_NONE page; f.5 and f.6 buffer on an own PROT_READ page; f.7 and f.8 buffer 8 bytes before an own PROT_NONE page (the name needs 12 bytes, only 8 are writable); f.9 and f.10 thread 0x10 with a valid target. About 30 guarded steps. */
typedef void* (*self_fn)(void);
typedef int (*rename_fn)(void*, const char*);
typedef int (*getname_fn)(void*, char*);
typedef int (*getnp_fn)(void*, char*, size_t);
static void* probe_watchdog(void* arg) {
  static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
  (void)arg;
  { unsigned left = PROBE_MAX_S; 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 unsigned char area[256];
#define TGT (area + 96)
static void area_reset(void) { memset(area, 0xAA, sizeof area); }
static int changed_bytes(void) {
  int n = 0;
  for(int i = 0; i < 64; i++) if(TGT[i] != 0xAA) n++;
  return n;
}
static int canary_ok(void) {
  for(int i = 80; i < 96; i++) if(area[i] != 0xAA) return 0;
  for(int i = 160; i < 176; i++) if(area[i] != 0xAA) return 0;
  return 1;
}
static void text_of(char* out, int sz) {
  int pos = 0;
  for(int i = 0; i < 64 && pos < sz - 6; i++) {
    unsigned char c = TGT[i];
    if(c == 0xAA) break;
    if(c == 0) { pos += snprintf(out + pos, sz - pos, "[NUL]"); break; }
    out[pos++] = (c >= 32 && c < 127) ? (char)c : '?';
  }
  out[pos] = 0;
}
int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();
  probe_watchdog_start();
  guard_arm();
  char line[400], txt[120];
  probe_case("0.pre", "next: dlopen of libkernel.sprx; a hang here ends the run by timeout", 0, 0, "-");
  void* k1 = dlopen("libkernel.sprx", RTLD_LAZY);
  probe_case("0.dlopen.1", "dlopen(libkernel.sprx) first attempt", k1 != 0, 0, "-");
  void* k2 = dlopen("libkernel.sprx", RTLD_LAZY);
  probe_case("0.dlopen.2", "dlopen(libkernel.sprx) second attempt", k2 != 0, 0, "-");
  void* kern = k1 ? k1 : k2;
  if(!kern) { probe_end(); return 0; }
  void* ctl = dlsym(kern, "sceKernelGetCurrentCpu");
  void* neg = dlsym(kern, "sceKernelNoSuchControlAps5");
  snprintf(line, sizeof line, "control sceKernelGetCurrentCpu resolves %d, negative control resolves %d (1 yes, 0 no)", ctl != 0, neg != 0);
  probe_case("1.ctrl", "dlsym in libkernel.sprx: control and negative control", 0, 0, line);
  self_fn f_self = (self_fn)dlsym(kern, "scePthreadSelf");
  rename_fn f_ren = (rename_fn)dlsym(kern, "scePthreadRename");
  getname_fn f_get = (getname_fn)dlsym(kern, "scePthreadGetname");
  getnp_fn f_np = (getnp_fn)dlsym(kern, "pthread_getname_np");
  snprintf(line, sizeof line, "dlsym in libkernel.sprx: scePthreadSelf %d, scePthreadRename %d, scePthreadGetname %d, pthread_getname_np %d (1 yes, 0 no)", f_self != 0, f_ren != 0, f_get != 0, f_np != 0);
  probe_case("2", "name stage", 0, 0, line);
  if(!ctl || neg || !f_self || !f_ren || !f_get || !f_np) { probe_end(); return 0; }
  int rc, e, sig;
  void* me = f_self();
  CALL(rc, e, f_ren(me, "aps5getname"));
  sig = guard_sig;
  snprintf(line, sizeof line, "rc=0x%x signal=%d", (unsigned)rc, sig);
  probe_case("3", "scePthreadRename(self, aps5getname) as the control of the name", sig ? -1 : rc, e, line);
  if(sig) { probe_end(); return 0; }
  guard_hits = 0;
  /* a: non-faulting cases */
  area_reset();
  CALL(rc, e, f_get(me, (char*)TGT));
  sig = guard_sig;
  text_of(txt, sizeof txt);
  snprintf(line, sizeof line, "rc=0x%x signal=%d text=%s changed=%d canary_ok=%d", (unsigned)rc, sig, txt, changed_bytes(), canary_ok());
  probe_case("a.1", "scePthreadGetname(self, 64-byte target)", sig ? -1 : rc, e, line);
  if(sig) { probe_end(); return 0; }
  static const size_t LENS[5] = {64, 4, 0, 12, 11};
  for(int i = 0; i < 5; i++) {
    char id[8];
    snprintf(id, sizeof id, "a.%d", i + 2);
    area_reset();
    CALL(rc, e, f_np(me, (char*)TGT, LENS[i]));
    sig = guard_sig;
    text_of(txt, sizeof txt);
    snprintf(line, sizeof line, "length %zu: rc=0x%x signal=%d text=%s changed=%d canary_ok=%d", LENS[i], (unsigned)rc, sig, txt, changed_bytes(), canary_ok());
    probe_case(id, "pthread_getname_np(self, 64-byte target, length)", sig ? -1 : rc, e, line);
    if(sig) { probe_end(); return 0; }
  }
  area_reset();
  CALL(rc, e, f_get(0, (char*)TGT));
  sig = guard_sig;
  snprintf(line, sizeof line, "rc=0x%x signal=%d changed=%d canary_ok=%d", (unsigned)rc, sig, changed_bytes(), canary_ok());
  probe_case("e.1", "scePthreadGetname(NULL thread, target)", sig ? -1 : rc, e, line);
  if(sig) { probe_end(); return 0; }
  CALL(rc, e, f_get(me, 0));
  sig = guard_sig;
  snprintf(line, sizeof line, "rc=0x%x signal=%d", (unsigned)rc, sig);
  probe_case("e.2", "scePthreadGetname(self, NULL buffer)", sig ? -1 : rc, e, line);
  if(sig) { probe_end(); return 0; }
  area_reset();
  CALL(rc, e, f_np(0, (char*)TGT, 64));
  sig = guard_sig;
  snprintf(line, sizeof line, "rc=0x%x signal=%d changed=%d canary_ok=%d", (unsigned)rc, sig, changed_bytes(), canary_ok());
  probe_case("e.3", "pthread_getname_np(NULL thread, target, 64)", sig ? -1 : rc, e, line);
  if(sig) { probe_end(); return 0; }
  CALL(rc, e, f_np(me, 0, 64));
  sig = guard_sig;
  snprintf(line, sizeof line, "rc=0x%x signal=%d", (unsigned)rc, sig);
  probe_case("e.4", "pthread_getname_np(self, NULL buffer, 64)", sig ? -1 : rc, e, line);
  if(sig) { probe_end(); return 0; }
  /* own pages */
  void* pn = mmap(0, 0x8000, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
  void* pr = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
  int prot_ok = 0;
  if(pr != MAP_FAILED) { memset(pr, 0, 0x4000); prot_ok = mprotect(pr, 0x4000, PROT_READ) == 0; }
  char* edge = 0;
  void* pnone = 0;
  if(pn != MAP_FAILED) {
    if(mprotect(pn, 0x4000, PROT_READ | PROT_WRITE) == 0) { memset(pn, 0, 0x4000); edge = (char*)pn + 0x4000 - 8; }
    pnone = (char*)pn + 0x4000;
  }
  snprintf(line, sizeof line, "PROT_NONE page %d, PROT_READ page %d, edge buffer 8 bytes before a PROT_NONE page %d (1 yes, 0 no)", pnone != 0, prot_ok, edge != 0);
  probe_case("5", "own anonymous pages", 0, 0, line);
  /* f: faulting cases, the run ends at the first signal */
  struct { const char* id; const char* desc; int which; void* buf; void* thr; } F[10] = {
    {"f.1", "scePthreadGetname(self, 0x10)", 0, (void*)0x10, me},
    {"f.2", "pthread_getname_np(self, 0x10, 64)", 1, (void*)0x10, me},
    {"f.3", "scePthreadGetname(self, PROT_NONE page)", 0, pnone, me},
    {"f.4", "pthread_getname_np(self, PROT_NONE page, 64)", 1, pnone, me},
    {"f.5", "scePthreadGetname(self, PROT_READ page)", 0, prot_ok ? pr : 0, me},
    {"f.6", "pthread_getname_np(self, PROT_READ page, 64)", 1, prot_ok ? pr : 0, me},
    {"f.7", "scePthreadGetname(self, 8 bytes before a PROT_NONE page)", 0, edge, me},
    {"f.8", "pthread_getname_np(self, 8 bytes before a PROT_NONE page, 64)", 1, edge, me},
    {"f.9", "scePthreadGetname(thread 0x10, target)", 0, (void*)TGT, (void*)0x10},
    {"f.10", "pthread_getname_np(thread 0x10, target, 64)", 1, (void*)TGT, (void*)0x10},
  };
  for(int i = 0; i < 10; i++) {
    if(!F[i].buf) { probe_case(F[i].id, F[i].desc, 0, 0, "page not available, not run"); continue; }
    char pre[200];
    snprintf(pre, sizeof pre, "next: %s; a signal here ends the run", F[i].desc);
    probe_case("f.pre", pre, 0, 0, "-");
    area_reset();
    if(F[i].which == 0) { CALL(rc, e, f_get(F[i].thr, (char*)F[i].buf)); }
    else { CALL(rc, e, f_np(F[i].thr, (char*)F[i].buf, 64)); }
    sig = guard_sig;
    snprintf(line, sizeof line, "rc=0x%x signal=%d", (unsigned)rc, sig);
    probe_case(F[i].id, F[i].desc, sig ? -1 : rc, e, line);
    if(sig) { probe_end(); return 0; }
  }
  probe_end();
  return 0;
}
Run 1 at 00:29 UTC: stdout
PROBE	libkernel_getname_buf	fw=0x11600005	build=2ada3b4f45e3	pid=175	utc=2026-11-29T02:12:20Z
CASE	0.pre	next: dlopen of libkernel.sprx; a hang here ends the run by timeout	0	0	-
CASE	0.dlopen.1	dlopen(libkernel.sprx) first attempt	1	0	-
CASE	0.dlopen.2	dlopen(libkernel.sprx) second attempt	1	0	-
CASE	1.ctrl	dlsym in libkernel.sprx: control and negative control	0	0	control sceKernelGetCurrentCpu resolves 1, negative control resolves 0 (1 yes, 0 no)
CASE	2	name stage	0	0	dlsym in libkernel.sprx: scePthreadSelf 1, scePthreadRename 1, scePthreadGetname 1, pthread_getname_np 1 (1 yes, 0 no)
CASE	3	scePthreadRename(self, aps5getname) as the control of the name	0	0	rc=0x0 signal=0
CASE	a.1	scePthreadGetname(self, 64-byte target)	0	0	rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.2	pthread_getname_np(self, 64-byte target, length)	0	0	length 64: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.3	pthread_getname_np(self, 64-byte target, length)	0	0	length 4: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.4	pthread_getname_np(self, 64-byte target, length)	0	0	length 0: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.5	pthread_getname_np(self, 64-byte target, length)	0	0	length 12: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.6	pthread_getname_np(self, 64-byte target, length)	0	0	length 11: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	e.1	scePthreadGetname(NULL thread, target)	-2147352573	0	rc=0x80020003 signal=0 changed=0 canary_ok=1
CASE	e.2	scePthreadGetname(self, NULL buffer)	-2147352562	14	rc=0x8002000e signal=0
CASE	e.3	pthread_getname_np(NULL thread, target, 64)	3	0	rc=0x3 signal=0 changed=0 canary_ok=1
CASE	e.4	pthread_getname_np(self, NULL buffer, 64)	14	14	rc=0xe signal=0
CASE	5	own anonymous pages	0	0	PROT_NONE page 1, PROT_READ page 1, edge buffer 8 bytes before a PROT_NONE page 1 (1 yes, 0 no)
CASE	f.pre	next: scePthreadGetname(self, 0x10); a signal here ends the run	0	0	-
CASE	f.1	scePthreadGetname(self, 0x10)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, 0x10, 64); a signal here ends the run	0	0	-
CASE	f.2	pthread_getname_np(self, 0x10, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(self, PROT_NONE page); a signal here ends the run	0	0	-
CASE	f.3	scePthreadGetname(self, PROT_NONE page)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, PROT_NONE page, 64); a signal here ends the run	0	0	-
CASE	f.4	pthread_getname_np(self, PROT_NONE page, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(self, PROT_READ page); a signal here ends the run	0	0	-
CASE	f.5	scePthreadGetname(self, PROT_READ page)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, PROT_READ page, 64); a signal here ends the run	0	0	-
CASE	f.6	pthread_getname_np(self, PROT_READ page, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(self, 8 bytes before a PROT_NONE page); a signal here ends the run	0	0	-
CASE	f.7	scePthreadGetname(self, 8 bytes before a PROT_NONE page)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, 8 bytes before a PROT_NONE page, 64); a signal here ends the run	0	0	-
CASE	f.8	pthread_getname_np(self, 8 bytes before a PROT_NONE page, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(thread 0x10, target); a signal here ends the run	0	0	-
CASE	f.9	scePthreadGetname(thread 0x10, target)	-2147352573	0	rc=0x80020003 signal=0
CASE	f.pre	next: pthread_getname_np(thread 0x10, target, 64); a signal here ends the run	0	0	-
CASE	f.10	pthread_getname_np(thread 0x10, target, 64)	3	0	rc=0x3 signal=0
END	37
Run 2 at 00:59 UTC: stdout (equal to run 1 except the PROBE line)
PROBE	libkernel_getname_buf	fw=0x11600005	build=2ada3b4f45e3	pid=178	utc=2026-11-29T02:42:26Z
CASE	0.pre	next: dlopen of libkernel.sprx; a hang here ends the run by timeout	0	0	-
CASE	0.dlopen.1	dlopen(libkernel.sprx) first attempt	1	0	-
CASE	0.dlopen.2	dlopen(libkernel.sprx) second attempt	1	0	-
CASE	1.ctrl	dlsym in libkernel.sprx: control and negative control	0	0	control sceKernelGetCurrentCpu resolves 1, negative control resolves 0 (1 yes, 0 no)
CASE	2	name stage	0	0	dlsym in libkernel.sprx: scePthreadSelf 1, scePthreadRename 1, scePthreadGetname 1, pthread_getname_np 1 (1 yes, 0 no)
CASE	3	scePthreadRename(self, aps5getname) as the control of the name	0	0	rc=0x0 signal=0
CASE	a.1	scePthreadGetname(self, 64-byte target)	0	0	rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.2	pthread_getname_np(self, 64-byte target, length)	0	0	length 64: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.3	pthread_getname_np(self, 64-byte target, length)	0	0	length 4: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.4	pthread_getname_np(self, 64-byte target, length)	0	0	length 0: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.5	pthread_getname_np(self, 64-byte target, length)	0	0	length 12: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	a.6	pthread_getname_np(self, 64-byte target, length)	0	0	length 11: rc=0x0 signal=0 text=aps5getname[NUL] changed=12 canary_ok=1
CASE	e.1	scePthreadGetname(NULL thread, target)	-2147352573	0	rc=0x80020003 signal=0 changed=0 canary_ok=1
CASE	e.2	scePthreadGetname(self, NULL buffer)	-2147352562	14	rc=0x8002000e signal=0
CASE	e.3	pthread_getname_np(NULL thread, target, 64)	3	0	rc=0x3 signal=0 changed=0 canary_ok=1
CASE	e.4	pthread_getname_np(self, NULL buffer, 64)	14	14	rc=0xe signal=0
CASE	5	own anonymous pages	0	0	PROT_NONE page 1, PROT_READ page 1, edge buffer 8 bytes before a PROT_NONE page 1 (1 yes, 0 no)
CASE	f.pre	next: scePthreadGetname(self, 0x10); a signal here ends the run	0	0	-
CASE	f.1	scePthreadGetname(self, 0x10)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, 0x10, 64); a signal here ends the run	0	0	-
CASE	f.2	pthread_getname_np(self, 0x10, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(self, PROT_NONE page); a signal here ends the run	0	0	-
CASE	f.3	scePthreadGetname(self, PROT_NONE page)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, PROT_NONE page, 64); a signal here ends the run	0	0	-
CASE	f.4	pthread_getname_np(self, PROT_NONE page, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(self, PROT_READ page); a signal here ends the run	0	0	-
CASE	f.5	scePthreadGetname(self, PROT_READ page)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, PROT_READ page, 64); a signal here ends the run	0	0	-
CASE	f.6	pthread_getname_np(self, PROT_READ page, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(self, 8 bytes before a PROT_NONE page); a signal here ends the run	0	0	-
CASE	f.7	scePthreadGetname(self, 8 bytes before a PROT_NONE page)	-2147352562	14	rc=0x8002000e signal=0
CASE	f.pre	next: pthread_getname_np(self, 8 bytes before a PROT_NONE page, 64); a signal here ends the run	0	0	-
CASE	f.8	pthread_getname_np(self, 8 bytes before a PROT_NONE page, 64)	14	14	rc=0xe signal=0
CASE	f.pre	next: scePthreadGetname(thread 0x10, target); a signal here ends the run	0	0	-
CASE	f.9	scePthreadGetname(thread 0x10, target)	-2147352573	0	rc=0x80020003 signal=0
CASE	f.pre	next: pthread_getname_np(thread 0x10, target, 64); a signal here ends the run	0	0	-
CASE	f.10	pthread_getname_np(thread 0x10, target, 64)	3	0	rc=0x3 signal=0
END	37

AI-assisted (Claude Code).

@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 91876d5c22:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_pthread_getname_tests built cleanly.
  • CTest (guest_pthread_getname):
    1/1 Test #6541: guest_pthread_getname ............   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Pthread/src/Thread.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #6541: guest_pthread_getname ............Subprocess aborted***Exception:   0.12 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified scePthreadGetname parameter validation in core/libs/prx/libkernel/Pthread/src/Thread.cpp:1646-1647 correctly returns SCE_KERNEL_ERROR_ESRCH for null thread and SCE_KERNEL_ERROR_EFAULT for null name, matching PS5 hardware probe measurements.
    • Verified LockRegisteredGuestThread is only called after null checks, correctly returning SCE_KERNEL_ERROR_ESRCH for nonexistent threads.
    • Verified GuestPthreadGetname.cpp unit tests assert SCE_KERNEL_ERROR_ESRCH on nullptr thread and SCE_KERNEL_ERROR_EFAULT on nullptr buffer without leaving residual state.
    • Verified technical debt fragment docs/dev/debt/changes/fix-libkernel-getname-null-console.md matches standard conventions and accurately documents the measured console behavior.
    • Confirmed zero AGENTS.md rule violations, no disallowed comments added, and mechanical checks/tests cleanly pass.

Looks Good To Me

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Getname null-argument errors

Layer / File(s) Summary
Null-argument results and validation
core/libs/prx/libkernel/Pthread/src/Thread.cpp, core/libs/tests/GuestPthreadGetname.cpp, docs/dev/debt/changes/fix-libkernel-getname-null-console.md
scePthreadGetname returns SCE_KERNEL_ERROR_ESRCH for a null thread and SCE_KERNEL_ERROR_EFAULT for a null name buffer. The test expectations and documentation record these results and related observations.

Suggested labels: libkernel, docs

Suggested reviewers: gruzzberry, marczx10, milescoviello

Change: Bug fix

Merge Risk: Minimal · up to 91876

This change makes scePthreadGetname return ESRCH for a null thread and EFAULT for a null name buffer, matching the author's reported console measurements. It adds no concrete merge risk, and the tests and notes are updated to match.

Security architecture risk: Minimal · up to 91876

The change distinguishes a null thread handle from a null output buffer without expanding access to thread names or changing how names are written to guest memory.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The observable difference is limited to error codes for direct calls with null arguments. Neither revised return depends on whether a supplied thread handle is registered or on what name a thread holds.

Trust Boundaries and Controls

  • observed — Both versions reject null inputs before accessing thread data or guest memory. For non-null inputs, the implementation still checks thread registration before reading the name under lock and uses the same guest-memory copy-out routine.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53a243d2-31d7-49b1-97b2-9d00036dff60
Commits

Reviewing files that changed from the base of the PR and between 859a238 and 91876d5.

Files selected for processing: 3

  • core/libs/prx/libkernel/Pthread/src/Thread.cpp
  • core/libs/tests/GuestPthreadGetname.cpp
  • docs/dev/debt/changes/fix-libkernel-getname-null-console.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@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 in the reviewed changes blocks merging; the null argument results match the reported console behavior and the test expectations.

What I ran

Reviewed head 91876d5c22bc5e5a2728dfcb7d988789c23ebbcd using the prepared diff, changed files, and pinned source context. No commands or tests were run by me.

Results

Check Result Note
Changed code review passed Three changed files read
Tests not run Author reports test results
Build and merge checks not run Author reports results

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read all three files listed as reviewed in manifest.json: core/libs/prx/libkernel/Pthread/src/Thread.cpp, core/libs/tests/GuestPthreadGetname.cpp, and docs/dev/debt/changes/fix-libkernel-getname-null-console.md. No changed files were excluded. I did not run the tests or independently verify the author-reported console, build, convention, debt, or merge checks. Title-process behavior and simultaneous invalid arguments remain unmeasured as the description states.

To get this to a good state

Nothing is required.

@JJenkx

JJenkx commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Linux check of the exact head 91876d5c22bc; the description has no Linux results. Arch Linux 7.3.5 x86-64, GCC 16.2.1, Release, -DBUILD_TESTING=ON:

  • ctest -R '^guest_pthread_getname$' (this PR's GuestPthreadGetname.cpp): 1 pass, 0 skipped.

AI-assisted: yes

@github-actions

github-actions Bot commented Nov 29, 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 9938 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12130 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12682 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12688 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12700 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12965 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 15040 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 16790 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 18190 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 23953 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 27864 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28299 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28808 core/libs/prx/libkernel/Pthread/src/Thread.cpp

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Built and ran the repository’s guest_pthread_getname CTest on Linux with this change applied. The fixture passed with the updated kernel errors for null handles and null buffers, and still passed its stale-handle, read-only, guard-page and exact-fit buffer cases.

AI-assisted: yes.

@Plyxen Plyxen 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.

I read the diff at 91876d5c22. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at b97867d3ce6 together with other open PRs (so not an isolated build).

  • guest_pthread_getname: pass on both.
  • Control (same tree and tests, the changed files of those PRs put back to main's): aborts on both.

Not checked: a title.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit e957aad into boykopovar:main Dec 5, 2026
15 of 17 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