Repository navigation
docs(debt): record the _Mtx_current_owns results on firmware 11.60 - #22020
Merged
oneandonlydean merged 1 commit intoNov 17, 2026
Merged
oneandonlydean merged 1 commit into
oneandonlydean merged 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Probe source (built with ps5-payload-sdk v0.45; probe.c#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)
/* _Mtx_current_owns of libSceLibcInternal.sprx (dlsym) on firmware 11.60 ('returns 1 and ignores its argument ... PS5 12.00
body reading reported in PR8859 ... other firmware versions and the argument's console type remain unverified'). Prototype int _Mtx_current_owns(void** m);
helpers int _Mtx_init(void**, int), int _Mtx_lock(void**), int _Mtx_unlock(void**), void _Mtx_destroy(void**). Cases: a plain mutex locked by this thread and after
unlock; b a mutex held by ANOTHER thread, queried by the main thread; c an initialised-then-destroyed handle and an empty slot with value 0 (single
calls, guarded); the NULL pointer is not passed. Own objects only; the helper thread is joined. 10 calls, each guarded. */
#include <stdatomic.h>
typedef int (*mi_fn)(void**, int);
typedef int (*mo_fn)(void**);
typedef void (*md_fn)(void**);
static mi_fn minit; static mo_fn mlock, munlock, mowns; static md_fn mdestroy;
static void* mtx2;
static atomic_int held, release;
static void* holder(void* a) {
(void)a;
mlock(&mtx2);
atomic_store(&held, 1);
int spin = 0;
while(!atomic_load(&release) && spin++ < 500000) usleep(100);
munlock(&mtx2);
return 0;
}
static void q(const char* id, const char* what, void** m) {
int rc, e, r = -99;
CALL(rc, e, (r = mowns(m)));
char ex[60];
snprintf(ex, sizeof ex, "value=%d signal=%d", r, (int)guard_sig);
probe_case(id, what, guard_sig ? -1 : r, e, ex);
}
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
guard_arm();
void* hl = dlopen("libSceLibcInternal.sprx", RTLD_LAZY);
minit = (mi_fn)(hl ? dlsym(hl, "_Mtx_init") : 0);
mlock = (mo_fn)(hl ? dlsym(hl, "_Mtx_lock") : 0);
munlock = (mo_fn)(hl ? dlsym(hl, "_Mtx_unlock") : 0);
mowns = (mo_fn)(hl ? dlsym(hl, "_Mtx_current_owns") : 0);
mdestroy = (md_fn)(hl ? dlsym(hl, "_Mtx_destroy") : 0);
char ex[10];
snprintf(ex, sizeof ex, "%d%d%d%d%d%d", !!hl, !!minit, !!mlock, !!munlock, !!mowns, !!mdestroy);
probe_case("0", "dlopen LibcInternal; dlsym _Mtx_init _Mtx_lock _Mtx_unlock _Mtx_current_owns _Mtx_destroy (1 yes, 0 no)", 0, 0, ex);
if(!minit || !mlock || !munlock || !mowns || !mdestroy) { probe_end(); return 0; }
void* m1 = 0;
int ir = minit(&m1, 1);
char l[40]; snprintf(l, sizeof l, "init_rc=%d", ir);
probe_case("a.0", "_Mtx_init(&m1, plain)", ir, 0, l);
q("a.1", "_Mtx_current_owns(&m1) before locking", &m1);
mlock(&m1);
q("a.2", "_Mtx_current_owns(&m1) locked by this thread", &m1);
munlock(&m1);
q("a.3", "_Mtx_current_owns(&m1) after unlock", &m1);
mtx2 = 0;
minit(&mtx2, 1);
atomic_store(&held, 0); atomic_store(&release, 0);
pthread_t th;
int cr = pthread_create(&th, 0, holder, 0);
for(int i = 0; i < 2000 && !atomic_load(&held); i++) usleep(1000);
q("b", "_Mtx_current_owns(&mtx2) while ANOTHER thread holds it", &mtx2);
atomic_store(&release, 1);
if(cr == 0) pthread_join(th, 0);
void* empty = 0;
q("c.1", "_Mtx_current_owns(&empty_slot) (value 0, never initialised)", &empty);
mdestroy(&mtx2);
q("c.2", "_Mtx_current_owns(&mtx2) after _Mtx_destroy", &mtx2);
mdestroy(&m1);
probe_end();
return 0;
}stdoutAI-assisted (Claude Code). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
_Mtx_current_ownsentry indocs/dev/debt/libc.mdsays that this library returns 1 and ignores its argument, following a firmware 12.00 reading reported in PR8859, and that other firmware versions and the argument's console type remain unverified. A probe has now called the console's_Mtx_current_owns(libSceLibcInternal.sprx) from a payload process on firmware 11.60. The pull request adds one sentence to the entry and changes "The firmware observation" to "The 12.00 observation", through a debt fragment, as the contribution rules ask; no code changes.On firmware 11.60
_Mtx_current_ownsreturned 1 in all six calls: on an initialized plain mutex before it was locked (case a.1, line 4), while this thread held it (a.2, line 5) and after unlocking (a.3, line 6); on another mutex while a different thread held it (case b, line 7); on a zeroed slot that was never initialized (c.1, line 8); and after_Mtx_destroy(c.2, line 9). So the console's answer does not depend on the state of the mutex or on which thread holds it in these cases, which is what ignoring the argument gives; this library's_Mtx_current_owns_nid_postfixinThreads.cppreturns 1 without reading its argument.Not measured: other argument values (the probe passed pointers to mutexes and to a zeroed slot), the argument's console type, and a title process.
Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr) that loadslibSceLibcInternal.sprxand takes_Mtx_init,_Mtx_lock,_Mtx_unlock,_Mtx_current_ownsand_Mtx_destroywithdlsym, on 2026-11-16 at 23:38 UTC. A title process may differ. The cases are 0 to c.2, lines 2 to 9 of the raw output in the first comment (line 2 shows that all five symbols were found).main(code read)_Mtx_destroytools/check_conventions.py --base upstream/mainpasses with no error and no warning (the entry is 653 characters, up from 453). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against these calls, 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-libc-mtx-current-owns-console-1160.md, a new file) or the debt entry it changes, found by reading the changed files of all 1593 open pull requests at about 00:37 UTC, by reading what they change indocs/dev/debt/libc.mdand in the fragments underdocs/dev/debt/changes/for_Mtx_current_owns, and by searching their titles and branch names for the same names. The branch was test-merged on 2026-11-16 at about 01:13 UTC againstmainc50f19c4b8e(the branch is based onc40f058298d, an ancestor of it) and merges into it without a conflict;tools/debt_fold.py --checkapplies the fragment to the debt file of thatmainwithout an error (checked without the fragmentlibressl3-20171-inventory.md, which already conflicts withfeat-libressl3-evp-pkey-new-mac-key-v2.mdonmainand is not part of this change), the text it changes occurs in exactly one entry, and no other fragment changes that entry. Five other open pull requests changeThreads.cpp(#18347, #18122, #12315, #9447, #1835); none of them changes a line that names_Mtx_current_ownsor this debt entry (#18347 changes the_Mtx_trylockentry), and #12315 lists the file but changes nothing in it againstmain. #17555, #17556, #17557 and #17558 touchlibc.mdelsewhere. 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)