summaryrefslogtreecommitdiffstats
path: root/crypto/initthread.c
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2022-03-14 08:13:12 +0000
committerPauli <pauli@openssl.org>2022-04-01 10:49:19 +1100
commit927d0566ded0dff9d6c5abc8a40bb84068446b76 (patch)
treec6d898a04aaa2062c9a74cb9c89ce25fa9680a41 /crypto/initthread.c
parent9c140a33663f319ad4000a6a985c3e14297c7389 (diff)
Refactor OSSL_LIB_CTX to avoid using CRYPTO_EX_DATA
This refactors OSSL_LIB_CTX to avoid using CRYPTO_EX_DATA. The assorted objects to be managed by OSSL_LIB_CTX are hardcoded and are initialized eagerly rather than lazily, which avoids the need for locking on access in most cases. Fixes #17116. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17881)
Diffstat (limited to 'crypto/initthread.c')
-rw-r--r--crypto/initthread.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/crypto/initthread.c b/crypto/initthread.c
index 1bdaeda9fc..ee57d14466 100644
--- a/crypto/initthread.c
+++ b/crypto/initthread.c
@@ -12,6 +12,7 @@
#include "crypto/cryptlib.h"
#include "prov/providercommon.h"
#include "internal/thread_once.h"
+#include "crypto/context.h"
#ifdef FIPS_MODULE
#include "prov/provider_ctx.h"
@@ -248,7 +249,7 @@ void ossl_ctx_thread_stop(OSSL_LIB_CTX *ctx)
#else
-static void *thread_event_ossl_ctx_new(OSSL_LIB_CTX *libctx)
+void *ossl_thread_event_ctx_new(OSSL_LIB_CTX *libctx)
{
THREAD_EVENT_HANDLER **hands = NULL;
CRYPTO_THREAD_LOCAL *tlocal = OPENSSL_zalloc(sizeof(*tlocal));
@@ -274,17 +275,11 @@ static void *thread_event_ossl_ctx_new(OSSL_LIB_CTX *libctx)
return NULL;
}
-static void thread_event_ossl_ctx_free(void *tlocal)
+void ossl_thread_event_ctx_free(void *tlocal)
{
OPENSSL_free(tlocal);
}
-static const OSSL_LIB_CTX_METHOD thread_event_ossl_ctx_method = {
- OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY,
- thread_event_ossl_ctx_new,
- thread_event_ossl_ctx_free,
-};
-
static void ossl_arg_thread_stop(void *arg)
{
ossl_ctx_thread_stop((OSSL_LIB_CTX *)arg);
@@ -294,8 +289,7 @@ void ossl_ctx_thread_stop(OSSL_LIB_CTX *ctx)
{
THREAD_EVENT_HANDLER **hands;
CRYPTO_THREAD_LOCAL *local
- = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_THREAD_EVENT_HANDLER_INDEX,
- &thread_event_ossl_ctx_method);
+ = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_THREAD_EVENT_HANDLER_INDEX);
if (local == NULL)
return;
@@ -363,8 +357,7 @@ int ossl_init_thread_start(const void *index, void *arg,
* OSSL_LIB_CTX gets informed about thread stop events individually.
*/
CRYPTO_THREAD_LOCAL *local
- = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_THREAD_EVENT_HANDLER_INDEX,
- &thread_event_ossl_ctx_method);
+ = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_THREAD_EVENT_HANDLER_INDEX);
#else
/*
* Outside of FIPS mode the list of THREAD_EVENT_HANDLERs is unique per