/*
- * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* https://www.openssl.org/source/license.html
*/
+#include "e_os.h"
#include "eng_int.h"
#include <openssl/rand.h>
+#include "internal/refcount.h"
CRYPTO_RWLOCK *global_engine_lock;
DEFINE_RUN_ONCE(do_engine_lock_init)
{
+ OPENSSL_init_crypto(0, NULL);
global_engine_lock = CRYPTO_THREAD_lock_new();
return global_engine_lock != NULL;
}
e->flags = 0;
}
-int engine_free_util(ENGINE *e, int locked)
+int engine_free_util(ENGINE *e, int not_locked)
{
int i;
if (e == NULL)
return 1;
- if (locked)
+#ifdef HAVE_ATOMICS
+ CRYPTO_DOWN_REF(&e->struct_ref, &i, global_engine_lock);
+#else
+ if (not_locked)
CRYPTO_atomic_add(&e->struct_ref, -1, &i, global_engine_lock);
else
i = --e->struct_ref;
- engine_ref_debug(e, 0, -1)
+#endif
+ engine_ref_debug(e, 0, -1);
if (i > 0)
return 1;
REF_ASSERT_ISNT(i < 0);
engine_cleanup_cb_free);
cleanup_stack = NULL;
}
- /*
- * FIXME: This should be handled (somehow) through RAND, eg. by it
- * registering a cleanup callback.
- */
- RAND_set_rand_method(NULL);
CRYPTO_THREAD_lock_free(global_engine_lock);
}
int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg)
{
- return (CRYPTO_set_ex_data(&e->ex_data, idx, arg));
+ return CRYPTO_set_ex_data(&e->ex_data, idx, arg);
}
void *ENGINE_get_ex_data(const ENGINE *e, int idx)
{
- return (CRYPTO_get_ex_data(&e->ex_data, idx));
+ return CRYPTO_get_ex_data(&e->ex_data, idx);
}
/*