Play your Steam library's Windows games on a jailbroken PS5.
C++
Enable thread safety for concurrent Steam TLS
Leonardo Lobatoebd0eddb10c2
diff --git a/cmake/SteamBackend.cmake b/cmake/SteamBackend.cmakeindex 1221cf4..4d0ebee 100644--- a/cmake/SteamBackend.cmake+++ b/cmake/SteamBackend.cmake@@ -49,6 +49,17 @@ foreach(required_path IN ITEMSendif()endforeach()+# Threading changes public context layouts, so headers and all linked archives must be rebuilt together.+set(playden_mbedtls_config "${PLAYDEN_STEAM_PREFIX}/include/mbedtls/mbedtls_config.h")+string(JSON expected_mbedtls_config_hash GET "${playden_dependency_lock}"+ steam_network_probe mbedtls config_sha256)+file(SHA256 "${playden_mbedtls_config}" actual_mbedtls_config_hash)+if(NOT actual_mbedtls_config_hash STREQUAL expected_mbedtls_config_hash)+ message(FATAL_ERROR "Pinned Mbed TLS pthread configuration mismatch. "+ "Rebuild with scripts/network-deps/prepare-${playden_steam_dependency_platform}-deps.sh")+endif()+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${playden_mbedtls_config}")+file(GLOB playden_curl_headers CONFIGURE_DEPENDS"${PLAYDEN_STEAM_PREFIX}/include/curl/*.h")string(JSON expected_header_count LENGTH "${playden_dependency_lock}"@@ -107,6 +118,19 @@ if(APPLE AND NOT PLAYDEN_PLATFORM_PS5)"-framework CoreServices")endif()+# Require the threading implementation to link, catching new headers with old host archives.+include(CheckCXXSourceCompiles)+set(CMAKE_REQUIRED_LIBRARIES playden_curl_8_22)+unset(playden_mbedtls_threading_links CACHE)+check_cxx_source_compiles("#include <mbedtls/threading.h>+int main() { mbedtls_threading_mutex_t mutex; mbedtls_mutex_init(&mutex);+ int result = mbedtls_mutex_lock(&mutex); mbedtls_mutex_unlock(&mutex);+ mbedtls_mutex_free(&mutex); return result; }" playden_mbedtls_threading_links)+unset(CMAKE_REQUIRED_LIBRARIES)+if(NOT playden_mbedtls_threading_links)+ message(FATAL_ERROR "Mbed TLS pthread headers/libraries mismatch. Rebuild network dependencies together.")+endif()+add_library(playden_steam_http STATIC"${CMAKE_SOURCE_DIR}/src/steam/backend/http_client.cpp""${CMAKE_SOURCE_DIR}/src/steam/backend/ws_client.cpp"@@ -191,6 +215,10 @@ function(playden_register_steam_backend_tests)target_link_libraries(native_resolution_cache_test PRIVATE playden_steam_http)add_test(NAME native_resolution_cache COMMAND native_resolution_cache_test)+ add_executable(mbedtls_threading_test "${CMAKE_SOURCE_DIR}/tests/mbedtls_threading_test.cpp")+ target_link_libraries(mbedtls_threading_test PRIVATE playden_steam_http)+ add_test(NAME mbedtls_threading COMMAND mbedtls_threading_test)+add_executable(http_client_test "${CMAKE_SOURCE_DIR}/tests/http_client_test.cpp")target_link_libraries(http_client_test PRIVATE playden_steam_http)add_test(NAME http_clientdiff --git a/dependencies.lock.json b/dependencies.lock.jsonindex cf630fe..270ab5d 100644--- a/dependencies.lock.json+++ b/dependencies.lock.json@@ -74,7 +74,12 @@},"mbedtls": {"version": "3.6.6",- "source_sha256": "8fb65fae8dcae5840f793c0a334860a411f884cc537ea290ce1c52bb64ca007a"+ "source_sha256": "8fb65fae8dcae5840f793c0a334860a411f884cc537ea290ce1c52bb64ca007a",+ "config": [+ "MBEDTLS_THREADING_C",+ "MBEDTLS_THREADING_PTHREAD"+ ],+ "config_sha256": "92f08b8ed84a09b84ff9a1728a2b7868c45dabdcdda6574dc8ae3b64d290c035"},"ca_bundle": {"version": "2026-09-25",@@ -95,11 +100,11 @@"curl/websockets.h": "05b70dbce5274aa6e360703bb17d67a0390fea18bf4437745a25b08b55d6962b"},"ps5_archives": {- "libcurl.a": "4d3a53c0fb710931a6c1c99a8b540d2a4298d491a17813f889d5e0ae9c60cb37",+ "libcurl.a": "48073d585213b7698514c3d15ee9f85f6fa74ba8d7f3728116b96271601eb951","libeverest.a": "beb61a9fb21e7a9cc016f0ad7fc9027cc09da674a3f2c743bfa8d1bfe06de00c",- "libmbedcrypto.a": "ac7d5c54ed457d4e4948dfecd80f9f2157c4b164b4770ab706218238d74557a0",- "libmbedtls.a": "a760fcc1b4a0cd9c954f838b06ae9cf81353166430c4a9fba6a4b1e404a2ffb1",- "libmbedx509.a": "cf958baa32e5d20631b8d873365eb81589487e4fbb800faab86a6bed68426e65",+ "libmbedcrypto.a": "10702b58c100c6c6dfde592949a8282c708518c030f6672b6bed955113bcecde",+ "libmbedtls.a": "d7e12979e590a796a8f6383fec0b5e285b3badc19afc44f4cb89da7e7544c8b2",+ "libmbedx509.a": "547c3ea5244efe1836edbec54a43c5fda31244926892084076fdcbeccc217aa6","libp256m.a": "412e12a472d4b2a3377760ccea57c87609831197c9183736ccd848d23b27da02"},"ps5_build_flags": "-ffile-prefix-map=<source root>/= (relative source paths; byte-reproducible with SDK v0.43 and LLVM 18.1.8)"diff --git a/scripts/network-deps/README.md b/scripts/network-deps/README.mdindex 1892321..3534275 100644--- a/scripts/network-deps/README.md+++ b/scripts/network-deps/README.md@@ -12,3 +12,9 @@ scripts/network-deps/prepare-ps5-deps.sh # PS5 buildstarts from clean source, build and install folders. The PS5 build applies `patches/curl-ps5-native-nonblock.patch`,uses relative source paths so the archives are reproducible, and writes `.deps/ps5/build-manifest.txt`. CMake checksthe PS5 archives, the curl headers and the CA bundle against `steam_network_probe` in `dependencies.lock.json`.++Both builds enable Mbed TLS `MBEDTLS_THREADING_C` and `MBEDTLS_THREADING_PTHREAD` through its source configuration+header. TLS shares entropy/DRBG and PSA state across clients; separate HTTP clients still require these locks.+Changing this configuration requires rebuilding Mbed TLS, curl and all title objects together because the public+context layouts include mutex fields. The installed configuration hash is pinned for both platforms, and PS5+archive hashes remain pinned. The host suite tests concurrent PSA key operations and independent HTTPS clients.diff --git a/scripts/network-deps/prepare-host-deps.sh b/scripts/network-deps/prepare-host-deps.shindex 1affdde..7edfd36 100755--- a/scripts/network-deps/prepare-host-deps.sh+++ b/scripts/network-deps/prepare-host-deps.sh@@ -30,6 +30,12 @@ rm -rf "$deps/src/mbedtls-$mbedtls_version" "$deps/src/curl-$curl_version" \"$deps/build/mbedtls-host" "$deps/build/curl-host" "$prefix"mkdir -p "$prefix"tar -xjf "$downloads/mbedtls-$mbedtls_version.tar.bz2" -C "$deps/src"+# TLS uses shared entropy/DRBG and PSA state even with distinct client contexts.+# Configure the installed header as well as the libraries to keep their mutex layouts consistent.+for option in MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD; do+ python3 "$deps/src/mbedtls-$mbedtls_version/scripts/config.py" \+ --file "$deps/src/mbedtls-$mbedtls_version/include/mbedtls/mbedtls_config.h" set "$option"+donetar -xJf "$downloads/curl-$curl_version.tar.xz" -C "$deps/src"# Relative source paths keep local paths out of the objects (see prepare-ps5-deps.sh).diff --git a/scripts/network-deps/prepare-ps5-deps.sh b/scripts/network-deps/prepare-ps5-deps.shindex 25f5cf4..1826b7a 100755--- a/scripts/network-deps/prepare-ps5-deps.sh+++ b/scripts/network-deps/prepare-ps5-deps.sh@@ -44,6 +44,12 @@ rm -rf "$deps/src/mbedtls-$mbedtls_version" "$deps/src/curl-$curl_version" \"$deps/build/mbedtls-ps5" "$deps/build/curl-ps5" "$prefix"mkdir -p "$prefix"tar -xjf "$downloads/mbedtls-$mbedtls_version.tar.bz2" -C "$deps/src"+# TLS uses shared entropy/DRBG and PSA state even with distinct client contexts.+# Configure the installed header as well as the libraries to keep their mutex layouts consistent.+for option in MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD; do+ python3 "$deps/src/mbedtls-$mbedtls_version/scripts/config.py" \+ --file "$deps/src/mbedtls-$mbedtls_version/include/mbedtls/mbedtls_config.h" set "$option"+donetar -xJf "$downloads/curl-$curl_version.tar.xz" -C "$deps/src"patch --fuzz=0 -d "$deps/src/curl-$curl_version" -p1 < "$curl_patch"# Record source paths relative to the extracted tree: the archives are then identical in every@@ -112,8 +118,11 @@ sdk_archive_sha256=$(cat "$sdk/.playden-source-sha256" 2>/dev/null || echo unkno"$(shasum -a 256 "$compiler_binary" | awk '{print $1}')"printf 'ps5_compiler_version=%s\n' "$compiler_version"printf '%s\n' \+ 'mbedtls_config=MBEDTLS_THREADING_C;MBEDTLS_THREADING_PTHREAD' \'mbedtls_flags=CMAKE_BUILD_TYPE=Release;CMAKE_C_FLAGS=-ffile-prefix-map=<src>/=;ENABLE_PROGRAMS=OFF;ENABLE_TESTING=OFF;USE_SHARED_MBEDTLS_LIBRARY=OFF' \'curl_flags=CMAKE_BUILD_TYPE=Release;CMAKE_C_FLAGS=-DPLAYDEN_PS5_NATIVE_NONBLOCK=1 -ffile-prefix-map=<src>/=;BUILD_CURL_EXE=OFF;BUILD_EXAMPLES=OFF;BUILD_LIBCURL_DOCS=OFF;BUILD_MISC_DOCS=OFF;BUILD_SHARED_LIBS=OFF;HTTP_ONLY=OFF;CURL_USE_MBEDTLS=ON;CURL_USE_CMAKECONFIG=ON;CURL_DISABLE_WEBSOCKETS=OFF;ENABLE_IPV6=OFF;ENABLE_THREADED_RESOLVER=OFF;CURL_DISABLE_SOCKETPAIR=ON;CURL_USE_LIBPSL=OFF;CURL_USE_LIBSSH2=OFF;CURL_ZLIB=OFF;CURL_DISABLE_NETRC=ON;HAVE_GETPWUID_R=0;HAVE_GMTIME_R=0;HAVE_IF_NAMETOINDEX=0;HAVE_PIPE2=0;HAVE_FCNTL_O_NONBLOCK=0;CURL_BROTLI=OFF;CURL_ZSTD=OFF;USE_NGHTTP2=OFF;USE_LIBIDN2=OFF;CURL_DISABLE_DICT=ON;CURL_DISABLE_FILE=ON;CURL_DISABLE_FTP=ON;CURL_DISABLE_GOPHER=ON;CURL_DISABLE_IMAP=ON;CURL_DISABLE_LDAP=ON;CURL_DISABLE_LDAPS=ON;CURL_DISABLE_MQTT=ON;CURL_DISABLE_POP3=ON;CURL_DISABLE_RTSP=ON;CURL_ENABLE_SMB=OFF;CURL_DISABLE_SMTP=ON;CURL_DISABLE_TELNET=ON;CURL_DISABLE_TFTP=ON'+ printf 'mbedtls_config_sha256=%s\n' \+ "$(shasum -a 256 "$prefix/include/mbedtls/mbedtls_config.h" | awk '{print $1}')"for archive in libcurl.a libmbedtls.a libmbedx509.a libmbedcrypto.a libeverest.a libp256m.a; doprintf 'output_%s_sha256=%s\n' "$archive" \"$(shasum -a 256 "$prefix/lib/$archive" | awk '{print $1}')"diff --git a/tests/http_client_test.cpp b/tests/http_client_test.cppindex 80d98fc..cbff009 100644--- a/tests/http_client_test.cpp+++ b/tests/http_client_test.cpp@@ -44,6 +44,7 @@ int main(int argc, char** argv) {std::atomic<bool> cancel{false};HttpClient client(ca_bundle);+{HttpClient persistent(ca_bundle);HttpRequest keep;@@ -222,5 +223,25 @@ int main(int argc, char** argv) {Check(std::string(playden::steam::HttpErrorName(HttpError::kCanceled)) == "canceled","error names should be stable and safe for diagnostics");+ {+ std::atomic<int> ready{0};+ std::atomic<bool> begin{false};+ std::vector<std::thread> workers;+ for (int index = 0; index < 8; ++index) workers.emplace_back([&] {+ HttpClient independent(ca_bundle);+ ++ready;+ while (!begin.load()) std::this_thread::yield();+ HttpRequest request;+ request.url = base_url + "/keep/ok";+ for (int iteration = 0; iteration < 10; ++iteration) {+ const auto response = independent.Perform(request, cancel);+ Check(response.ok() && Text(response.body) == "fixture-ok", "parallel verified HTTPS clients");+ }+ });+ while (ready.load() != 8) std::this_thread::yield();+ begin.store(true);+ for (auto& worker : workers) worker.join();+ }+return 0;}diff --git a/tests/mbedtls_threading_test.cpp b/tests/mbedtls_threading_test.cppnew file mode 100644index 0000000..3167284--- /dev/null+++ b/tests/mbedtls_threading_test.cpp@@ -0,0 +1,52 @@+#include <mbedtls/build_info.h>+#include <mbedtls/threading.h>+#include <psa/crypto.h>++#include <array>+#include <cstdio>+#include <cstdlib>+#include <thread>+#include <vector>++namespace {+void Check(bool ok, const char* message) {+ if (!ok) { std::fprintf(stderr, "%s\n", message); std::exit(1); }+}+}++int main() {+#if !defined(MBEDTLS_THREADING_C) || !defined(MBEDTLS_THREADING_PTHREAD)+ Check(false, "Concurrent TLS requires the Mbed TLS pthread configuration");+#else+ mbedtls_threading_mutex_t mutex;+ mbedtls_mutex_init(&mutex);+ unsigned counter = 0;+ Check(psa_crypto_init() == PSA_SUCCESS, "PSA initialization");+ std::vector<std::thread> workers;+ for (unsigned worker = 0; worker < 8; ++worker) workers.emplace_back([&, worker] {+ for (unsigned iteration = 0; iteration < 500; ++iteration) {+ Check(mbedtls_mutex_lock(&mutex) == 0, "Mbed TLS mutex lock");+ ++counter;+ Check(mbedtls_mutex_unlock(&mutex) == 0, "Mbed TLS mutex unlock");+ std::array<unsigned char, 16> key{};+ key[0] = worker; key[1] = iteration; key[2] = iteration >> 8;+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;+ psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);+ psa_set_key_bits(&attributes, 128);+ psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);+ mbedtls_svc_key_id_t id;+ Check(psa_import_key(&attributes, key.data(), key.size(), &id) == PSA_SUCCESS, "Concurrent key import");+ std::array<unsigned char, 16> exported{};+ std::size_t size = 0;+ Check(psa_export_key(id, exported.data(), exported.size(), &size) == PSA_SUCCESS,+ "Concurrent key export");+ Check(size == key.size() && exported == key, "Each key keeps its own bytes");+ Check(psa_destroy_key(id) == PSA_SUCCESS, "Concurrent key destruction");+ psa_reset_key_attributes(&attributes);+ }+ });+ for (auto& worker : workers) worker.join();+ Check(counter == 4000, "Mbed TLS pthread mutex synchronizes workers");+ mbedtls_mutex_free(&mutex);+#endif+}