Repository navigation
docs(debt): record the hardware_concurrency result on firmware 11.60 - #22023
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)
/* srandomdev and std::thread::hardware_concurrency of libSceLibcInternal.sprx (dlsym) on firmware 11.60 ('srandomdev
... not verified against the console' and 'the starting mask ... and whether the console's count follows a process-wide
cpuset_setaffinity is not measured; this returns 13'). Part c: srandomdev(); random() x4; srandomdev() again; random() x4; srandom(1) and random()
x4 as a counter-test (only 'different yes or no' and the export). Part a: hardware_concurrency() against the number of set bits of this process's
affinity mask from cpuset_getaffinity. Part b: the process-wide mask (CPU_WHICH_PID, id -1) is set to 0x3 and hardware_concurrency is read again, then the
ORIGINAL mask is restored at once and verified; only the probe process is affected, a 5 s alarm limit covers a stuck call. KERN_ARND is not touched.
About 14 calls, each guarded. */
#include <sys/param.h>
#include <sys/cpuset.h>
typedef unsigned (*hc_fn)(void);
typedef void (*sd_fn)(void);
typedef long (*rd_fn)(void);
typedef void (*sr_fn)(unsigned);
static int count_bits(const cpuset_t* m) { int n = 0; for(int i = 0; i < CPU_SETSIZE; i++) if(CPU_ISSET(i, m)) n++; return n; }
static unsigned long first_word(const cpuset_t* m) { unsigned long w = 0; memcpy(&w, m, sizeof w); return w; }
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
guard_arm();
void* hl = dlopen("libSceLibcInternal.sprx", RTLD_LAZY);
hc_fn hc = (hc_fn)(hl ? dlsym(hl, "_ZNSt6thread20hardware_concurrencyEv") : 0);
sd_fn sdev = (sd_fn)(hl ? dlsym(hl, "srandomdev") : 0);
rd_fn rnd = (rd_fn)(hl ? dlsym(hl, "random") : 0);
sr_fn sr = (sr_fn)(hl ? dlsym(hl, "srandom") : 0);
char ex[16];
snprintf(ex, sizeof ex, "%d%d%d%d%d", !!hl, !!hc, !!sdev, !!rnd, !!sr);
probe_case("0", "dlopen LibcInternal; dlsym hardware_concurrency srandomdev random srandom (1 yes, 0 no)", 0, 0, ex);
int rc, e;
char line[200];
cpuset_t orig;
int have_orig = 0;
CPU_ZERO(&orig);
CALL(rc, e, (have_orig = (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof orig, &orig) == 0)));
if(hc) {
unsigned v = 0xdead;
CALL(rc, e, (v = hc(), 0));
snprintf(line, sizeof line, "value=%u mask_bits=%d mask_word0=0x%lx getaffinity_ok=%d signal=%d", v, have_orig ? count_bits(&orig) : -1,
have_orig ? first_word(&orig) : 0UL, have_orig, (int)guard_sig);
probe_case("a", "hardware_concurrency() against the thread's affinity mask", guard_sig ? -1 : (int)v, e, line);
}
if(hc && have_orig) {
cpuset_t two, back;
CPU_ZERO(&two); CPU_SET(0, &two); CPU_SET(1, &two);
int sr0 = -9;
CALL(rc, e, (sr0 = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof two, &two)));
int e0 = e;
unsigned v2 = 0xdead;
CALL(rc, e, (v2 = hc(), 0));
int rs = -9;
CALL(rc, e, (rs = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof orig, &orig)));
CPU_ZERO(&back);
int gb = -9;
CALL(rc, e, (gb = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof back, &back)));
unsigned v3 = 0xdead;
CALL(rc, e, (v3 = hc(), 0));
snprintf(line, sizeof line, "set_rc=%d errno=%d value_after_set=%u restore_rc=%d restored_equal=%d value_after_restore=%u", sr0, e0, v2, rs,
gb == 0 && memcmp(&back, &orig, sizeof back) == 0, v3);
probe_case("b", "process-wide affinity {0,1}, hardware_concurrency(), then restore", sr0, e0, line);
}
if(sdev && rnd && sr) {
long a[4] = {0, 0, 0, 0}, b[4] = {0, 0, 0, 0}, c[4] = {0, 0, 0, 0};
CALL(rc, e, (sdev(), 0));
for(int i = 0; i < 4; i++) { CALL(rc, e, (a[i] = rnd(), 0)); }
CALL(rc, e, (sdev(), 0));
for(int i = 0; i < 4; i++) { CALL(rc, e, (b[i] = rnd(), 0)); }
CALL(rc, e, (sr(1), 0));
for(int i = 0; i < 4; i++) { CALL(rc, e, (c[i] = rnd(), 0)); }
int diff = memcmp(a, b, sizeof a) != 0;
snprintf(line, sizeof line, "sequences_differ=%d first_after_srandom1=%lx,%lx,%lx,%lx signal=%d", diff, c[0], c[1], c[2], c[3], (int)guard_sig);
probe_case("c", "srandomdev() x2 with 4 random() each: sequences differ? and srandom(1) known sequence", diff, 0, line);
}
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
std::thread::hardware_concurrencyentry indocs/dev/debt/libc.mdsays that this library returns 13, the number of CPUs in libkernel's default thread mask, and that in payload processes whose threads started with mask0xea00the console'slibSceLibcInternalreturned 5 on firmware 13.60 and 12.70. A probe has now called it from a payload process on firmware 11.60. The pull request adds one sentence to the entry through a debt fragment, as the contribution rules ask; no code changes.On firmware 11.60
hardware_concurrencyreturned 5 (case a, line 3). The probe could not read the thread's affinity mask there (cpuset_getaffinityfailed, so no mask is shown), so it cannot say whether that mask is0xea00as on the other firmware versions; the entry therefore says "On 11.60 it also returned 5, but the mask could not be read there." The part of the probe that sets a process-wide mask depends on reading the original mask and did not run. This library still returns 13 and the entry still says that what a title sees is not measured.Not measured: the starting mask on 11.60, the effect of a process-wide
cpuset_setaffinitythere, and a title process (PPSA34015, named in the entry, imports the function).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 the function withdlsymunder its mangled name_ZNSt6thread20hardware_concurrencyEv, on 2026-11-16 at 23:38 UTC. A title process may differ. The cases used are 0 and a, lines 2 and 3 of the raw output in the first comment (the probe also readsrandomdev,randomandsrandom; those results are in a separate pull request).mainhardware_concurrency()0x1FFF)tools/check_conventions.py --base upstream/mainpasses with no error and no warning (the entry is 908 characters, up from 841). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against this call, 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-hardware-concurrency-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/forstd::thread::hardware_concurrency, 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 on3b7ffd7a05c, 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). #9447 addsstd::__sce_v2::_Thrd_hardware_concurrency, a different function with its own debt entry that returns the population count of a thread's affinity mask, and it already conflicts withmaininThreads.cppwithout this change; none of them changes this debt entry or a line that namesstd::thread::hardware_concurrency, and #12315 lists the file but changes nothing in it againstmain. The pull request forsrandomandsrandomdev(the same probe, a different file) changes neither this entry nor this file. 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)