Fix duplicate lock IDs & simplify lock ID maintenance.
* Eliminate the possibility of multiple lock IDs having the same value (CRYPTO_LOCK_FIPS2 and CRYPTO_LOCK_OBJ were both 40 prior to this commit). * Remove unused lock IDs. * Automatically guarantee that lock IDs and lock names stay in sync. Change-Id: If20e462db1285fa891595a7e52404ad011ff16f6 Reviewed-on: https://boringssl-review.googlesource.com/3923 Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
d434f28ef2
commit
ab2a8e03d9
@ -66,27 +66,18 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openssl/mem.h>
|
#include <openssl/mem.h>
|
||||||
#include <openssl/type_check.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
#define CRYPTO_LOCK_ITEM(x) #x
|
||||||
|
|
||||||
/* lock_names contains the names of all the locks defined in thread.h. */
|
/* lock_names contains the names of all the locks defined in thread.h. */
|
||||||
static const char *const lock_names[] = {
|
static const char *const lock_names[] = {
|
||||||
"<<ERROR>>", "err", "ex_data", "x509",
|
CRYPTO_LOCK_LIST
|
||||||
"x509_info", "x509_pkey", "x509_crl", "x509_req",
|
|
||||||
"dsa", "rsa", "evp_pkey", "x509_store",
|
|
||||||
"ssl_ctx", "ssl_cert", "ssl_session", "ssl_sess_cert",
|
|
||||||
"ssl", "ssl_method", "rand", "rand2",
|
|
||||||
"debug_malloc", "BIO", "gethostbyname", "getservbyname",
|
|
||||||
"readdir", "RSA_blinding", "dh", "debug_malloc2",
|
|
||||||
"dso", "dynlock", "engine", "ui",
|
|
||||||
"ecdsa", "ec", "ecdh", "bn",
|
|
||||||
"ec_pre_comp", "store", "comp", "fips",
|
|
||||||
"fips2", "obj",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
OPENSSL_COMPILE_ASSERT(CRYPTO_NUM_LOCKS ==
|
#undef CRYPTO_LOCK_ITEM
|
||||||
sizeof(lock_names) / sizeof(lock_names[0]),
|
|
||||||
CRYPTO_NUM_LOCKS_inconsistent);
|
#define CRYPTO_NUM_LOCKS (sizeof(lock_names) / sizeof(lock_names[0]))
|
||||||
|
|
||||||
static void (*locking_callback)(int mode, int lock_num, const char *file,
|
static void (*locking_callback)(int mode, int lock_num, const char *file,
|
||||||
int line) = 0;
|
int line) = 0;
|
||||||
|
@ -178,50 +178,39 @@ void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src);
|
|||||||
/* CRYPTO_THREADID_hash returns a hash of the numeric value of |id|. */
|
/* CRYPTO_THREADID_hash returns a hash of the numeric value of |id|. */
|
||||||
uint32_t CRYPTO_THREADID_hash(const CRYPTO_THREADID *id);
|
uint32_t CRYPTO_THREADID_hash(const CRYPTO_THREADID *id);
|
||||||
|
|
||||||
/* These are the locks used by OpenSSL. These values should match up with the
|
/* Lock IDs start from 1. CRYPTO_LOCK_INVALID_LOCK is an unused placeholder
|
||||||
* table in thread.c. */
|
* used to ensure no lock has ID 0. */
|
||||||
#define CRYPTO_LOCK_ERR 1
|
#define CRYPTO_LOCK_LIST \
|
||||||
#define CRYPTO_LOCK_EX_DATA 2
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_INVALID_LOCK), \
|
||||||
#define CRYPTO_LOCK_X509 3
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_BIO), \
|
||||||
#define CRYPTO_LOCK_X509_INFO 4
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_DH), \
|
||||||
#define CRYPTO_LOCK_X509_PKEY 5
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_DSA), \
|
||||||
#define CRYPTO_LOCK_X509_CRL 6
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EC), \
|
||||||
#define CRYPTO_LOCK_X509_REQ 7
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EC_PRE_COMP), \
|
||||||
#define CRYPTO_LOCK_DSA 8
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_ERR), \
|
||||||
#define CRYPTO_LOCK_RSA 9
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EVP_PKEY), \
|
||||||
#define CRYPTO_LOCK_EVP_PKEY 10
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EX_DATA), \
|
||||||
#define CRYPTO_LOCK_X509_STORE 11
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_OBJ), \
|
||||||
#define CRYPTO_LOCK_SSL_CTX 12
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RAND), \
|
||||||
#define CRYPTO_LOCK_SSL_CERT 13
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_READDIR), \
|
||||||
#define CRYPTO_LOCK_SSL_SESSION 14
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RSA), \
|
||||||
#define CRYPTO_LOCK_SSL_SESS_CERT 15
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RSA_BLINDING), \
|
||||||
#define CRYPTO_LOCK_SSL 16
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_SSL_CTX), \
|
||||||
#define CRYPTO_LOCK_SSL_METHOD 17
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_SSL_SESSION), \
|
||||||
#define CRYPTO_LOCK_RAND 18
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509), \
|
||||||
#define CRYPTO_LOCK_RAND2 19
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_INFO), \
|
||||||
#define CRYPTO_LOCK_MALLOC 20
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_PKEY), \
|
||||||
#define CRYPTO_LOCK_BIO 21
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_CRL), \
|
||||||
#define CRYPTO_LOCK_GETHOSTBYNAME 22
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_REQ), \
|
||||||
#define CRYPTO_LOCK_GETSERVBYNAME 23
|
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_STORE), \
|
||||||
#define CRYPTO_LOCK_READDIR 24
|
|
||||||
#define CRYPTO_LOCK_RSA_BLINDING 25
|
#define CRYPTO_LOCK_ITEM(x) x
|
||||||
#define CRYPTO_LOCK_DH 26
|
|
||||||
#define CRYPTO_LOCK_MALLOC2 27
|
enum {
|
||||||
#define CRYPTO_LOCK_DSO 28
|
CRYPTO_LOCK_LIST
|
||||||
#define CRYPTO_LOCK_DYNLOCK 29
|
};
|
||||||
#define CRYPTO_LOCK_ENGINE 30
|
|
||||||
#define CRYPTO_LOCK_UI 31
|
#undef CRYPTO_LOCK_ITEM
|
||||||
#define CRYPTO_LOCK_ECDSA 32
|
|
||||||
#define CRYPTO_LOCK_EC 33
|
|
||||||
#define CRYPTO_LOCK_ECDH 34
|
|
||||||
#define CRYPTO_LOCK_BN 35
|
|
||||||
#define CRYPTO_LOCK_EC_PRE_COMP 36
|
|
||||||
#define CRYPTO_LOCK_STORE 37
|
|
||||||
#define CRYPTO_LOCK_COMP 38
|
|
||||||
#define CRYPTO_LOCK_FIPS 39
|
|
||||||
#define CRYPTO_LOCK_FIPS2 40
|
|
||||||
#define CRYPTO_LOCK_OBJ 40
|
|
||||||
#define CRYPTO_NUM_LOCKS 42
|
|
||||||
|
|
||||||
#define CRYPTO_LOCK 1
|
#define CRYPTO_LOCK 1
|
||||||
#define CRYPTO_UNLOCK 2
|
#define CRYPTO_UNLOCK 2
|
||||||
|
Loading…
Reference in New Issue
Block a user