Skip to content

feat(libSceLibreSsl): implement SSL_CTX_ctrl, SSL_CTX_callback_ctrl, SSL_CTX_set_msg_callback, SSL_CTX_set_verify and SSL_CTX_set_session_id_context - #11138

Merged
oneandonlydean merged 53 commits into
boykopovar:mainfrom
ahmadmuj:fix/anyps5-lssl-sslctx-fields
Nov 5, 2026

Conversation

@ahmadmuj

@ahmadmuj ahmadmuj commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements SSL_CTX_ctrl, SSL_CTX_callback_ctrl, SSL_CTX_set_msg_callback, SSL_CTX_set_verify and SSL_CTX_set_session_id_context in libSceLibreSsl, which threw and were declared without parameters. SSL_CTX_ctrl is what SSL_CTX_set_options, set_mode, set_session_cache_mode, set_read_ahead and friends expand to, so it's the one most TLS setup code hits.

This stacks on #10483 and uses its LibreSslCtx / LibreSslCtxInternal. The diff carries #10483's commits (a local merge with main) until it merges. #10483's functions and test are unchanged; LibreSslCtxInternal goes from beforeQuietShutdown[292] / quietShutdown / rest[168] to every ssl_ctx_internal_st field named at its offset. quietShutdown stays at 292 and the size stays 464. The slots #10485 uses keep its names (newSessionCb 24, appVerifyCallback 48, ... alpnSelectCbArg 408), so its planned move onto #10483's types is a type swap.

Behaviour follows LibreSSL 2.5.4 ssl_lib.c and s3_lib.c (SSL_CTX_ctrl falls through to ssl3_ctx_ctrl, the same for the callback version):

Export Behaviour
long SSL_CTX_ctrl(SSL_CTX*, int cmd, long larg, void* parg) options / mode set and clear (return the new mask), read_ahead, max_cert_list, session cache size and mode (return the old value; read_ahead and cache mode keep the low 32 bits), the 11 session stats, max_send_fragment (512..16384, else 0), msg callback arg, servername arg, status arg, ticket keys get/set (null parg returns 48, a length other than 48 queues 0x14FFF145 and returns 0), extra chain certs get. Commands 2, 5, 6 and 7 queue 0x14FFF042 and return 0; 1 returns 0. Commands not in 2.5.4's switch return 0, as that release does
long SSL_CTX_callback_ctrl(SSL_CTX*, int cmd, void (*)(void)) 15 msg callback, 53 servername, 63 status, 72 ticket key callback (return 1); 5 queues 0x14FFF042, returns 0; anything else 0
void SSL_CTX_set_msg_callback(SSL_CTX*, cb) internal->msg_callback = cb
void SSL_CTX_set_verify(SSL_CTX*, int mode, cb) verify_mode = mode, internal->default_verify_callback = cb
int SSL_CTX_set_session_id_context(SSL_CTX*, const unsigned char*, unsigned int) length > 32 queues 0x14FFF111 and returns 0 with no write; else copies, sets the length, returns 1. Bytes past the new length are kept, as in 2.5.4

Throws: control commands 3, 4, 14, 20, 83, 91, 92, 94, 118 and callback commands 6 and 7 (they use cert, session table, DH, ECDH, stack or group state no export builds yet), a null context, a null internal state (2.5.4 reads ctx->internal->cert on entry for every command), a null output for command 82, and a null session ID with a nonzero length. Errors go through the existing LibreSslPutError_nid_no_patch as SSLerrorx does (lib 20, function 0xfff), and the ERR debt entry lists the three additional SSL_CTX producers.

The debt entry records the source and the throwing commands. The merged branch has 181 pending exports; main has 191.

Tested

Ubuntu 24.04 on WSL2, GCC 13.3, Release. Head 300af5cbcef1 merges main a0a8b1b1733c and #10483 2c6493028f9f.

The selected build passes. Ordinary LibreSSL tests pass: 60/60. Public headers pass: 65/65. Conventions and whitespace checks pass.

SslCtx.cpp and both context tests are byte-identical to the published head. The merge removes duplicate parent layout definitions and keeps the expanded fields. The parent offsets and structure size stay unchanged. Earlier differential and mutation checks are not repeated.

