#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 {
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))
#define ALIAS1 "alias1"
#define ALIAS1_UC "ALIAS1"
+static int test_namemap_empty(void)
+{
+ OSSL_NAMEMAP *nm = NULL;
+ int ok;
+
+ ok = TEST_true(ossl_namemap_empty(NULL))
+ && TEST_ptr(nm = ossl_namemap_new())
+ && TEST_true(ossl_namemap_empty(nm))
+ && TEST_int_ne(ossl_namemap_add_name(nm, 0, NAME1), 0)
+ && TEST_false(ossl_namemap_empty(nm));
+ ossl_namemap_free(nm);
+ return ok;
+}
+
static int test_namemap(OSSL_NAMEMAP *nm)
{
int num1 = ossl_namemap_add_name(nm, 0, NAME1);
static int test_namemap_independent(void)
{
OSSL_NAMEMAP *nm = ossl_namemap_new();
- int ok = nm != NULL && test_namemap(nm);
+ int ok = TEST_ptr(nm) && test_namemap(nm);
ossl_namemap_free(nm);
return ok;
{
OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
- return nm != NULL
+ return TEST_ptr(nm)
&& test_namemap(nm);
}
OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
const EVP_MD *sha256, *foo;
+ if (!TEST_ptr(nm))
+ return 0;
id = ossl_namemap_add_name(nm, 0, "SHA256");
if (!TEST_int_ne(id, 0))
return 0;
OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
const EVP_CIPHER *aes128, *bar;
+ if (!TEST_ptr(nm))
+ return 0;
id = ossl_namemap_add_name(nm, 0, "AES-128-CBC");
if (!TEST_int_ne(id, 0))
return 0;
EVP_CIPHER *fetched = EVP_CIPHER_fetch(NULL, "AES-256-CCM", NULL);
int rv = 1;
- if (!TEST_ptr_ne(fetched, NULL))
+ if (!TEST_ptr(fetched))
return 0;
if (!TEST_true(EVP_CIPHER_is_a(fetched, "id-aes256-CCM"))
|| !TEST_false(EVP_CIPHER_is_a(fetched, "AES-128-GCM")))
EVP_MD *fetched = EVP_MD_fetch(NULL, "SHA2-512", NULL);
int rv = 1;
- if (!TEST_ptr_ne(fetched, NULL))
+ if (!TEST_ptr(fetched))
return 0;
if (!TEST_true(EVP_MD_is_a(fetched, "SHA512"))
|| !TEST_false(EVP_MD_is_a(fetched, "SHA1")))
int setup_tests(void)
{
+ ADD_TEST(test_namemap_empty);
ADD_TEST(test_namemap_independent);
ADD_TEST(test_namemap_stored);
ADD_TEST(test_digestbyname);