feat(libkernel): implement pthread_getname_np #1798

Merged
hugodearaujo merged 1 commit from upstream-pr/1798 into main 2026-10-09 21:51:57 +00:00
hugodearaujo commented 2026-10-08 19:27:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-08T19:27:16Z.


What

Hades (PPSA03355, v01.003) stops at load on main:

./app.elf: symbol lookup error: ./app.elf: undefined symbol: 9HzfhdtESio

9HzfhdtESio is pthread_getname_np. The executable imports it from libkernel and calls it once: pthread_getname_np(pthread_self(), buffer), with a 32-byte stack buffer that was zeroed first. No length is set before the call.

I measured the console function on a PS5 (firmware 13.60) by calling libkernel's export through dlopen from a homebrew payload, with the buffer filled with 0xAA before each call:

Call Console
thread named "", "A", "AnyPS5Probe", a 31-character name 0; writes the name and its terminator, nothing after
a third argument of 0, 1, 4 or 64 ignored: the whole name is written
a new thread that was never named 0, ""
a joined thread, or a null thread 3 (ESRCH), nothing written
a null buffer 14 (EFAULT)

So on the PS5 it takes (thread, buffer), not FreeBSD's (thread, buffer, length). This adds pthread_getname_np with that signature on top of scePthreadGetname, which already writes the stored name truncated to 31 characters and terminated, and returns ESRCH and EFAULT for the two measured errors.

A joined thread cannot be detected here: scePthreadJoin frees the thread object, so the pointer is indistinguishable from a live one. The TechnicalDebt entry records that. Hades only passes pthread_self().

With this branch, Hades gets past load and runs until sceKernelDebugRaiseException (0xa0020013), before it reaches the pthread_getname_np call. That stop is unrelated and is not touched here.

A fork branch (budhilaw/AnyPS5, feat/macos-uncharted, not in a PR) has a three-argument version that would read the length from rdx. Hades never sets that register before this call.

Measured in passing, and not changed here: the console's pthread_rename_np refuses a name of 32 characters or more with 63 (ENAMETOOLONG) and keeps the old name, while main stores any length.

Tested

  • PS5 firmware 13.60: every row of the table. The probe source and the raw output are in the comment below.
  • Hades (PPSA03355) on Linux: stops at load on main with the line above, and gets past load with this branch.
  • Linux: build, libs, full CTest 480/480. The new guest_pthread_getname covers every row except the joined thread.
  • Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: build, libs, CTest 0 failed of 474, guest_pthread_getname included (GPU execution tests skipped, the VM has no GPU).
  • Mutation check: 5 mutations each make guest_pthread_getname fail. They drop the null-thread or null-buffer check, return EINVAL for the buffer, drop the terminator, or pad the buffer past the name.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791779641 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1798). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-08T19:27:16Z. --- ### What Hades (PPSA03355, v01.003) stops at load on `main`: ``` ./app.elf: symbol lookup error: ./app.elf: undefined symbol: 9HzfhdtESio ``` `9HzfhdtESio` is `pthread_getname_np`. The executable imports it from libkernel and calls it once: `pthread_getname_np(pthread_self(), buffer)`, with a 32-byte stack buffer that was zeroed first. No length is set before the call. I measured the console function on a PS5 (firmware 13.60) by calling libkernel's export through `dlopen` from a homebrew payload, with the buffer filled with `0xAA` before each call: | Call | Console | |---|---| | thread named `""`, `"A"`, `"AnyPS5Probe"`, a 31-character name | 0; writes the name and its terminator, nothing after | | a third argument of 0, 1, 4 or 64 | ignored: the whole name is written | | a new thread that was never named | 0, `""` | | a joined thread, or a null thread | 3 (`ESRCH`), nothing written | | a null buffer | 14 (`EFAULT`) | So on the PS5 it takes `(thread, buffer)`, not FreeBSD's `(thread, buffer, length)`. This adds `pthread_getname_np` with that signature on top of `scePthreadGetname`, which already writes the stored name truncated to 31 characters and terminated, and returns `ESRCH` and `EFAULT` for the two measured errors. A joined thread cannot be detected here: `scePthreadJoin` frees the thread object, so the pointer is indistinguishable from a live one. The TechnicalDebt entry records that. Hades only passes `pthread_self()`. With this branch, Hades gets past load and runs until `sceKernelDebugRaiseException` (`0xa0020013`), before it reaches the `pthread_getname_np` call. That stop is unrelated and is not touched here. A fork branch (`budhilaw/AnyPS5`, `feat/macos-uncharted`, not in a PR) has a three-argument version that would read the length from `rdx`. Hades never sets that register before this call. Measured in passing, and not changed here: the console's `pthread_rename_np` refuses a name of 32 characters or more with 63 (`ENAMETOOLONG`) and keeps the old name, while `main` stores any length. ### Tested - PS5 firmware 13.60: every row of the table. The probe source and the raw output are in the comment below. - Hades (PPSA03355) on Linux: stops at load on `main` with the line above, and gets past load with this branch. - Linux: build, `libs`, full CTest 480/480. The new `guest_pthread_getname` covers every row except the joined thread. - Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: build, `libs`, CTest 0 failed of 474, `guest_pthread_getname` included (GPU execution tests skipped, the VM has no GPU). - Mutation check: 5 mutations each make `guest_pthread_getname` fail. They drop the null-thread or null-buffer check, return `EINVAL` for the buffer, drop the terminator, or pad the buffer past the name. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hugodearaujo commented 2026-10-08 19:27:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-08T19:27:25Z.


Probe and raw output. It is a ps5-payload-sdk v0.43 payload (prospero-clang -O1 -rdynamic) that resolves pthread_getname_np and pthread_rename_np from libkernel with dlopen. Each line shows the return value and the bytes written into a 64-byte buffer pre-filled with 0xAA. The initial line is the payload's own main thread name.

getname.c
#include "../probe/probe.h"
#include <dlfcn.h>
#include <pthread.h>
#include <stdint.h>
#include <string.h>
typedef int (*Get2)(pthread_t, char*);
typedef int (*Get3)(pthread_t, char*, size_t);
typedef int (*Rename)(pthread_t, const char*);
static Get2 get2;
static void show(const char* label, int rc, const unsigned char* b) {
    printf("%s|rc=%08x|", label, (unsigned)rc);
    int last = 0;
    for (int i = 0; i < 64; ++i) if (b[i] != 0xAA) last = i + 1;
    for (int i = 0; i < last; ++i) printf("%02x", b[i]);
    printf("|written=%d\n", last);
    fflush(stdout);
}
static void* worker(void* arg) {
    unsigned char b[64]; memset(b, 0xAA, sizeof b);
    show("unnamed-thread", get2(pthread_self(), (char*)b), b);
    (void)arg;
    return 0;
}
int main(void) {
    int client = probe_begin();
    if (client < 0) return 1;
    void* k = dlopen("libkernel.sprx", RTLD_LAZY);
    if (!k) k = dlopen("libkernel_web.sprx", RTLD_LAZY);
    get2 = (Get2)dlsym(k, "pthread_getname_np");
    Get3 get3 = (Get3)get2;
    Rename ren = (Rename)dlsym(k, "pthread_rename_np");
    printf("dlsym get=%p rename=%p\n", (void*)get2, (void*)ren);
    if (!get2 || !ren) { probe_end(client); return 1; }
    unsigned char b[64];
    memset(b, 0xAA, sizeof b); show("initial", get2(pthread_self(), (char*)b), b);
    static const char* names[] = {"", "A", "AnyPS5Probe", "0123456789012345678901234567890", "01234567890123456789012345678901", "0123456789012345678901234567890123456789"};
    for (unsigned i = 0; i < 6; ++i) {
        int r = ren(pthread_self(), names[i]);
        memset(b, 0xAA, sizeof b);
        char label[64]; snprintf(label, sizeof label, "len%u|rename=%08x", (unsigned)strlen(names[i]), (unsigned)r);
        show(label, get2(pthread_self(), (char*)b), b);
    }
    ren(pthread_self(), "AnyPS5Probe");
    for (size_t n = 0; n < 4; ++n) { static const size_t lens[] = {0, 1, 4, 64}; memset(b, 0xAA, sizeof b); char label[32]; snprintf(label, sizeof label, "third=%zu", lens[n]); show(label, get3(pthread_self(), (char*)b, lens[n]), b); }
    pthread_t t; pthread_create(&t, 0, worker, 0); pthread_join(t, 0);
    memset(b, 0xAA, sizeof b); show("joined-thread", get2(t, (char*)b), b);
    printf("STEP null buffer\n"); fflush(stdout);
    printf("nullbuf|rc=%08x\n", (unsigned)get2(pthread_self(), NULL)); fflush(stdout);
    printf("STEP null thread\n"); fflush(stdout);
    memset(b, 0xAA, sizeof b); show("nullthread", get2((pthread_t)0, (char*)b), b);
    probe_end(client);
    return 0;
}
raw output
dlsym get=800009400 rename=800009290
initial|rc=00000000|53636553705a65726f436f6e664d61696e00|written=18
len0|rename=00000000|rc=00000000|00|written=1
len1|rename=00000000|rc=00000000|4100|written=2
len11|rename=00000000|rc=00000000|416e7950533550726f626500|written=12
len31|rename=00000000|rc=00000000|3031323334353637383930313233343536373839303132333435363738393000|written=32
len32|rename=0000003f|rc=00000000|3031323334353637383930313233343536373839303132333435363738393000|written=32
len40|rename=0000003f|rc=00000000|3031323334353637383930313233343536373839303132333435363738393000|written=32
third=0|rc=00000000|416e7950533550726f626500|written=12
third=1|rc=00000000|416e7950533550726f626500|written=12
third=4|rc=00000000|416e7950533550726f626500|written=12
third=64|rc=00000000|416e7950533550726f626500|written=12
unnamed-thread|rc=00000000|00|written=1
joined-thread|rc=00000003||written=0
STEP null buffer
nullbuf|rc=0000000e
STEP null thread
nullthread|rc=00000003||written=0
PROBE DONE
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067446019 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1798#issuecomment-6067446019). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-08T19:27:25Z. --- Probe and raw output. It is a ps5-payload-sdk v0.43 payload (`prospero-clang -O1 -rdynamic`) that resolves `pthread_getname_np` and `pthread_rename_np` from libkernel with `dlopen`. Each line shows the return value and the bytes written into a 64-byte buffer pre-filled with `0xAA`. The `initial` line is the payload's own main thread name. <details><summary>getname.c</summary> ```c #include "../probe/probe.h" #include <dlfcn.h> #include <pthread.h> #include <stdint.h> #include <string.h> typedef int (*Get2)(pthread_t, char*); typedef int (*Get3)(pthread_t, char*, size_t); typedef int (*Rename)(pthread_t, const char*); static Get2 get2; static void show(const char* label, int rc, const unsigned char* b) { printf("%s|rc=%08x|", label, (unsigned)rc); int last = 0; for (int i = 0; i < 64; ++i) if (b[i] != 0xAA) last = i + 1; for (int i = 0; i < last; ++i) printf("%02x", b[i]); printf("|written=%d\n", last); fflush(stdout); } static void* worker(void* arg) { unsigned char b[64]; memset(b, 0xAA, sizeof b); show("unnamed-thread", get2(pthread_self(), (char*)b), b); (void)arg; return 0; } int main(void) { int client = probe_begin(); if (client < 0) return 1; void* k = dlopen("libkernel.sprx", RTLD_LAZY); if (!k) k = dlopen("libkernel_web.sprx", RTLD_LAZY); get2 = (Get2)dlsym(k, "pthread_getname_np"); Get3 get3 = (Get3)get2; Rename ren = (Rename)dlsym(k, "pthread_rename_np"); printf("dlsym get=%p rename=%p\n", (void*)get2, (void*)ren); if (!get2 || !ren) { probe_end(client); return 1; } unsigned char b[64]; memset(b, 0xAA, sizeof b); show("initial", get2(pthread_self(), (char*)b), b); static const char* names[] = {"", "A", "AnyPS5Probe", "0123456789012345678901234567890", "01234567890123456789012345678901", "0123456789012345678901234567890123456789"}; for (unsigned i = 0; i < 6; ++i) { int r = ren(pthread_self(), names[i]); memset(b, 0xAA, sizeof b); char label[64]; snprintf(label, sizeof label, "len%u|rename=%08x", (unsigned)strlen(names[i]), (unsigned)r); show(label, get2(pthread_self(), (char*)b), b); } ren(pthread_self(), "AnyPS5Probe"); for (size_t n = 0; n < 4; ++n) { static const size_t lens[] = {0, 1, 4, 64}; memset(b, 0xAA, sizeof b); char label[32]; snprintf(label, sizeof label, "third=%zu", lens[n]); show(label, get3(pthread_self(), (char*)b, lens[n]), b); } pthread_t t; pthread_create(&t, 0, worker, 0); pthread_join(t, 0); memset(b, 0xAA, sizeof b); show("joined-thread", get2(t, (char*)b), b); printf("STEP null buffer\n"); fflush(stdout); printf("nullbuf|rc=%08x\n", (unsigned)get2(pthread_self(), NULL)); fflush(stdout); printf("STEP null thread\n"); fflush(stdout); memset(b, 0xAA, sizeof b); show("nullthread", get2((pthread_t)0, (char*)b), b); probe_end(client); return 0; } ``` </details> <details><summary>raw output</summary> ``` dlsym get=800009400 rename=800009290 initial|rc=00000000|53636553705a65726f436f6e664d61696e00|written=18 len0|rename=00000000|rc=00000000|00|written=1 len1|rename=00000000|rc=00000000|4100|written=2 len11|rename=00000000|rc=00000000|416e7950533550726f626500|written=12 len31|rename=00000000|rc=00000000|3031323334353637383930313233343536373839303132333435363738393000|written=32 len32|rename=0000003f|rc=00000000|3031323334353637383930313233343536373839303132333435363738393000|written=32 len40|rename=0000003f|rc=00000000|3031323334353637383930313233343536373839303132333435363738393000|written=32 third=0|rc=00000000|416e7950533550726f626500|written=12 third=1|rc=00000000|416e7950533550726f626500|written=12 third=4|rc=00000000|416e7950533550726f626500|written=12 third=64|rc=00000000|416e7950533550726f626500|written=12 unnamed-thread|rc=00000000|00|written=1 joined-thread|rc=00000003||written=0 STEP null buffer nullbuf|rc=0000000e STEP null thread nullthread|rc=00000003||written=0 PROBE DONE ``` </details>
github-actions[bot] commented 2026-10-08 19:27:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T19:27:43Z.


Progress report (b858fdc → 3c7859c)

➖ System libraries: 84.76% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel pthread_getname_np_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067450916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1798#issuecomment-6067450916). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T19:27:43Z. --- <!-- progress-report --> ### Progress report (b858fdc → 3c7859c) ➖ **System libraries**: 84.76% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `pthread_getname_np_nid_postfix` | </details>
adriadam10 commented 2026-10-09 21:51:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:51:54Z.


Checked the diff, build + full ctest (524/524) on Linux, and that guest_pthread_getname fails to link without the change; Linux, Windows and conventions CI are green. The joined-thread gap is recorded in TechnicalDebt under "Unknown function info". Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089864501 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1798#issuecomment-6089864501). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:51:54Z. --- Checked the diff, build + full ctest (524/524) on Linux, and that `guest_pthread_getname` fails to link without the change; Linux, Windows and conventions CI are green. The joined-thread gap is recorded in TechnicalDebt under "Unknown function info". Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1798
No description provided.