fix(libc): give strerror_r, perror and strerror_s the strerror texts as measured on a PS5 #11127
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11127"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T18:57:13Z.
What
strerror_randperrornow give the textsstrerrorgives, as the systemlibSceLibcInternalof a retail PS5 (firmware 13.60) does. Measured with a homebrew probe from a payload process; the source and console log are in this gist (pstrerr).On the console:
strerror: 0 gives "No error", 1 to 94 the FreeBSD texts, and 95, 96, 97, 100, 1000, -1,INT_MAXandINT_MINgive "error_code=0x%08x". This is what AnyPS5 already returns.strerror_ruses the same texts: 0 gives "No error", 95 gives "error_code=0x0000005f", and 1000 and -1 give "error_code=..." with a return of 0, not 22.ERANGE) and leaves every byte alone, for every number tried, including 0 whose "No error" would fit in 16 bytes; 256 bytes returns 0 with the text. AnyPS5 wrote a truncated text.strerror_rof thelibc.prxthat PPSA31872 ships, read statically (cmp $0x17,%rdx; jbreturning 0x22, thenstrncpy(buffer, text, length - 1)andbuffer[length - 1] = 0): under 23 bytes it returns 34 without writing, otherwise it copies at most length - 1 bytes, zero-fills the rest and returns 0, so a text longer than 22 characters is cut. That agrees with every firmware 13.60 row above; 17 to 255 bytes were not run on the console.perrorprints "x: No error\n", "No error\n" for a null or empty prefix, and "x: error_code=0x00000060\n".errnois never changed.Before this change
strerror_rused the 97-entry table, giving "No error: 0", "State not recoverable" and "Previous owner died" for 0, 95 and 96, and "Unknown error: %d" with 22 for other numbers.perrorand syslog's%mreadstrerror_r, so they follow it.strerror_sandstrerrorlen_snow use the same texts too. A later probe (gist,pstrerrs3) measured them on the console:strerrorlen_sreturns the length of thestrerrortext (8 for 0, 16 for 22, 21 for 95, 96, 97, 1000, -1 andINT_MAX).strerror_swrites that text, and with a buffer of 1 to 16 bytes it truncates, writing "..." over the last three characters when the buffer holds more than 3 bytes ("N..." for 0 in 5 bytes, "Invalid argu..." for 22 in 16), and returns 0, where AnyPS5 returned 34.errnois never changed. Sostrerror_sreadsstrerror_rand returns 0 on truncation, and the libc-internalFreeBsdErrorMessage_nid_no_patchand its header are gone. Its constraint cases (null destination, capacity 0 or aboveRSIZE_MAX) are unchanged: the earlier probes hung after installing a handler, and the debt entry leads with that gap.The
strerrordebt entry said the console's system libc answers differently ("No error information" for 0 and unknown numbers, 95 and 96 named). On firmware 13.60 it gives the same texts as thelibc.prxtitles ship, so the entry now covers all three functions. A nullstrerror_rbuffer returns 34 under 23 bytes, as the length check comes first; at 23 bytes or more the console writes through it, so AnyPS5 throws.Before and after
strerror_rof 0strerror_rof 95strerror_rof 1000 or -1strerror_rwith a 16-byte bufferperror("x")witherrno0strerror_sof 22 in 16 bytesstrerrorlen_sof 95Tested
Head
ff667ba3b7onmaincceb6c3c41. Windows 11, WinLibs GCC 15.2:guest_errors,guest_safe_errors,guest_syslogandguest_host_standard_error_windowspass 3 times out of 3. Linux (WSL Ubuntu, GCC), on the head before thestrerror_schange:guest_errors,guest_safe_errorsandguest_syslogpassed 3 times out of 3 (guest_host_standard_error_windowsis Windows only).guest_errorschecks the measured texts for 0 to 96 and the unknown numbers; for 0, 19, 22, 95 and -1 it checks that 0, 1, 5, 16 and 22 bytes return 34 with an 0xcc canary untouched, that 23 bytes return 0 with the text cut to 22 characters and zero-filled ("Operation not supporte" for 19) and the next byte untouched, and that a null buffer returns 34 under 23 bytes and throws at 23. With the previous head'sErrors.cpp,guest_errorsfails.guest_safe_errorschecksstrerror_sandstrerrorlen_sagainst the measured texts for 0 to 96 and the unknown numbers at every capacity from 1 to the length plus 2, with the ellipsis, a return of 0 and the canaries.tools/check_conventions.pypasses. #10782 also editsperrorinErrors.cpp; the two merge cleanly in either order.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)Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T19:39:11Z.
Review: CHANGES_REQUESTED
Reviewed exact head
e5ad4813f3d278f629c5806f2b85e69415dfca29. The text changes and the separation of the safe-string APIs check out in my native comparison, but one measured buffer case still disagrees with the implementation and the PR's stated success rule.In the published
pstrerr.console.logat revisionac32b35b38ef0b871b47e975877738add7b4c0b0, firmware metadata is0x13600007, the internal symbol resolves successfully, and the error-zero/16-byte case is:The SDK row records the same result. At capacity 256 the log records successful output of an eight-character message instead. Therefore the console's acceptance rule in this evidence is not simply whether the text and its terminator fit: capacity 16 already fits that message, yet the recorded call rejects it and leaves the observed bytes untouched.
This head computes
required = strlen(text) + 1, returns 0 for that call, and overwrites the canary with the message and its terminator. The currentGuestErrorscases miss capacity 16 for error zero: they test 0, 1, 5, one byte short of the inferred length, and the inferred exact length. The exact-length success expectation is not established by the supplied console measurements.Please include the recorded
(error=0, capacity=16)case in the regression, measure the acceptance boundary around it (and representative other errors), and reconcile the implementation, tests and debt/description with that result. I have not guessed a fixed minimum or proposed a special case: the existing log only samples 0, 1, 5, 16 and 256, so it cannot identify the general boundary.Minimal replay, linked against this head's libc or the complete production
Errors.cppin an isolated fixture:Actual native output is
return=0 unchanged=false errno=1234, exit 1. The check expects the recorded return 34 and unchanged buffer, so it fails on this exact head.Additional independent Windows 11 build 26200 / GCC 16.2.0 UCRT / C++20 checks:
Errors.cppandWideConversion.cppfor this head and parent8a29e0883470b827f7eb7081196d0518c2aef0ec. The explicit errno adapter isreturn &errno, identical toProcess.cpp; the fixture uses the actualFileStreamclass for its native stderr object, and its standard-stream preparation adapter requires already-open valid CRT descriptors. An unrelatedwcrtombboundary throws if called. No target error-message or constraint-handler algorithm was mocked.strerrorrecords match both variants. Of 35 internalstrerror_rrecords, head differs only in error-zero/capacity-16; the parent differs in 30. The 35 SDK records equal the internal records. Comparisons include the recorded return/errno, exposed text bytes, terminator flag, first byte and eight bytes of recorded tail canary. Bytes the probe did not record are not treated as console observations.strerror_scalls and 113strerrorlen_scalls per variant across 113 errors, capacities 0 through 80, null destinations, and constraint callbacks. The complete 1,070,336-byte snapshots (returns, lengths, errno, callback counts and all native buffer/canary bytes) are byte-identical before/after. This is a native preservation comparison, not new console evidence for those APIs.GuestErrorsfixture passes at head, and the complete committedGuestSafeErrorsfixture passes against both head and parent: 3/3 external native CTests pass, zero skips, 0.18 s total. Thus the existing suite passing does not cover the console discrepancy above.ae7d59258ea77b090c6be392e2eb2872a9744d00, whitespace and clean-checkout checks pass.I did not run a new PS5 probe, full product/shared-library/NID integration, guest standard-stream/syslog tests, Linux/macOS tests or hosted CI. The referenced console measurements are the author's published evidence. AI-assisted review and native replay (OpenAI Codex).
Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T20:23:36Z.
Review: APPROVED
Re-reviewed exact head
7b9fb0e20472b85267abf79b53e954e01240c991. Approve: my recorded error-zero/16-byte discrepancy is fixed, and the description/debt now distinguish console observations from the statically derived boundary rule.The new guard rejects every length below 23 before touching the destination. Accepted buffers use the stated length-minus-one copy, zero-fill and final terminator; a null accepted-size destination throws explicitly. The 23-byte rule is attributed to the author's static reading of PPSA31872's bundled libc, rather than a new console run. I have not independently read that private binary, and the text correctly leaves 17–255-byte console behavior unmeasured.
Fresh Windows 11 build 26200 / GCC 16.2.0-6 UCRT native checks, compiling the complete revised
Errors.cppandWideConversion.cpp:strerrorand 35strerror_rrows in the previously pinned console log (ac32b35b38ef0b871b47e975877738add7b4c0b0) now match. The specific(0,16)replay returns 34, preserves the buffer, and retains errno1234. The old-head executable still returns 0 and writes, so the negative control remains effective.GuestErrorsandGuestSafeErrorsfixtures, the recorded-row comparison, original minimal reproduction and additional boundary matrix.strerror_scalls plus 113strerrorlen_scalls produce a 1,070,336-byte snapshot identical to both prior-head and original-main snapshots, including all recorded buffer bytes, returns, lengths, errno and 452 callbacks.2f506cacac52cc58887236582b96338c5ad51f62, whitespace and clean-checkout checks pass.The isolated harness retains the disclosed errno adapter (
return &errno, as inProcess.cpp), actualFileStreamclass with already-open CRT-standard-descriptor preparation, and an unused wide-conversion boundary that throws if reached. No error-message algorithm was replaced. I did not run a full shared libc/NID/guest-standard-stream/syslog build, new PS5 probe, Linux/macOS execution or hosted CI. The author's separate full guest-test reports are not my runs.The corrected inline thread remains unresolved/outdated; please resolve it from the author/maintainer side. No remaining finding from my review. AI-assisted re-review (OpenAI Codex).