From: Neil Horman Date: Thu, 12 Jun 2025 17:17:34 +0000 (-0400) Subject: Move the async-job api to use the new thread-local api X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21980b981395ab64edabb1432feb9f15798c68e7;p=thirdparty%2Fopenssl.git Move the async-job api to use the new thread-local api Make the async-job api use our new thread-local storage api. Not strictly needed, but reduces our OS level key usage Reviewed-by: Saša Nedvědický Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/27794) --- diff --git a/crypto/async/async.c b/crypto/async/async.c index 46c87d6a5af..c23027e3aef 100644 --- a/crypto/async/async.c +++ b/crypto/async/async.c @@ -17,6 +17,7 @@ /* This must be the first #include file */ #include "async_local.h" +#include "internal/threads_common.h" #include #include "crypto/cryptlib.h" @@ -27,9 +28,6 @@ #define ASYNC_JOB_PAUSED 2 #define ASYNC_JOB_STOPPING 3 -static CRYPTO_THREAD_LOCAL ctxkey; -static CRYPTO_THREAD_LOCAL poolkey; - static void async_delete_thread_state(void *arg); static async_ctx *async_ctx_new(void) @@ -46,7 +44,7 @@ static async_ctx *async_ctx_new(void) async_fibre_init_dispatcher(&nctx->dispatcher); nctx->currjob = NULL; nctx->blocked = 0; - if (!CRYPTO_THREAD_set_local(&ctxkey, nctx)) + if (!CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_CTX_KEY, NULL, nctx)) goto err; return nctx; @@ -58,7 +56,7 @@ err: async_ctx *async_get_ctx(void) { - return (async_ctx *)CRYPTO_THREAD_get_local(&ctxkey); + return (async_ctx *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_CTX_KEY, NULL); } static int async_ctx_free(void) @@ -67,7 +65,7 @@ static int async_ctx_free(void) ctx = async_get_ctx(); - if (!CRYPTO_THREAD_set_local(&ctxkey, NULL)) + if (!CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_CTX_KEY, NULL, NULL)) return 0; OPENSSL_free(ctx); @@ -101,7 +99,7 @@ static ASYNC_JOB *async_get_pool_job(void) { ASYNC_JOB *job; async_pool *pool; - pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); + pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL); if (pool == NULL) { /* * Pool has not been initialised, so init with the defaults, i.e. @@ -109,7 +107,7 @@ static ASYNC_JOB *async_get_pool_job(void) { */ if (ASYNC_init_thread(0, 0) == 0) return NULL; - pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); + pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL); } job = sk_ASYNC_JOB_pop(pool->jobs); @@ -133,7 +131,7 @@ static ASYNC_JOB *async_get_pool_job(void) { static void async_release_job(ASYNC_JOB *job) { async_pool *pool; - pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); + pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL); if (pool == NULL) { ERR_raise(ERR_LIB_ASYNC, ERR_R_INTERNAL_ERROR); return; @@ -327,21 +325,11 @@ static void async_empty_pool(async_pool *pool) int async_init(void) { - if (!CRYPTO_THREAD_init_local(&ctxkey, NULL)) - return 0; - - if (!CRYPTO_THREAD_init_local(&poolkey, NULL)) { - CRYPTO_THREAD_cleanup_local(&ctxkey); - return 0; - } - return async_local_init(); } void async_deinit(void) { - CRYPTO_THREAD_cleanup_local(&ctxkey); - CRYPTO_THREAD_cleanup_local(&poolkey); async_local_deinit(); } @@ -391,7 +379,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size) curr_size++; } pool->curr_size = curr_size; - if (!CRYPTO_THREAD_set_local(&poolkey, pool)) { + if (!CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL, pool)) { ERR_raise(ERR_LIB_ASYNC, ASYNC_R_FAILED_TO_SET_POOL); goto err; } @@ -406,13 +394,14 @@ err: static void async_delete_thread_state(void *arg) { - async_pool *pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); + async_pool *pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, + NULL); if (pool != NULL) { async_empty_pool(pool); sk_ASYNC_JOB_free(pool->jobs); OPENSSL_free(pool); - CRYPTO_THREAD_set_local(&poolkey, NULL); + CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL, NULL); } async_local_cleanup(); async_ctx_free();