fix(libc): write the constraint message and return from the default handler #9935
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9935"
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-22T22:37:10Z.
What
The default runtime-constraint handler of
libccalledstd::abort()without writing anything. It now writes the message and a newline to the gueststderrand returns, so an_sfunction called with no handler installed returns its error to the title instead of ending it.This follows the default handler of the
libc.prxtitles ship insce_module/, which this module stands for. JJenkx read it from the disassembly of the copies in PPSA13934, PPSA07923 and PPSA05916 (#9087 comment):set_constraint_handler_sstoreshandler ? handler : default, and the default callsfputs(message, stderr),fputc('\n', stderr)and returns, whileabort_handler_smakes the same two calls and then callsabort. Thewcsrtombs_sdebt entry already describes that handler the same way. The console'slibSceLibcInternal.sprx(firmware 13.60, measured for #9087) has a different default that ends the process after writing; that module is not this one, and the debt entry says so.libSceAmpr's re-export shares the header, so its default handler changes the same way.Tested
main(f80ce6cec1, with #11121):7aa063d91c. The only conflict wasdocs/dev/debt/libc.md: kept main'slocaleconventry (and its removal of thesetlocaleentry) and this PR'sset_constraint_handler_swording.guest_safe_errorspasses three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC);check_conventionspasses.main(f26434afa3, with #10706):0bae438695. The test now takes its declarations from the libc headers;SonyCrt.hppincludesApi.hppinstead of declaringfputs/fputcagain.guest_safe_errors,guest_crt,guest_bounds_checking,guest_qsortandguest_wide_stringspass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC);public_headersaudit andcheck_conventionspass.main(a2c36d4ed6, with #12589):9260172a4c.guest_safe_errorsnow expects the default handler to writestrerror_s: bad argument\ntwice, the message #12589 passes.guest_safe_errors,guest_crtandguest_bounds_checkingpass three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL Ubuntu, GCC);check_conventionspasses.Windows 11, MinGW (winlibs).
guest_safe_errorsnow installs the default handler withset_constraint_handler_s(NULL), redirects the gueststderrto a file and checks that twostrerror_sviolations returnEINVAL(22) and writestrerror_s: bad argument\ntwice. Onmainthe test ends with0xc0000409at the first violation; with the change it passes.guest_safe_errors,guest_crt,guest_bounds_checking,guest_qsortandguest_wide_stringspass three runs in a row.tools/check_conventions.pypasses.main(ba8dcc6ae8, with #13220, which removes the duplicate write-watch test names that failed the macOS jobs):d7b7f9ad59.guest_safe_errorspasses three runs in a row on Windows (MinGW, GCC 15.2).tools/check_conventions.pypasses.main(98346b748c, with #9688'sqsort_sentry):91d71873be. The only conflict wasdocs/dev/debt/libc.md: kept main'sqsort_sentry and this PR'sset_constraint_handler_swording.guest_safe_errorspasses three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC 16.2).tools/check_conventions.pypasses.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)set_constraint_handler_sdebt entry and edits the same lines; merge order only; #9688 has merged); #9087 lands after this PR and will be refreshed then; #10706 removes the test declarations this PR adds toGuestSafeErrors.cpp(merge order only); #11621 (B-Howell) addslibc.mdentries next to the one this PR edits (merge order only); #12598 (JJenkx) rewrites theqsort_sentry next to theset_constraint_handler_sentry this PR edits (merge order only)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T23:58:12Z.
Review: APPROVED
Reviewed exact head
f96b6d2fb8e39db1f0fb8d9c5f3777aee65833bcagainst currentmain895f47f4eeaf56048b9a7080b7c01a9a47cf0ecf. The default handler writes its supplied message and newline to gueststderrand returns; this is the behavior attributed to the three shippedlibc.prxdisassemblies, and the debt entry separately retains the measuredlibSceLibcInternal.sprxprocess-termination difference. The regression redirects gueststderr, checks two exact messages, and verifies both violating calls returnEINVAL. The author reports five focused/neighboring Windows tests passing three repetitions after merging main; I did not rerun the C++ suite locally. I independently ran current-maingit diff --checkand conventions; both pass. Hosted eligibility, conventions, intake, labels, relinker, ASan, register-context and write-watch checks pass; full Linux/Windows product builds are skipped by repository policy. The declared #9087 debt-text integration is appropriate and no intervening current-main commit changes the reviewed source, test or debt paths. I found no remaining issue in the reviewed change.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T23:22:55Z.
Review: APPROVED
Re-checked — new head, looks good
The current head retains the reviewed default-handler behavior and test, and the rebase passes the available static and hosted checks.
What I ran
Reviewed PR head
7aa063d91cb079e5d82cdb64aff5731288b0406fagainst basef80ce6cec1cad29aa45bd0bf6d8062a714c18e03; refreshed currentmainisf46f453a56f91d77e29ce0cbd7fe5bfb2fb69834. The merge preview with currentmainis clean (treea678797797647eee21884965d95daac02477dea6). Environment: Linux 6.1.0-54-amd64 x86_64; no local compiler, build, or tests run.Results
mainguest_safe_errorsand neighboring testsUnedited output from local and hosted checks
The focused test results are author-reported in the PR description; they are not local runs.
Negative control
mainwithout this PR.0xc0000409at the first violation.Findings
Blocking
None found in the current head. It writes the supplied message and newline to guest
stderr, then returns to the caller; the test exercises two violations and confirms both returnEINVALand produce the expected output.Non-blocking
The PR records merge-order dependencies for adjacent libc debt and test changes. Preserve that order if one of those dependent changes lands first.
Sources
Not verified
I did not build or run tests locally, independently reproduce the author's Windows/WSL2 tests, or verify behavior on a physical console. The hosted Linux and Windows product jobs were skipped.
Pull request closed