/*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
#include "internal/namemap.h"
#include <openssl/lhash.h>
#include "crypto/lhash.h" /* openssl_lh_strcasehash */
+#include "internal/tsan_assist.h"
/*-
* The namenum entry
CRYPTO_RWLOCK *lock;
LHASH_OF(NAMENUM_ENTRY) *namenum; /* Name->number mapping */
- int max_number; /* Current max number */
+
+#ifdef tsan_ld_acq
+ TSAN_QUALIFIER int max_number; /* Current max number TSAN version */
+#else
+ int max_number; /* Current max number plain version */
+#endif
};
/* LHASH callbacks */
int ossl_namemap_empty(OSSL_NAMEMAP *namemap)
{
- int rv = 0;
+#ifdef tsan_ld_acq
+ /* Have TSAN support */
+ return namemap == NULL || tsan_load(&namemap->max_number) == 0;
+#else
+ /* No TSAN support */
+ int rv;
+
+ if (namemap == NULL)
+ return 1;
CRYPTO_THREAD_read_lock(namemap->lock);
- if (namemap->max_number == 0)
- rv = 1;
+ rv = namemap->max_number == 0;
CRYPTO_THREAD_unlock(namemap->lock);
-
return rv;
+#endif
}
typedef struct doall_names_data_st {
NAMENUM_ENTRY *namenum_entry, namenum_tmpl;
int number = 0;
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
if (namemap == NULL)
namemap = ossl_namemap_stored(NULL);
#endif
NAMENUM_ENTRY *namenum = NULL;
int tmp_number;
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
if (namemap == NULL)
namemap = ossl_namemap_stored(NULL);
#endif
goto err;
namenum->number = tmp_number =
- number != 0 ? number : ++namemap->max_number;
+ number != 0 ? number : 1 + tsan_counter(&namemap->max_number);
(void)lh_NAMENUM_ENTRY_insert(namemap->namenum, namenum);
if (lh_NAMENUM_ENTRY_error(namemap->namenum))
if (number == 0) {
number = this_number;
} else if (this_number != number) {
- ERR_raise_data(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR,
+ ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR,
"Got number %d when expecting %d",
this_number, number);
return 0;
* ==============
*/
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
#include <openssl/evp.h>
/* Creates an initial namemap with names found in the legacy method db */
openssl_ctx_get_data(libctx, OPENSSL_CTX_NAMEMAP_INDEX,
&stored_namemap_method);
-#ifndef FIPS_MODE
+#ifndef FIPS_MODULE
if (namemap != NULL && ossl_namemap_empty(namemap)) {
/* Before pilfering, we make sure the legacy database is populated */
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS