summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2019-05-28 16:21:19 +0100
committerMatt Caswell <matt@openssl.org>2019-06-17 16:19:44 +0100
commit52b18ce10498dc2d8ced7db31ead116f4eeca134 (patch)
tree03b9010afd6a4089e6beeb41fe04dbcf31b39c6e
parentda747958c5db57dbe22c015d058be9db8a90f8f9 (diff)
Add the function OPENSSL_thread_stop_ex()
This adds the ability to clean up a thread on a per OPENSSL_CTX basis. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9040)
-rw-r--r--crypto/initthread.c11
-rw-r--r--include/openssl/crypto.h1
-rw-r--r--test/evp_extra_test.c5
-rw-r--r--util/libcrypto.num1
4 files changed, 18 insertions, 0 deletions
diff --git a/crypto/initthread.c b/crypto/initthread.c
index 124fdccd6e..02a51ee5d2 100644
--- a/crypto/initthread.c
+++ b/crypto/initthread.c
@@ -97,6 +97,17 @@ void cleanup_thread(void)
destructor_key.sane = -1;
}
+void OPENSSL_thread_stop_ex(OPENSSL_CTX *ctx)
+{
+ ctx = openssl_ctx_get_concrete(ctx);
+ /*
+ * TODO(3.0). It would be nice if we could figure out a way to do this on
+ * all threads that have used the OPENSSL_CTX when the OPENSSL_CTX is freed.
+ * This is currently not possible due to the use of thread local variables.
+ */
+ ossl_ctx_thread_stop(ctx);
+}
+
void OPENSSL_thread_stop(void)
{
if (destructor_key.sane != -1) {
diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h
index 5322cc8f04..79531196ed 100644
--- a/include/openssl/crypto.h
+++ b/include/openssl/crypto.h
@@ -415,6 +415,7 @@ void OPENSSL_cleanup(void);
int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);
int OPENSSL_atexit(void (*handler)(void));
void OPENSSL_thread_stop(void);
+void OPENSSL_thread_stop_ex(OPENSSL_CTX *ctx);
/* Low-level control of initialization */
OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void);
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index 6fca3a38f5..5bf4a8c1f3 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -1220,6 +1220,11 @@ static int test_EVP_MD_fetch(int tst)
EVP_MD_meth_free(md);
OSSL_PROVIDER_unload(defltprov);
OSSL_PROVIDER_unload(fipsprov);
+ /* Not normally needed, but we would like to test that
+ * OPENSSL_thread_stop_ex() behaves as expected.
+ */
+ if (ctx != NULL)
+ OPENSSL_thread_stop_ex(ctx);
OPENSSL_CTX_free(ctx);
return ret;
}
diff --git a/util/libcrypto.num b/util/libcrypto.num
index 7280649920..0b181070eb 100644
--- a/util/libcrypto.num
+++ b/util/libcrypto.num
@@ -4831,3 +4831,4 @@ OPENSSL_CTX_get0_public_drbg 4775 3_0_0 EXIST::FUNCTION:
OPENSSL_CTX_get0_private_drbg 4776 3_0_0 EXIST::FUNCTION:
BN_CTX_new_ex 4777 3_0_0 EXIST::FUNCTION:
BN_CTX_secure_new_ex 4778 3_0_0 EXIST::FUNCTION:
+OPENSSL_thread_stop_ex 4779 3_0_0 EXIST::FUNCTION: