#ifndef OPENSSL_NO_SOCK
#include <openssl/err.h>
#include <openssl/buffer.h>
+#include <internal/thread_once.h>
#include <ctype.h>
CRYPTO_RWLOCK *bio_lookup_lock;
return 1;
}
-static void do_bio_lookup_init(void)
+DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
{
bio_lookup_lock = CRYPTO_THREAD_lock_new();
+ return (bio_lookup_lock != NULL);
}
/*-
struct servent se_fallback = { NULL, NULL, 0, NULL };
#endif
- CRYPTO_THREAD_run_once(&bio_lookup_init, do_bio_lookup_init);
+ if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) {
+ BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
+ ret = 0;
+ goto err;
+ }
CRYPTO_THREAD_write_lock(bio_lookup_lock);
he_fallback_address = INADDR_ANY;
ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
CRYPTO_THREAD_write_lock(global_engine_lock);
ret = engine_unlocked_init(e);
CRYPTO_THREAD_unlock(global_engine_lock);
# include "internal/cryptlib.h"
# include <internal/engine.h>
+# include <internal/thread_once.h>
#ifdef __cplusplus
extern "C" {
/* Once initialisation function */
extern CRYPTO_ONCE engine_lock_init;
-void do_engine_lock_init(void);
+DECLARE_RUN_ONCE(do_engine_lock_init)
/*
* This is a structure for storing implementations of various crypto
/* The "new"/"free" stuff first */
-void do_engine_lock_init(void)
+DEFINE_RUN_ONCE(do_engine_lock_init)
{
global_engine_lock = CRYPTO_THREAD_lock_new();
+ return global_engine_lock != NULL;
}
ENGINE *ENGINE_new(void)
{
ENGINE *ret;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
-
- ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)
+ || (ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
{
ENGINE *ret;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_GET_FIRST, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
ret = engine_list_head;
if (ret) {
{
ENGINE *ret;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_GET_LAST, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
ret = engine_list_tail;
if (ret) {
ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
}
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
iterator = engine_list_head;
while (iterator && (strcmp(id, iterator->id) != 0))
fstr.str = str;
fstr.len = len;
- CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+ if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
+ ENGINEerr(ENGINE_F_ENGINE_PKEY_ASN1_FIND_STR, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
CRYPTO_THREAD_write_lock(global_engine_lock);
engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr);
/* If found obtain a structural reference to engine */
#include <openssl/buffer.h>
#include <openssl/bio.h>
#include <openssl/opensslconf.h>
+#include <internal/thread_once.h>
static void err_load_strings(int lib, ERR_STRING_DATA *str);
OPENSSL_free(s);
}
-static void do_err_strings_init(void)
+DEFINE_RUN_ONCE_STATIC(do_err_strings_init)
{
err_string_lock = CRYPTO_THREAD_lock_new();
+ return err_string_lock != NULL;
}
void err_cleanup(void)
void ERR_load_ERR_strings(void)
{
#ifndef OPENSSL_NO_ERR
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ RUN_ONCE(&err_string_init, do_err_strings_init);
err_load_strings(0, ERR_str_libraries);
err_load_strings(0, ERR_str_reasons);
err_load_strings(lib, str);
}
-void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
+int ERR_unload_strings(int lib, ERR_STRING_DATA *str)
{
LHASH_OF(ERR_STRING_DATA) *hash;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init))
+ return 0;
CRYPTO_THREAD_write_lock(err_string_lock);
hash = get_hash(0, 0);
}
}
CRYPTO_THREAD_unlock(err_string_lock);
+
+ return 1;
}
void err_free_strings_int(void)
{
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init))
+ return;
CRYPTO_THREAD_write_lock(err_string_lock);
lh_ERR_STRING_DATA_free(int_error_hash);
ERR_STRING_DATA d, *p;
unsigned long l;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return NULL;
+ }
l = ERR_GET_LIB(e);
d.error = ERR_PACK(l, 0, 0);
ERR_STRING_DATA d, *p;
unsigned long l, f;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return NULL;
+ }
l = ERR_GET_LIB(e);
f = ERR_GET_FUNC(e);
ERR_STRING_DATA d, *p = NULL;
unsigned long l, r;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return NULL;
+ }
l = ERR_GET_LIB(e);
r = ERR_GET_REASON(e);
}
#endif
-static void err_do_init(void)
+DEFINE_RUN_ONCE_STATIC(err_do_init)
{
- CRYPTO_THREAD_init_local(&err_thread_local, NULL);
+ return CRYPTO_THREAD_init_local(&err_thread_local, NULL);
}
ERR_STATE *ERR_get_state(void)
{
ERR_STATE *state = NULL;
- CRYPTO_THREAD_run_once(&err_init, err_do_init);
+ if (!RUN_ONCE(&err_init, err_do_init))
+ return NULL;
state = CRYPTO_THREAD_get_local(&err_thread_local);
{
int ret;
- CRYPTO_THREAD_run_once(&err_string_init, do_err_strings_init);
+ if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
+ return 0;
+ }
CRYPTO_THREAD_write_lock(err_string_lock);
ret = int_err_library_number++;
*/
#include "internal/cryptlib_int.h"
+#include "internal/thread_once.h"
#include <openssl/lhash.h>
/*
static CRYPTO_RWLOCK *ex_data_lock = NULL;
static CRYPTO_ONCE ex_data_init = CRYPTO_ONCE_STATIC_INIT;
-static void do_ex_data_init(void)
+DEFINE_RUN_ONCE_STATIC(do_ex_data_init)
{
ex_data_lock = CRYPTO_THREAD_lock_new();
+ return ex_data_lock != NULL;
}
/*
return NULL;
}
- CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);
+ if (!RUN_ONCE(&ex_data_init, do_ex_data_init)) {
+ CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
if (ex_data_lock == NULL) {
/*
#include <internal/objects.h>
#include <stdlib.h>
#include <assert.h>
+#include <internal/thread_once.h>
static int stopped = 0;
static CRYPTO_ONCE base = CRYPTO_ONCE_STATIC_INIT;
static int base_inited = 0;
-static void ossl_init_base(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_base)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
#ifndef OPENSSL_SYS_UEFI
atexit(OPENSSL_cleanup);
#endif
- init_lock = CRYPTO_THREAD_lock_new();
+ if ((init_lock = CRYPTO_THREAD_lock_new()) == NULL)
+ return 0;
OPENSSL_cpuid_setup();
base_inited = 1;
+ return 1;
}
static CRYPTO_ONCE load_crypto_strings = CRYPTO_ONCE_STATIC_INIT;
static int load_crypto_strings_inited = 0;
-static void ossl_init_no_load_crypto_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_crypto_strings)
{
/* Do nothing in this case */
- return;
+ return 1;
}
-static void ossl_init_load_crypto_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
{
/*
* OPENSSL_NO_AUTOERRINIT is provided here to prevent at compile time
err_load_crypto_strings_int();
#endif
load_crypto_strings_inited = 1;
+ return 1;
}
static CRYPTO_ONCE add_all_ciphers = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_add_all_ciphers(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_ciphers)
{
/*
* OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
# endif
openssl_add_all_ciphers_int();
#endif
+ return 1;
}
static CRYPTO_ONCE add_all_digests = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_add_all_digests(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests)
{
/*
* OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
# endif
openssl_add_all_digests_int();
#endif
+ return 1;
}
-static void ossl_init_no_add_algs(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_add_algs)
{
/* Do nothing */
- return;
+ return 1;
}
static CRYPTO_ONCE config = CRYPTO_ONCE_STATIC_INIT;
static int config_inited = 0;
static const char *appname;
-static void ossl_init_config(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_config)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr,
#endif
openssl_config_int(appname);
config_inited = 1;
+ return 1;
}
-static void ossl_init_no_config(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_config)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr,
#endif
openssl_no_config_int();
config_inited = 1;
+ return 1;
}
static CRYPTO_ONCE async = CRYPTO_ONCE_STATIC_INIT;
static int async_inited = 0;
-static void ossl_init_async(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_async)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_async: async_init()\n");
#endif
- async_init();
+ if (!async_init())
+ return 0;
async_inited = 1;
+ return 1;
}
#ifndef OPENSSL_NO_ENGINE
static CRYPTO_ONCE engine_openssl = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_openssl(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_openssl)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_openssl: "
"engine_load_openssl_int()\n");
# endif
engine_load_openssl_int();
+ return 1;
}
# if !defined(OPENSSL_NO_HW) && \
(defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
static CRYPTO_ONCE engine_cryptodev = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_cryptodev(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_cryptodev)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_cryptodev: "
"engine_load_cryptodev_int()\n");
# endif
engine_load_cryptodev_int();
+ return 1;
}
# endif
# ifndef OPENSSL_NO_RDRAND
static CRYPTO_ONCE engine_rdrand = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_rdrand(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_rdrand)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_rdrand: "
"engine_load_rdrand_int()\n");
# endif
engine_load_rdrand_int();
+ return 1;
}
# endif
static CRYPTO_ONCE engine_dynamic = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_dynamic(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_dynamic)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dynamic: "
"engine_load_dynamic_int()\n");
# endif
engine_load_dynamic_int();
+ return 1;
}
# ifndef OPENSSL_NO_STATIC_ENGINE
# if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
static CRYPTO_ONCE engine_padlock = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_padlock(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_padlock)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_padlock: "
"engine_load_padlock_int()\n");
# endif
engine_load_padlock_int();
+ return 1;
}
# endif
# if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
static CRYPTO_ONCE engine_capi = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_capi(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_capi)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_capi: "
"engine_load_capi_int()\n");
# endif
engine_load_capi_int();
+ return 1;
}
# endif
static CRYPTO_ONCE engine_dasync = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_dasync(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_dasync)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dasync: "
"engine_load_dasync_int()\n");
# endif
engine_load_dasync_int();
+ return 1;
}
# if !defined(OPENSSL_NO_AFALGENG)
static CRYPTO_ONCE engine_afalg = CRYPTO_ONCE_STATIC_INIT;
-static void ossl_init_engine_afalg(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_engine_afalg)
{
# ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_afalg: "
"engine_load_afalg_int()\n");
# endif
engine_load_afalg_int();
+ return 1;
}
# endif
# endif
static CRYPTO_ONCE zlib = CRYPTO_ONCE_STATIC_INIT;
static int zlib_inited = 0;
-static void ossl_init_zlib(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_zlib)
{
/* Do nothing - we need to know about this for the later cleanup */
zlib_inited = 1;
+ return 1;
}
#endif
return 0;
}
- if (!CRYPTO_THREAD_run_once(&base, ossl_init_base))
+ if (!RUN_ONCE(&base, ossl_init_base))
return 0;
if ((opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
- && !CRYPTO_THREAD_run_once(&load_crypto_strings,
- ossl_init_no_load_crypto_strings))
+ && !RUN_ONCE(&load_crypto_strings,
+ ossl_init_no_load_crypto_strings))
return 0;
if ((opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
- && !CRYPTO_THREAD_run_once(&load_crypto_strings,
- ossl_init_load_crypto_strings))
+ && !RUN_ONCE(&load_crypto_strings, ossl_init_load_crypto_strings))
return 0;
if ((opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
- && !CRYPTO_THREAD_run_once(&add_all_ciphers, ossl_init_no_add_algs))
+ && !RUN_ONCE(&add_all_ciphers, ossl_init_no_add_algs))
return 0;
if ((opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
- && !CRYPTO_THREAD_run_once(&add_all_ciphers,
- ossl_init_add_all_ciphers))
+ && !RUN_ONCE(&add_all_ciphers, ossl_init_add_all_ciphers))
return 0;
if ((opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
- && !CRYPTO_THREAD_run_once(&add_all_digests, ossl_init_no_add_algs))
+ && !RUN_ONCE(&add_all_digests, ossl_init_no_add_algs))
return 0;
if ((opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
- && !CRYPTO_THREAD_run_once(&add_all_digests,
- ossl_init_add_all_digests))
+ && !RUN_ONCE(&add_all_digests, ossl_init_add_all_digests))
return 0;
if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG)
- && !CRYPTO_THREAD_run_once(&config, ossl_init_no_config))
+ && !RUN_ONCE(&config, ossl_init_no_config))
return 0;
if (opts & OPENSSL_INIT_LOAD_CONFIG) {
int ret;
CRYPTO_THREAD_write_lock(init_lock);
appname = (settings == NULL) ? NULL : settings->appname;
- ret = CRYPTO_THREAD_run_once(&config, ossl_init_config);
+ ret = RUN_ONCE(&config, ossl_init_config);
CRYPTO_THREAD_unlock(init_lock);
if (!ret)
return 0;
}
if ((opts & OPENSSL_INIT_ASYNC)
- && !CRYPTO_THREAD_run_once(&async, ossl_init_async))
+ && !RUN_ONCE(&async, ossl_init_async))
return 0;
#ifndef OPENSSL_NO_ENGINE
if ((opts & OPENSSL_INIT_ENGINE_OPENSSL)
- && !CRYPTO_THREAD_run_once(&engine_openssl,
- ossl_init_engine_openssl))
+ && !RUN_ONCE(&engine_openssl, ossl_init_engine_openssl))
return 0;
# if !defined(OPENSSL_NO_HW) && \
(defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
if ((opts & OPENSSL_INIT_ENGINE_CRYPTODEV)
- && !CRYPTO_THREAD_run_once(&engine_cryptodev,
- ossl_init_engine_cryptodev))
+ && !RUN_ONCE(&engine_cryptodev, ossl_init_engine_cryptodev))
return 0;
# endif
# ifndef OPENSSL_NO_RDRAND
if ((opts & OPENSSL_INIT_ENGINE_RDRAND)
- && !CRYPTO_THREAD_run_once(&engine_rdrand, ossl_init_engine_rdrand))
+ && !RUN_ONCE(&engine_rdrand, ossl_init_engine_rdrand))
return 0;
# endif
if ((opts & OPENSSL_INIT_ENGINE_DYNAMIC)
- && !CRYPTO_THREAD_run_once(&engine_dynamic,
- ossl_init_engine_dynamic))
+ && !RUN_ONCE(&engine_dynamic, ossl_init_engine_dynamic))
return 0;
# ifndef OPENSSL_NO_STATIC_ENGINE
# if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
if ((opts & OPENSSL_INIT_ENGINE_PADLOCK)
- && !CRYPTO_THREAD_run_once(&engine_padlock,
- ossl_init_engine_padlock))
+ && !RUN_ONCE(&engine_padlock, ossl_init_engine_padlock))
return 0;
# endif
# if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
if ((opts & OPENSSL_INIT_ENGINE_CAPI)
- && !CRYPTO_THREAD_run_once(&engine_capi, ossl_init_engine_capi))
+ && !RUN_ONCE(&engine_capi, ossl_init_engine_capi))
return 0;
# endif
if ((opts & OPENSSL_INIT_ENGINE_DASYNC)
- && !CRYPTO_THREAD_run_once(&engine_dasync, ossl_init_engine_dasync))
+ && !RUN_ONCE(&engine_dasync, ossl_init_engine_dasync))
return 0;
# if !defined(OPENSSL_NO_AFALGENG)
if ((opts & OPENSSL_INIT_ENGINE_AFALG)
- && !CRYPTO_THREAD_run_once(&engine_afalg, ossl_init_engine_afalg))
+ && !RUN_ONCE(&engine_afalg, ossl_init_engine_afalg))
return 0;
# endif
# endif
#ifndef OPENSSL_NO_COMP
if ((opts & OPENSSL_INIT_ZLIB)
- && !CRYPTO_THREAD_run_once(&zlib, ossl_init_zlib))
+ && !RUN_ONCE(&zlib, ossl_init_zlib))
return 0;
#endif
#else
int ret = mh_mode;
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return -1;
CRYPTO_THREAD_write_lock(malloc_lock);
switch (mode) {
CRYPTO_THREAD_ID cur;
if (mh_mode & CRYPTO_MEM_CHECK_ON) {
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return 0;
cur = CRYPTO_THREAD_get_current_id();
CRYPTO_THREAD_read_lock(malloc_lock);
{
APP_INFO *current = NULL;
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return 0;
+
current = (APP_INFO *)CRYPTO_THREAD_get_local(&appinfokey);
if (current != NULL) {
APP_INFO *next = current->next;
if (mem_check_on()) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
-
- if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL)
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init)
+ || (ami = OPENSSL_malloc(sizeof(*ami))) == NULL)
goto err;
ami->threadid = CRYPTO_THREAD_get_current_id();
if (mem_check_on()) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
-
- if ((m = OPENSSL_malloc(sizeof(*m))) == NULL) {
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init)
+ || (m = OPENSSL_malloc(sizeof(*m))) == NULL) {
OPENSSL_free(addr);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
return;
/* Ensure all resources are released */
OPENSSL_cleanup();
- CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init);
+ if (!RUN_ONCE(&memdbg_init, do_memdbg_init))
+ return -1;
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
#include <openssl/err.h>
+#include <internal/thread_once.h>
+
#ifdef OPENSSL_FIPS
# include <openssl/fips.h>
#endif
rand_status
};
-static void do_rand_lock_init(void)
+DEFINE_RUN_ONCE_STATIC(do_rand_lock_init)
{
rand_lock = CRYPTO_THREAD_lock_new();
rand_tmp_lock = CRYPTO_THREAD_lock_new();
+ return rand_lock != NULL && rand_tmp_lock != NULL;
}
RAND_METHOD *RAND_OpenSSL(void)
if (m == NULL)
goto err;
- CRYPTO_THREAD_run_once(&rand_lock_init, do_rand_lock_init);
+ if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))
+ goto err;
/* check if we already have the lock */
if (crypto_lock_rand) {
* global 'md'.
*/
- CRYPTO_THREAD_run_once(&rand_lock_init, do_rand_lock_init);
+ if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))
+ goto err_mem;
+
CRYPTO_THREAD_write_lock(rand_lock);
/*
* We could end up in an async engine while holding this lock so ensure
int ret;
int do_not_lock;
- CRYPTO_THREAD_run_once(&rand_lock_init, do_rand_lock_init);
+ if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))
+ return 0;
+
cur = CRYPTO_THREAD_get_current_id();
/*
* check if we already have the lock (could happen if a RAND_poll()
void ERR_add_error_data(int num, ...);
void ERR_add_error_vdata(int num, va_list args);
void ERR_load_strings(int lib, ERR_STRING_DATA str[]);
-void ERR_unload_strings(int lib, ERR_STRING_DATA str[]);
+int ERR_unload_strings(int lib, ERR_STRING_DATA str[]);
void ERR_load_ERR_strings(void);
#if OPENSSL_API_COMPAT < 0x10100000L
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include "ssl_locl.h"
+#include "internal/thread_once.h"
static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, int op,
int bits, int nid, void *other,
static CRYPTO_ONCE ssl_x509_store_ctx_once = CRYPTO_ONCE_STATIC_INIT;
static volatile int ssl_x509_store_ctx_idx = -1;
-static void ssl_x509_store_ctx_init(void)
+DEFINE_RUN_ONCE_STATIC(ssl_x509_store_ctx_init)
{
ssl_x509_store_ctx_idx = X509_STORE_CTX_get_ex_new_index(0,
"SSL for verify callback",
NULL, NULL, NULL);
+ return ssl_x509_store_ctx_idx >= 0;
}
int SSL_get_ex_data_X509_STORE_CTX_idx(void)
{
- CRYPTO_THREAD_run_once(&ssl_x509_store_ctx_once, ssl_x509_store_ctx_init);
+ if (!RUN_ONCE(&ssl_x509_store_ctx_once, ssl_x509_store_ctx_init))
+ return -1;
return ssl_x509_store_ctx_idx;
}
#include <openssl/engine.h>
#include <openssl/crypto.h>
#include "ssl_locl.h"
+#include "internal/thread_once.h"
#define SSL_ENC_DES_IDX 0
#define SSL_ENC_3DES_IDX 1
return ((*a)->id - (*b)->id);
}
-static void do_load_builtin_compressions(void)
+DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)
{
SSL_COMP *comp = NULL;
COMP_METHOD *method = COMP_zlib();
}
}
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+ return 1;
}
static void load_builtin_compressions(void)
{
- CRYPTO_THREAD_run_once(&ssl_load_builtin_comp_once,
- do_load_builtin_compressions);
+ RUN_ONCE(&ssl_load_builtin_comp_once, do_load_builtin_compressions);
}
#endif
#include <openssl/evp.h>
#include <assert.h>
#include "ssl_locl.h"
+#include "internal/thread_once.h"
static int stopped;
static CRYPTO_ONCE ssl_base = CRYPTO_ONCE_STATIC_INIT;
static int ssl_base_inited = 0;
-static void ossl_init_ssl_base(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_ssl_base)
{
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_ssl_base: "
*/
OPENSSL_atexit(ssl_library_stop);
ssl_base_inited = 1;
+ return 1;
}
static CRYPTO_ONCE ssl_strings = CRYPTO_ONCE_STATIC_INIT;
static int ssl_strings_inited = 0;
-static void ossl_init_load_ssl_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_load_ssl_strings)
{
/*
* OPENSSL_NO_AUTOERRINIT is provided here to prevent at compile time
ERR_load_SSL_strings();
#endif
ssl_strings_inited = 1;
+ return 1;
}
-static void ossl_init_no_load_ssl_strings(void)
+DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_ssl_strings)
{
/* Do nothing in this case */
- return;
+ return 1;
}
static void ssl_library_stop(void)
| OPENSSL_INIT_ADD_ALL_DIGESTS, settings))
return 0;
- if (!CRYPTO_THREAD_run_once(&ssl_base, ossl_init_ssl_base))
+ if (!RUN_ONCE(&ssl_base, ossl_init_ssl_base))
return 0;
if ((opts & OPENSSL_INIT_NO_LOAD_SSL_STRINGS)
- && !CRYPTO_THREAD_run_once(&ssl_strings,
- ossl_init_no_load_ssl_strings))
+ && !RUN_ONCE(&ssl_strings, ossl_init_no_load_ssl_strings))
return 0;
if ((opts & OPENSSL_INIT_LOAD_SSL_STRINGS)
- && !CRYPTO_THREAD_run_once(&ssl_strings,
- ossl_init_load_ssl_strings))
+ && !RUN_ONCE(&ssl_strings, ossl_init_load_ssl_strings))
return 0;
return 1;