Repository navigation
docs(debt): record the printf floating-point results on firmware 11.60 - #22031
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
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)
/* printf number formats %a, %A, %e, %f and %g of snprintf of libSceLibcInternal.sprx (dlsym) on firmware 11.60 (
the entries follow the libc.prx that titles ship, 'checked by running the copies' on a CPU; the system libc of the console may differ). Prototype int
snprintf(char*, size_t, const char*, ...). Fixed 64 byte buffer, no widths above 40, never %*d. No subnormal input. Group a: %.3a, %a, %A, %-010.3a of
1.0, 0.5, 0x1.fffp0, 0x1.ffffffffffffep+1023, 0x1p-1022 and a carry case; b: %e %f %g of 0.1, 1e22, 1e23, 123456789012345678.0, 2.2250738585072014e-308,
%.20e, %.0f of 0.5/1.5/2.5, %.30f of 0.1. The text is printed; 50 calls at most, each guarded. */
#include <math.h>
typedef int (*sp_fn)(char*, size_t, const char*, ...);
static sp_fn sp;
static void fmt(const char* id, const char* what, const char* f, double v) {
char buf[96];
memset(buf, 0, sizeof buf);
int rc, e, r = -99;
CALL(rc, e, (r = sp(buf, 64, f, v)));
char ex[180];
snprintf(ex, sizeof ex, "rc=%d text='%.70s' signal=%d", r, guard_sig ? "-" : buf, (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);
sp = (sp_fn)(hl ? dlsym(hl, "snprintf") : 0);
char ex[8];
snprintf(ex, sizeof ex, "%d%d", !!hl, !!sp);
probe_case("0", "dlopen LibcInternal; dlsym snprintf (1 yes, 0 no)", 0, 0, ex);
if(!sp) { probe_end(); return 0; }
static const double av[] = {1.0, 0.5, 1.99951171875, 1.7976931348623157e308, 2.2250738585072014e-308, 1.0 - 1.1102230246251565e-16, 3.5};
static const char* const an[] = {"1.0", "0.5", "0x1.fffp0", "DBL_MAX", "DBL_MIN", "1-2^-53 (carry)", "3.5"};
char id[16], w[60];
for(size_t i = 0; i < sizeof av / sizeof av[0]; i++) {
snprintf(id, sizeof id, "a1.%zu", i); snprintf(w, sizeof w, "%%.3a of %s", an[i]); fmt(id, w, "%.3a", av[i]);
snprintf(id, sizeof id, "a2.%zu", i); snprintf(w, sizeof w, "%%a of %s", an[i]); fmt(id, w, "%a", av[i]);
snprintf(id, sizeof id, "a3.%zu", i); snprintf(w, sizeof w, "%%A of %s", an[i]); fmt(id, w, "%A", av[i]);
snprintf(id, sizeof id, "a4.%zu", i); snprintf(w, sizeof w, "%%-010.3a of %s", an[i]); fmt(id, w, "%-010.3a", av[i]);
}
static const double bv[] = {0.1, 1e22, 1e23, 123456789012345678.0, 2.2250738585072014e-308};
static const char* const bn[] = {"0.1", "1e22", "1e23", "123456789012345678.0", "DBL_MIN"};
for(size_t i = 0; i < sizeof bv / sizeof bv[0]; i++) {
snprintf(id, sizeof id, "b1.%zu", i); snprintf(w, sizeof w, "%%e of %s", bn[i]); fmt(id, w, "%e", bv[i]);
snprintf(id, sizeof id, "b2.%zu", i); snprintf(w, sizeof w, "%%g of %s", bn[i]); fmt(id, w, "%g", bv[i]);
}
fmt("b3.0", "%f of 0.1", "%f", 0.1);
fmt("b3.1", "%.20e of 0.1", "%.20e", 0.1);
fmt("b3.2", "%.0f of 0.5", "%.0f", 0.5);
fmt("b3.3", "%.0f of 1.5", "%.0f", 1.5);
fmt("b3.4", "%.0f of 2.5", "%.0f", 2.5);
fmt("b3.5", "%.30f of 0.1", "%.30f", 0.1);
fmt("b3.6", "%.1f of 0.25", "%.1f", 0.25);
fmt("b3.7", "%.1f of 0.35", "%.1f", 0.35);
probe_end();
return 0;
}stdoutAI-assisted (Claude Code). |
What
The
%a and %Aand%e, %f and %gentries indocs/dev/debt/libc.mddescribe this library's own formatter for floating-point conversions, which follows thelibc.prxthat titles ship, and both say that the result is "not measured on a console". A probe has now called the console'ssnprintf(libSceLibcInternal.sprx) from a payload process on firmware 11.60 with 46 floating-point cases. The pull request changes the two entries through a debt fragment, as the contribution rules ask, so that each says it was measured on a console in the cases below; no code changes.The 28 hexadecimal cases are the values 1, 0.5, 1.99951171875, 3.5,
DBL_MAX,DBL_MINand 1 - 2^-53, each with%.3a,%a,%Aand%-010.3a(cases a1 to a4, lines 3 to 30). Among them,%.3aofDBL_MAXgave0x2.000p+1023and of 1 - 2^-53 gave0x2.000p-1, a carry that stays in the leading digit as the entry says (lines 15 and 23),%aofDBL_MAXgave0x1.fffffffffffffp+1023(line 16), and%-010.3aprinted the same text as%.3a, so the-overrides the0(for example lines 6 and 10). The 18 decimal cases are%eand%gof 0.1, 1e22, 1e23, 123456789012345678.0 andDBL_MIN(lines 31 to 40), and%f,%.20e,%.0fof 0.5, 1.5 and 2.5 and%.30fof 0.1 and%.1fof 0.25 and 0.35 (lines 41 to 48). Ties go up:%.0fof 0.5, 1.5 and 2.5 gave1,2and3(lines 43 to 45), as the entry's "rounds half up" says, and%.30fof 0.1 gave0.100000000000000005550000000000(line 46).The formatter of this library (
HexFloatandDecimalFloatinWindowsFormatting.hpp), built into a local test program that is not part of this pull request, gives the same text in all 46 cases. The emulator itself was not run.Not measured on the console:
long double, infinities and NaN, other precisions and flags, widths beyond the cases above, the digits of%fof 1e22 (the entry's remark about about 7% of long outputs ending one unit lower is a statement about the titles' libraries and stays as it is), the wide printf family, 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 takessnprintfwithdlsym, on 2026-11-16 at 23:37 UTC. A title process may differ. The cases are 0 to b3.7, lines 2 to 48 of the raw output in the first comment (line 2 shows that both symbols were found).main(formatter run locally)%a,%A,%.3a,%-010.3acases%eand%gcases%f,%.20e,%.0f,%.30f,%.1fcasestools/check_conventions.py --base upstream/mainpasses with no error and no warning (the%a and %Aentry is 896 characters, up from 749, the%e, %f and %gentry 995, up from 937). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against these calls, Linux and macOS formatting, 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-printf-float-console-1160.md, a new file),core/libs/prx/libc/include/WindowsFormatting.hpp, which the two entries link, or the two debt entries it changes, found by reading the changed files of all 1611 open pull requests at about 01:36 UTC, by reading what they change indocs/dev/debt/libc.mdand in the fragments underdocs/dev/debt/changes/for%a and %A,%e, %f and %g,HexFloatandDecimalFloat, and by searching their titles and branch names for the same names. The branch was test-merged on 2026-11-17 at about 02:03 UTC againstmain2354a37269a(the branch is based on140d6a4546b, an ancestor of it) and merges into it without a conflict;tools/debt_fold.py --checkapplies the fragment to thelibcdebt file ofmainwithout 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 each, and no other fragment changes those entries. Three pull requests changeWindowsFormatting.hpp: #11332 (fix(libc): bound narrow formatting fields) rewritesHexFloatandDecimalFloatto write into an output object instead of returning a string, #9087 changes thesnprintf_sandsscanf_spaths, and #12315 lists the file but changes nothing in it againstmain; all three already conflict withmainwithout this change and conflict in the same way with it, because this change does not touch the file, so none of them conflicts only with this change, and the 46 cases above were compared against the code onmain, not against the rewrite in #11332. About a dozen pull requests that addstd::__sce_v2locale entries tolibc.md(for example #16516 and #17610) refer to the%e, %f and %gentry in their own text without changing it, and no open pull request changes either of the two entries. 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)