No console, title, Windows or macOS run. No full build, full ctest, patched or oracle run.

Checklist

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Progress report (a0a8b1b → 300af5c)

📈 System libraries: 26.83% (+0.02%, +8 implemented functions)

✅ 8 implemented
Library Name
libSceLibreSsl SSL_CTX_get_cert_store_nid_postfix
libSceLibreSsl SSL_CTX_get_verify_mode_nid_postfix
libSceLibreSsl SSL_CTX_set_default_passwd_cb_nid_postfix
libSceLibreSsl SSL_CTX_set_default_passwd_cb_userdata_nid_postfix
libSceLibreSsl SSL_CTX_set_msg_callback_nid_postfix
libSceLibreSsl SSL_CTX_set_quiet_shutdown_nid_postfix
libSceLibreSsl SSL_CTX_set_session_id_context_nid_postfix
libSceLibreSsl SSL_CTX_set_verify_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl 204/427 (47.78%) 212/427 (49.65%) +1.87%

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the PR-specific SslCtx.cpp behavior against pinned LibreSSL 2.5.4 ssl_lib.c / s3_lib.c, with #10483 as the declared layout dependency. I checked the command dispatch and return conventions for option/mode masks, read-ahead and cache settings, session counters, fragment bounds, ticket-key buffer length, callback setters, session-id context length, and the explicitly unsupported commands. The source-derived error reasons and the throw-vs-return boundaries are documented in the PR and debt entry. The base SSL_CTX layout dependency #10483 has a current review and remains open as a stack prerequisite.

Local checks on the submitted tree:

  • GCC 12.2 syntax-only compilation of SslCtx.cpp, GuestLibreSslSslCtx.cpp, and GuestLibreSslSslCtxFields.cpp: passed.
  • python3 tools/check_conventions.py --base upstream/main --head HEAD: passed.

The PR reports a byte-for-byte differential against real LibreSSL 2.5.4 for the context and internal layouts, command results, changed bytes and error queue, plus focused regression and mutation tests. Hosted eligibility, conventions, intake, labels and report pass; product/library build jobs are skipped. I did not independently run the LibreSSL runtime differential in this environment. No blocking issue found in this PR-specific change.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 15827 docs/dev/debt/libSceLibreSsl.md L10

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 10485 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
core/libs/prx/libSceLibreSsl/src/SslCtx.cpp
core/libs/tests/GuestLibreSslSslCtx.cpp
docs/dev/debt/libSceLibreSsl.md
PR 10486 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10508 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10570 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10878 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10915 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11003 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11359 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11466 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 12928 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13266 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13285 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13486 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13546 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13547 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13860 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13877 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 14115 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 14212 docs/dev/debt/libSceLibreSsl.md
PR 15278 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15279 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15280 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15281 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
core/libs/prx/libSceLibreSsl/src/SslCtx.cpp
core/libs/tests/GuestLibreSslSslCtx.cpp
docs/dev/debt/libSceLibreSsl.md
PR 15480 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15481 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15482 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15483 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15737 docs/dev/debt/libSceLibreSsl.md
PR 15994 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md

@ycbuzi

ycbuzi commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

A Windows run of this head, since the description doesn't cover Windows: Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release. 00846cdbfa merged onto main 97d33464c5 with no conflicts.

  • The test executables build without errors. There are no warnings.
  • guest_libressl_ssl_ctx, guest_libressl_ssl_ctx_fields pass both runs of ctest --repeat until-fail:2.
  • No negative control: the functions live in source files this PR adds.

AI-assisted: yes (Claude Code)

ahmadmuj added a commit to ahmadmuj/AnyPS5 that referenced this pull request Oct 26, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@ahmadmuj One change in the tests: please remove the two loops that require unsupported commands to throw, at GuestLibreSslSslCtxFields.cpp:319 (SSL_CTX_ctrl commands 3, 4, 14, 20, 83, 91, 92, 94, 118) and :336 (SSL_CTX_callback_ctrl commands 6 and 7). These are valid upstream commands that are only unimplemented here because the cert/session/DH/ECDH/group state doesn't exist yet, so the assertions would fail as soon as one of them is implemented. SslCtx.cpp can keep refusing them as documented in the debt entry; no new implementation is needed.

