Repository navigation
docs(debt): record the console results of std::_Mtx_init_with_default_name_override on firmware 11.60 - #23372
Conversation
…_name_override 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 (build 4124efccfb67, 33-character name)#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>
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);
}
#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)
/* Probe: std::_Mtx_init_with_default_name_override of libSceLibcInternal.sprx (dlsym, NID naKdJL9d3nE) on firmware 11.60 (debt libSceLibcInternal.md entry 'forwards to
std::_Mtx_init_with_name with the same type and name, so the mutex takes the given name and a null or empty name creates an unnamed one. Whether the console substitutes a default name such
as SceLibcI_Mtx for a null name ... is not measured'). Prototype int _Mtx_init_with_default_name_override(void** handle, int type, const char* name); neighbours _Mtx_init_with_name,
_Mtx_destroy, _Mtx_lock, _Mtx_unlock (std::__sce_v2 mangled). Case 0: existence of the five names (1 yes, 0 no). THE NAME ITSELF IS NOT OBSERVABLE from a payload process (no getter is
called), so this probe measures only the results and the behaviour: b) types _Mtx_plain 1, 0x101 (recursive plain), 2, 4 with the name n1_19_named: return code, handle != 0, then lock/unlock/destroy
through the neighbours; a recursive mutex locked twice in the same thread (a helper thread waited for 2 s: blocked = not recursive); c) the names NULL, empty, 31, 32 and 40 characters: return code
and handle; d) invalid types 0, 3, 0x7fffffff and -1: return code and handle (marker 0xAA before); e) NULL handle, handle 0x1, name 0x1 as single guarded calls with a 5 s alarm. All mutexes are
destroyed with _Mtx_destroy. About 35 calls. */
#include <pthread.h>
#include <time.h>
typedef int (*in_fn)(void**, int, const char*);
typedef int (*m1_fn)(void**);
static in_fn ini, ini2;
static m1_fn lk, ul, ds;
static volatile int done, step;
static volatile long R[8];
static void sleep_ms(int ms) { struct timespec t = {ms / 1000, (ms % 1000) * 1000000L}; nanosleep(&t, 0); }
static void* rec(void* p) {
void** h = (void**)p;
R[0] = lk(h); step = 1; R[1] = lk(h); step = 2; R[2] = ul(h); R[3] = ul(h); step = 4; done = 1;
return 0;
}
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
guard_arm();
void* hl = dlopen("libSceLibcInternal.sprx", RTLD_LAZY);
ini = (in_fn)(hl ? dlsym(hl, "_ZNSt8__sce_v236_Mtx_init_with_default_name_overrideEPP13pthread_mutexiPKc") : 0);
ini2 = (in_fn)(hl ? dlsym(hl, "_ZNSt8__sce_v219_Mtx_init_with_nameEPP13pthread_mutexiPKc") : 0);
ds = (m1_fn)(hl ? dlsym(hl, "_ZNSt8__sce_v212_Mtx_destroyEPP13pthread_mutex") : 0);
lk = (m1_fn)(hl ? dlsym(hl, "_ZNSt8__sce_v29_Mtx_lockEPP13pthread_mutex") : 0);
ul = (m1_fn)(hl ? dlsym(hl, "_ZNSt8__sce_v211_Mtx_unlockEPP13pthread_mutex") : 0);
char ex[8];
snprintf(ex, sizeof ex, "%d%d%d%d%d%d", !!hl, !!ini, !!ini2, !!ds, !!lk, !!ul);
probe_case("0", "dlopen LibcInternal; found _Mtx_init_with_default_name_override, _Mtx_init_with_name, _Mtx_destroy, _Mtx_lock, _Mtx_unlock (1 yes, 0 no)", 0, 0, ex);
if(!ini) { probe_end(); return 0; }
int rc, e;
char line[220];
static const int types[4] = {1, 0x101, 2, 4};
for(int i = 0; i < 4; i++) {
void* h = (void*)0xAAAAAAAAAAAAAAAAULL;
h = 0;
int r = -9, lr = -9, ur = -9, dr = -9;
CALL(rc, e, (r = ini(&h, types[i], "n1_19_named"), 0));
if(h && lk && ul) {
CALL(rc, e, (lr = lk(&h), 0));
CALL(rc, e, (ur = ul(&h), 0));
}
snprintf(line, sizeof line, "init rc=%d handle_not_null=%d lock rc=%d unlock rc=%d signal=%d", r, h != 0, lr, ur, (int)guard_sig);
char id[8], what[70];
snprintf(id, sizeof id, "b.%d", i + 1);
snprintf(what, sizeof what, "type 0x%x, name n1_19_named: init, lock, unlock", types[i]);
probe_case(id, what, guard_sig ? -1 : 0, e, line);
if(h && ds) CALL(rc, e, (dr = ds(&h), 0));
(void)dr;
}
if(lk && ul && ds) {
for(int k = 0; k < 2; k++) {
void* h = 0;
int tp = k == 0 ? 0x101 : 1;
CALL(rc, e, (ini(&h, tp, "n1_19_rec"), 0));
pthread_t th;
done = 0; step = 0;
for(int i = 0; i < 8; i++) R[i] = -1;
if(h && pthread_create(&th, 0, rec, &h) == 0) {
for(int i = 0; i < 200 && !done; i++) sleep_ms(10);
if(done) pthread_join(th, 0);
snprintf(line, sizeof line, "completed=%d last_step=%d lock1=%lx lock2=%lx unlock1=%lx unlock2=%lx", (int)done, (int)step, (long)R[0], (long)R[1], (long)R[2], (long)R[3]);
probe_case(k == 0 ? "b.rec" : "b.plain", k == 0 ? "type 0x101: the same thread locks twice (recursive: returns)" : "type 1: the same thread locks twice (plain: blocks)", 0, 0, line);
if(done) CALL(rc, e, (ds(&h), 0));
}
}
}
static const char* const names[5] = {0, "", "0123456789012345678901234567890", "01234567890123456789012345678901", "012345678901234567890123456789012"};
static const char* const nn[5] = {"NULL", "empty", "31 characters", "32 characters", "33 characters"};
for(int i = 0; i < 3; i++) {
void* h = 0;
int r = -9;
CALL(rc, e, (r = ini(&h, 1, names[i]), 0));
snprintf(line, sizeof line, "init rc=%d handle_not_null=%d signal=%d", r, h != 0, (int)guard_sig);
char id[8], what[60];
snprintf(id, sizeof id, "c.%d", i + 1);
snprintf(what, sizeof what, "name %s (the name is not observable)", nn[i]);
probe_case(id, what, guard_sig ? -1 : 0, e, line);
if(h && ds) CALL(rc, e, (ds(&h), 0));
}
static const int bad[4] = {0, 3, 0x7fffffff, -1};
for(int i = 0; i < 4; i++) {
void* h = (void*)0xAAAAAAAAAAAAAAAAULL;
int r = -9;
CALL(rc, e, (r = ini(&h, bad[i], "n1_19_bad"), 0));
snprintf(line, sizeof line, "init rc=%d handle_after=%s signal=%d", r, h == (void*)0xAAAAAAAAAAAAAAAAULL ? "unchanged(0xaa..)" : (h ? "non-null" : "null"), (int)guard_sig);
char id[8], what[50];
snprintf(id, sizeof id, "d.%d", i + 1);
snprintf(what, sizeof what, "invalid type 0x%x", (unsigned)bad[i]);
probe_case(id, what, guard_sig ? -1 : 0, e, line);
if(h != (void*)0xAAAAAAAAAAAAAAAAULL && h && ds) CALL(rc, e, (ds(&h), 0));
}
alarm(5);
{
int r = -9;
void* h = 0;
CALL(rc, e, (r = ini((void**)0, 1, "x"), 0)); snprintf(line, sizeof line, "rc=%d signal=%d", r, (int)guard_sig); probe_case("e.1", "e: NULL handle pointer (single call)", guard_sig ? -1 : 0, e, line); guard_hits = 0;
CALL(rc, e, (r = ini((void**)0x1, 1, "x"), 0)); snprintf(line, sizeof line, "rc=%d signal=%d", r, (int)guard_sig); probe_case("e.2", "e: handle pointer 0x1 (single call)", guard_sig ? -1 : 0, e, line); guard_hits = 0;
CALL(rc, e, (r = ini(&h, 1, (const char*)0x1), 0)); snprintf(line, sizeof line, "rc=%d signal=%d", r, (int)guard_sig); probe_case("e.3", "e: name pointer 0x1 (single call)", guard_sig ? -1 : 0, e, line); guard_hits = 0;
if(h && ds) ds(&h);
}
/* names of 32 and 40 characters last: the first run showed that a 32 character name throws std::system_error (invalid argument) that ends the process */
for(int i = 4; i < 5; i++) {
void* h = 0;
int r = -9;
probe_case("c.pre", "next call: name of 32 or 40 characters (an uncaught std::system_error ends the process)", 0, 0, nn[i]);
CALL(rc, e, (r = ini(&h, 1, names[i]), 0));
snprintf(line, sizeof line, "init rc=%d handle_not_null=%d signal=%d", r, h != 0, (int)guard_sig);
char id[8], what[60];
snprintf(id, sizeof id, "c.%d", i + 1);
snprintf(what, sizeof what, "name %s (the name is not observable)", nn[i]);
probe_case(id, what, guard_sig ? -1 : 0, e, line);
if(h && ds) CALL(rc, e, (ds(&h), 0));
}
alarm(PROBE_MAX_S);
probe_end();
return 0;
}stdout, 32 characters as the last name (run at 17:06 UTC, build 6368c663dabb)stdout, 40 characters as the last name (run at 19:52 UTC, build 79ee86dbb0eb)stdout, 40 characters as the last name (run at 20:35 UTC, build 79ee86dbb0eb)stdout, 33 characters as the last name (run at 20:36 UTC, build 4124efccfb67)AI-assisted (Claude Code). |
What
The
std::_Mtx_init_with_default_name_overrideentry indocs/dev/debt/libSceLibcInternal.mdsays the function forwards tostd::_Mtx_init_with_name"so the mutex takes the given name and a null or empty name creates an unnamed one", and that whether the console substitutes a default name is not measured. Probes in a payload process on firmware 11.60 have now called the console's function throughdlsymoflibSceLibcInternal.sprx. This pull request replaces that sentence through a debt fragment, as the contribution rules ask; no code changes. One correction comes with it: readingMutex.cppandThreads.cpp, the name reachesscePthreadMutexInit, which takes it as an unnamedconst char*and ignores it, so the mutex does not take the given name.With the types 0x1, 0x101, 0x2 and 0x4 and a short name,
initreturned 0 with a non-null handle, as didlockandunlock(cases b.1 to b.4, lines 3 to 6 of the output). Type 0x101 let the same thread lock twice (0 and 0) and unlock twice (b.rec, line 7); type 1 returned 3 from the secondlock(b.plain, line 8). A null name, an empty name and a name of 31 characters returned 0 with a non-null handle (c.1 to c.3, lines 9 to 11), and so did the types 0x0, 0x3, 0x7fffffff and 0xffffffff (d.1 to d.4, lines 12 to 15). A null handle pointer, a handle pointer 0x1 and a name pointer 0x1 faulted (SIGSEGV; e.1 to e.3, lines 16 to 18). A name of 32 characters (the line 19 of the 17:06 UTC run names the length), of 33 characters and of 40 characters (two runs) made the process print "Fatal error during phase 1 unwinding" and "Terminating due to uncaught exception 'invalid argument' of typestd::__sce_v2::system_error" (lines 20 and 21) and end, with no further case and noENDline. Each of the lengths 32, 33 and 40 was measured in its own run, so the exception follows the length of the name and not a case before it; 34 to 39 characters and more than 40 were not measured, and this pull request does not state a threshold.The entry now says what the process measured and what AnyPS5 does: a long name is accepted here, where the console throws, and the types behave as the console's did by reading (
_Mtx_init_with_namehas no type test; only bit 0x100 selects a recursive mutex). The throw is recorded as a difference and not changed here. The emulator itself was not run for this pull request, and the plain mutex's secondlock(3 on the console) was not compared.Not measured: names of 34 to 39 characters and of more than 40 characters, the name the console gives a null name (it cannot be observed from the guest), a title process, and other firmware.
Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from homebrew payload processes (ps5-payload-sdk v0.45, elfldr) that loadlibSceLibcInternal.sprxand take the function withdlsym, on 2026-11-18 at 17:06 UTC (32 characters), 19:52 UTC and 20:35 UTC (40 characters) and 20:36 UTC (33 characters). A title process may differ. The probe source and the complete output of all four runs are in the first comment.std::__sce_v2::system_error, process endstools/check_conventions.py --base upstream/mainpasses with no finding, andtools/debt_fold.py --checkpasses. This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against this function, 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-libcinternal-mtx-default-name-console-1160.md, a new file),core/libs/prx/libSceLibcInternal/Mutex.cpporcore/libs/prx/libc/src/Threads.cpp, which the entry describes, or the debt entrystd::_Mtx_init_with_default_name_overrideindocs/dev/debt/libSceLibcInternal.md, found by reading the changed files of all 1969 open pull requests at about 21:30 to 21:52 UTC, by reading what they change in the debt files and in those two source files for_Mtx_init_with_default_name_overrideand_Mtx_init_with_name, and by searching their titles and branch names for the same names (no hit), were checked on 2026-11-18 at about 22:03 UTC againstmain866864a5bc8together with this head and with the heads of the four other documentation pull requests opened with it (pthread_getstack_np,statvfsandfstatvfs,_Mtxinit,_Geterrno): the branch is based on97192ebf661, an ancestor of it, merges intomainwithout a conflict, andtools/debt_fold.py --checkapplies the fragment together with every other fragment onmainand with the four other fragments without an error (mainitself reports an error for the fragmentfeat-tools-windows-response-files.md, "no debt file for TechnicalDebt", with or without this branch; with that one fragment left out, the check passes with this fragment). Nine pull requests listlibSceLibcInternal.mdfor other entries; as this branch adds only a fragment, none of them conflicts with this change in the files, and none changes a line of thestd::_Mtx_init_with_default_name_overrideentry; #18135 carries it only as an unchanged context line. Of the seven that listThreads.cpporMutex.cpp, #23161 changes_MtxinitinMutex.cpp(another function, another entry), #18347 changes_Mtx_trylockinThreads.cpp, and #9447 (feat(libc): add the std::__sce_v2 thread start, timed wait, clock and processor count calls) adds_Mtx_init_with_namecode toThreads.cppthatmainalready has; none of them changes the debt entry. #12965, #12700, #12688 and #12682 carry the_Mtx_init_with_nameentry oflibc.mdas a context line, another file and another entry. Unpublished local branches that touch the same files were compared as well, and none changes this entry or these functions. 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)