]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Remove use of CRYPTO_LOCK_INIT in init code
authorMatt Caswell <matt@openssl.org>
Mon, 7 Mar 2016 14:39:22 +0000 (14:39 +0000)
committerMatt Caswell <matt@openssl.org>
Mon, 7 Mar 2016 17:17:21 +0000 (17:17 +0000)
Swap the use of CRYPTO_LOCK_INIT in the init code to use the new threading
API mechanism for locking.

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/init.c
crypto/lock.c
include/openssl/crypto.h

index 491ef831cb684c16a06157bcf9d2812565071df9..44acd4f4df87e54d6aaf939f29fc739a33bf4d4b 100644 (file)
@@ -105,6 +105,7 @@ struct ossl_init_stop_st {
 };
 
 static OPENSSL_INIT_STOP *stop_handlers = NULL;
+static CRYPTO_RWLOCK *init_lock = NULL;
 
 static CRYPTO_ONCE base = CRYPTO_ONCE_STATIC_INIT;
 static int base_inited = 0;
@@ -121,6 +122,7 @@ static void ossl_init_base(void)
 #ifndef OPENSSL_SYS_UEFI
     atexit(OPENSSL_cleanup);
 #endif
+    init_lock = CRYPTO_THREAD_lock_new();
     OPENSSL_cpuid_setup();
     base_inited = 1;
 }
@@ -425,6 +427,9 @@ void OPENSSL_cleanup(void)
         OPENSSL_free(lasthandler);
     }
     stop_handlers = NULL;
+
+    CRYPTO_THREAD_lock_free(init_lock);
+
     /*
      * We assume we are single-threaded for this function, i.e. no race
      * conditions for the various "*_inited" vars below.
@@ -544,10 +549,10 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
 
     if (opts & OPENSSL_INIT_LOAD_CONFIG) {
         int ret;
-        CRYPTO_w_lock(CRYPTO_LOCK_INIT);
+        CRYPTO_THREAD_write_lock(init_lock);
         config_filename = (settings == NULL) ? NULL : settings->config_name;
         ret = CRYPTO_THREAD_run_once(&config, ossl_init_config);
-        CRYPTO_w_unlock(CRYPTO_LOCK_INIT);
+        CRYPTO_THREAD_unlock(init_lock);
         if (!ret)
             return 0;
     }
index aa34202163721f2b69a5528a9702337729c092b1..35f0059ef3e18ff83d70e3d67beb9c1c6a9d41ee 100644 (file)
@@ -163,8 +163,7 @@ static const char *const lock_names[CRYPTO_NUM_LOCKS] = {
     "comp",
     "fips",
     "fips2",
-    "init",
-#if CRYPTO_NUM_LOCKS != 42
+#if CRYPTO_NUM_LOCKS != 41
 # error "Inconsistency between crypto.h and cryptlib.c"
 #endif
 };
index d52c14c379b66fa81e05a4930348bf4bb0f6af2c..a881fada73df531e52d0e175e5d1c2e0be38d429 100644 (file)
@@ -205,8 +205,7 @@ extern "C" {
 # define CRYPTO_LOCK_COMP                38
 # define CRYPTO_LOCK_FIPS                39
 # define CRYPTO_LOCK_FIPS2               40
-# define CRYPTO_LOCK_INIT                41
-# define CRYPTO_NUM_LOCKS                42
+# define CRYPTO_NUM_LOCKS                41
 
 # define CRYPTO_LOCK             1
 # define CRYPTO_UNLOCK           2