Please keep the supported-command, error-queue and full-buffer regressions and the real invalid-argument tests. #10483 still needs to land first.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@ahmadmuj

ahmadmuj commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

@AdnanKhan-ak47 thanks for the merge offer. I merged it myself in the end so the branch stays merge-commit only: head is now 0211156, with main e450145 and #10483's rebased head a481700. Same keep-both resolutions as yours. The pending count is 280, recounted from the merged Export.cpp (main's line says 292 but has 290 stubs since the GeneralName PR). All 40 guest_libressl* tests, public_headers 65/65 and conventions pass. Agreed on #11143: whichever lands second gets one more main merge from me.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 1, 2026
ahmadmuj added a commit to ahmadmuj/AnyPS5 that referenced this pull request Nov 1, 2026
# Conflicts:
#	docs/dev/debt/libSceLibreSsl.md
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 2, 2026
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 4, 2026
@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ AMD GPU test: passed

PR head 2458235 merged onto main b11c7bf · tested 2026-11-04 17:58 UTC · 18 min

GPU AMD Radeon RX 6300 (RADV NAVI24), driver Mesa 25.2.8-0ubuntu0.24.04.4, Vulkan 1.4.318
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-42-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,227 passed · 11 failed (0 new, 9 also fail on main, 2 unstable on main) · 9 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,247 of 3,894 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (966 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 120.1 s, ⚠️ agc_driver_graphics 79.8 s, ⚠️ agc_driver_graphics_maps_fallback 66.2 s, ⚠️ public_headers 64.6 s, ⚠️ agc_driver_bda_device 40.2 s
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_pipeline_journal: failed in 8 of the last 10 main runs
agc_driver_two_sample_alpha_to_coverage_sample_mask_export: failed in 3 of the last 10 main runs
Failing on main too (9, not counted against this PR)
agc_driver_alpha_to_coverage_sample_mask_export
agc_driver_guest_memory_lifetime_direct
agc_driver_image_table
agc_driver_job_manager_compute_capacity
agc_driver_native_depth_bda_clear
agc_driver_native_depth_buffer_clear
agc_driver_native_depth_clears
agc_driver_native_multisample_depth
agc_driver_submit_progress
Validation IDs already present on main (8 IDs in 731 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (731 tests): agc_compute_pipeline_replay, agc_driver_address_draw_space_reuse, agc_driver_address_draw_space_reuse_held, agc_driver_address_draw_space_reuse_off, agc_driver_address_draw_space_reuse_transitions, agc_driver_address_draw_space_reuse_verify, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, and 723 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store_image_copy, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_partially_unmapped_plane, agc_driver_depth_plane_unmapped_plane, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store_image_copy, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_partially_unmapped_plane, agc_driver_depth_plane_unmapped_plane, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
VUID-VkSamplerCreateInfo-addressModeU-01079 (1 test): agc_driver_image_gather_volume
VUID-VkSamplerCreateInfo-addressModeU-parameter (1 test): agc_driver_image_gather_volume
VUID-VkSamplerCreateInfo-addressModeV-parameter (1 test): agc_driver_image_gather_volume
VUID-VkSamplerCreateInfo-addressModeW-parameter (1 test): agc_driver_image_gather_volume
Skipped (9)
agc_driver_copied_writer_label_order: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_copied_writer_label_order_drain: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_float16_unused_nan_payloads: skipped, the device has no native f16 conversions with RTE rounding and kept f16 denormals
agc_driver_gcn_display_present: skipped, no display: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
agc_driver_linear_target_direct_write_completion: skipped, the device does not keep host imports write-watched, so no completion stamp over the target is tracked
agc_driver_ngg_vertex_wave_reduction: skipped, s3 describes a 32-lane wave only on 32-lane subgroups, and the device has 64 lanes
agc_driver_scattered_runs: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_vertex_elected_atomic_max: skipped, the device runs vertex programs in subgroups, so they keep their cross-lane reductions
Reproduce
git fetch origin 2458235ff62117acbdf3daad2e09b20fede6d147 b11c7bf84f5d2f636ff60166cc3371bd071e24d5
git checkout b11c7bf84f5d2f636ff60166cc3371bd071e24d5 && git merge --no-ff 2458235ff62117acbdf3daad2e09b20fede6d147
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 12 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 16 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants