feat(libSceLibreSsl): implement the per-thread error queue #9529
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9529"
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 2Swagger on 2026-10-22T00:18:39Z.
What
On
main,ERR_get_error,ERR_peek_error,ERR_clear_errorandERR_remove_thread_stateare no-parameter stubs that throwNotImplemented_nid_no_patch. This implements them as LibreSSL's err.c and err.h do, at the same commit #9025 cites.No export of libSceLibreSsl adds an error yet, so guest code always sees an empty queue. The queue is still LibreSSL's general behaviour, not a constant 0. Later LibreSsl implementations (BN, EVP, SSL) can report failures into it through
LibreSslPutError_nid_no_patch(include/Error.hpp). That is the same packing asERR_put_error, which is not in the PS5 export table.ERR_NUM_ERRORSandERR_put_errordo. A 16th push drops the oldest code.ERR_get_errorreturns the earliest code and removes it.ERR_peek_errorreturns it and keeps it. Both return 0 on an empty queue.ERR_clear_errorempties the calling thread's queue.ERR_remove_thread_state(NULL)drops the calling thread's queue.ERR_PACK: library& 0xffin bits 24-31, function& 0xfffin bits 12-23, reason& 0xfffin bits 0-11. They are returned asstd::uint64_t, since LibreSSL returnsunsigned long, which is 64 bits on the PS5 and 32 bits on Windows.thread_localstruct of integers only, enforced by astatic_assert.The PS5 module's LibreSSL version is unknown, so the case that differs between versions throws.
ERR_remove_thread_statewith a non-nullCRYPTO_THREADIDasserts in the cited version, but removes that thread's state in older ones. The queue keeps no file, line or data, as no export reads them.Left out on purpose:
ERR_error_stringandERR_error_string_n: their text depends on whether the error strings are loaded. The cited version loads them throughOPENSSL_init_cryptoand prints names such asunknown libraryeven for code 0. Older versions printlib(0):func(0):reason(0)untilERR_load_crypto_stringsorSSL_load_error_stringsis called. With the version unknown, every code would have to throw.ERR_peek_last_error: it is exported only by libSceLibreSsl3, a separate module with noERR_get_errorand no export that adds errors. Whether it shares a queue with libSceLibreSsl is unknown.The debt entry in
docs/dev/debt/libSceLibreSsl.mdrecords the above, and the pending count drops from 399 to 395.core/libs/prx/libSceLibreSsl/CMakeLists.txtis new here, as it is in the other open LibreSsl PRs (#8956, #9025, #9033, #9041, #9043, #9047, #9446, #9448). Whichever lands first, I will rebase onto it and keep both source files and tests.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, on headd21dd0637(this branch merged withmain).Before: on
main, all four exports are stubs that callNotImplemented_nid_no_patch(core/libs/prx/libSceLibreSsl/Export.cpplines 515, 535, 540 and 545), and no LibreSsl error test exists. The new test was not run againstmain.After:
guest_libressl_errorpasses. Each case it checks passed:ERR_get_errorandERR_peek_errorreturn 0.0x1ff, function0x1fffand reason0x1fffreturns exactly0xFFFFFFFF. This checks that each field is masked asERR_PACKdoes. It does not check the 64-bit return width: no code uses the upper 32 bits, so a 32-bit return type would pass too.ERR_clear_errorempties a queue holding two codes, and a later push and get work.std::threadstarts with an empty queue and reads only its own code. The main thread keeps its code, and the other thread's code never appears on it.ERR_remove_thread_state(nullptr)empties the queue.Also:
guest_libressl_error,guest_libressl_digest,guest_libressl_des,guest_libressl_x509_errors,guest_libressl_runtime,guest_libressl3_digest,guest_ssl,guest_ssl_load,guest_ssl_ps5_readers,guest_ssl_transport_kernelandguest_ssl_transport_netpass (11/11, 0.86 s).python tools/check_conventions.py --base upstream/main: all checks passed.python tools/check_test_registration.py build: passed, every test executable is registered with ctest.git merge-tree --write-tree upstream/main HEAD: clean.Linux: Ubuntu 24.04 under WSL2, GCC 13.3.0, Release,
BUILD_TESTING=ON:guest_libressl_errorpasses ond21dd0637.A reviewer reported a passing Linux run (Ubuntu 26.04, GCC 15.2.0), including a clean run under ASan and UBSan, in the comments; that run was on the original commit
ca32e706e, before the refreshes. Not tested on macOS. Not tested with a title.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T00:23:58Z.
Review: CHANGES_REQUESTED
The four queue functions and their tests look internally consistent with the cited LibreSSL implementation: the 16-slot ring retains 15 codes, preserves FIFO get/peek semantics, masks ERR_PACK fields, and keeps state thread-local. The focused test and full-build outcome are author-reported; I did not run a local build. Current hosted conventions, intake, and labels checks pass, while no product build/test job is present.
There is one merge-order blocker under CONTRIBUTING.md. The current overlap scan reports shared new
core/libs/prx/libSceLibreSsl/CMakeLists.txtanddocs/dev/debt/libSceLibreSsl.mdwork with #9025, #9033, #9041, #9043, #9047, #9446, and #9448. This PR says it will rebase whichever lands first, but the checklist saysDepends on: none, and no ordering agreement is recorded. Please coordinate with the affected authors on which shared-file change lands first, then declare the agreed prerequisite inDepends onand rebase/resolve the combined CMake and debt changes. I’m requesting changes for that repository-required overlap coordination, not for the queue implementation.Imported from boykopovar/AnyPS5. Originally posted by 2Swagger on 2026-10-22T00:35:55Z.
Thanks for the review, @MarcZX10. No overall order has been agreed among the overlapping LibreSsl PRs, so I'm proposing that this PR goes last and have declared Depends on: #9025, #9033, #9041, #9043, #9047, #9446, #9448. Nobody else needs to rebase because of it; I'll rebase onto each one as it lands (one source and one test in the shared CMakeLists.txt, plus the debt file's pending count).
@HQasper @VakzOs @AlxcBTW, could you confirm you're fine with this PR merging after yours? If you'd prefer a different order, say so here and I'll update Depends on.
Imported from boykopovar/AnyPS5. Originally posted by VakzOs on 2026-10-22T07:30:21Z.
Fine with me, thanks for coordinating. #9047 doesn’t depend on any of the other LibreSsl PRs: if one of #9025, #9033, #9041, #9043, #9446 or #9448 lands before it, I’ll rebase #9047 onto it (one source/test entry in the shared CMakeLists.txt plus the debt file’s pending count), so nobody has to wait for it.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T07:42:54Z.
Review: COMMENTED
Linux run, since the description says it was not tested on Linux: it passes, and the per-thread queue runs clean under ASan and UBSan.
Machine: Linux, Ubuntu 26.04, GCC 15.2.0, x86-64. Head
ca32e706emerged withgit merge --no-commitonto currentmaind6eafa54d(clean).BUILD_TESTING=ON,ANYPS5_RELINKER_ONLY=OFF):guest_libressl_errorandpatched_librariespass (2/2).-fsanitize=address,undefined -fno-sanitize-recover=undefined -O1 -g,ANYPS5_ENABLE_ASAN=ON, leak detection off):guest_libressl_error_testsprintsguest_libressl_error: okand exits 0 with no reports.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:38:14Z.
I rechecked current head
ca32e706e8: current conventions and diff-check pass, and it merges cleanly with today’smain. The focused Windows and independent Linux queue tests pass per the reports in this PR. The branch is 1 ahead / 119 behind currentmain(merge basea6dcea927); please refresh and rerunguest_libressl_error, conventions, test-registration and the updated overlap scan. TheDepends onlist now declares the shared-file landing order, and #9047’s author has acknowledged it; please keep the remaining author coordination up to date before merge.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T20:01:05Z.
Review: APPROVED
Reviewed current head 43315af3954f372e49f2e7047f187b7883aa2c7c (exactly
43315af395): the per-thread 16-slot/15-error ring, FIFO get/peek behavior, masking, clear, and null thread-state removal match the cited LibreSSL implementation; unsupported non-null thread IDs still throw and are documented. The focused test covers ordering, overflow, masking, thread isolation, and clear/removal. The author reports 11/11 focused and related tests on this exact head, andgit merge-treewith current main is clean; current hosted conventions and labels checks pass. The branch explicitly depends on older shared-file PRs #9033, #9446, and #9448; newer LibreSSL changes should stack on this PR where required. I did not run the tests locally.