2 * Written by Matt Caswell for the OpenSSL project.
4 /* ====================================================================
5 * Copyright (c) 2016 The OpenSSL Project. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
33 * 6. Redistributions of any form whatsoever must retain the following
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
58 #include <openssl/e_os2.h>
60 #if defined(OPENSSL_SYS_WINDOWS) && !defined(_WIN32_WINNT)
62 * We default to requiring Windows Vista, Windows Server 2008 or later. We can
63 * support lower versions if _WIN32_WINNT is explicity defined to something
66 # define _WIN32_WINNT 0x0600
69 #include <internal/cryptlib_int.h>
70 #include <openssl/err.h>
71 #include <openssl/evp.h>
72 #include <internal/evp_int.h>
73 #include <internal/conf.h>
74 #include <internal/async.h>
75 #include <internal/engine.h>
76 #include <openssl/comp.h>
77 #include <internal/err.h>
80 static void ossl_init_thread_stop(struct thread_local_inits_st *locals);
82 /* Implement "once" functionality */
83 #if !defined(OPENSSL_THREADS)
84 typedef int OPENSSL_INIT_ONCE;
85 # define OPENSSL_INIT_ONCE_STATIC_INIT 0
86 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = 0)
88 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
90 if (*once == OPENSSL_INIT_ONCE_STATIC_INIT) {
96 static int ossl_init_setup_thread_stop(void)
99 * There are no threads to stop. Do nothing.
104 static void ossl_init_thread_stop_cleanup(void)
108 static struct thread_local_inits_st *local = NULL;
109 void *ossl_init_get_thread_local(int alloc)
111 if (local == NULL && alloc)
112 local = OPENSSL_zalloc(sizeof(*local));
116 #elif defined(OPENSSL_SYS_WINDOWS)
118 # include <windows.h>
120 # if _WIN32_WINNT < 0x0600
123 * Versions before 0x0600 (Windows Vista, Windows Server 2008 or later) do not
124 * have InitOnceExecuteOnce, so we fall back to using a spinlock instead.
126 typedef LONG OPENSSL_INIT_ONCE;
127 # define OPENSSL_INIT_ONCE_STATIC_INIT 0
128 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = 0)
130 # define ONCE_UNINITED 0
131 # define ONCE_ININIT 1
134 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
136 LONG volatile *lock = (LONG *)once;
139 if (*lock == ONCE_DONE)
143 result = InterlockedCompareExchange(lock, ONCE_ININIT, ONCE_UNINITED);
144 if (result == ONCE_UNINITED) {
149 } while (result == ONCE_ININIT);
154 typedef INIT_ONCE OPENSSL_INIT_ONCE;
155 # define OPENSSL_INIT_ONCE_STATIC_INIT INIT_ONCE_STATIC_INIT
156 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) \
157 InitOnceInitialize((PINIT_ONCE)(once))
159 static BOOL CALLBACK once_cb(PINIT_ONCE once, PVOID initfp, PVOID *unused)
161 void (*init)(void) = initfp;
168 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
170 InitOnceExecuteOnce((INIT_ONCE *)once, once_cb, init, NULL);
174 DWORD threadstopkey = TLS_OUT_OF_INDEXES;
176 static int ossl_init_setup_thread_stop(void)
179 * We use a dummy thread local key here. We use the destructor to detect
180 * when the thread is going to stop
182 threadstopkey = TlsAlloc();
183 if (threadstopkey == TLS_OUT_OF_INDEXES)
189 static void ossl_init_thread_stop_cleanup(void)
191 if (threadstopkey != TLS_OUT_OF_INDEXES) {
192 TlsFree(threadstopkey);
196 void *ossl_init_get_thread_local(int alloc)
198 struct thread_local_inits_st *local = TlsGetValue(threadstopkey);
200 if (local == NULL && alloc) {
201 local = OPENSSL_zalloc(sizeof *local);
202 TlsSetValue(threadstopkey, local);
209 # include <pthread.h>
211 pthread_key_t threadstopkey;
213 typedef pthread_once_t OPENSSL_INIT_ONCE;
214 # define OPENSSL_INIT_ONCE_STATIC_INIT PTHREAD_ONCE_INIT
215 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = PTHREAD_ONCE_INIT)
217 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
219 pthread_once(once, init);
222 static void ossl_init_thread_stop_wrap(void *local)
224 ossl_init_thread_stop((struct thread_local_inits_st *)local);
227 static int ossl_init_setup_thread_stop(void)
230 * We use a dummy thread local key here. We use the destructor to detect
231 * when the thread is going to stop
233 return (pthread_key_create(&threadstopkey,
234 ossl_init_thread_stop_wrap) == 0);
237 static void ossl_init_thread_stop_cleanup(void)
241 void *ossl_init_get_thread_local(int alloc)
243 struct thread_local_inits_st *local = pthread_getspecific(threadstopkey);
245 if (local == NULL && alloc) {
246 local = OPENSSL_zalloc(sizeof *local);
247 pthread_setspecific(threadstopkey, local);
255 struct ossl_init_stop_st {
256 void (*handler)(void);
257 OPENSSL_INIT_STOP *next;
260 static OPENSSL_INIT_STOP *stop_handlers = NULL;
262 static OPENSSL_INIT_ONCE base = OPENSSL_INIT_ONCE_STATIC_INIT;
263 static int base_inited = 0;
264 static void ossl_init_base(void)
266 #ifdef OPENSSL_INIT_DEBUG
267 fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
269 ossl_init_setup_thread_stop();
270 atexit(OPENSSL_INIT_library_stop);
271 OPENSSL_cpuid_setup();
275 static OPENSSL_INIT_ONCE load_crypto_strings = OPENSSL_INIT_ONCE_STATIC_INIT;
276 static int load_crypto_strings_inited = 0;
277 static void ossl_init_no_load_crypto_strings(void)
279 /* Do nothing in this case */
283 static void ossl_init_load_crypto_strings(void)
286 * OPENSSL_NO_AUTOERRINIT is provided here to prevent at compile time
287 * pulling in all the error strings during static linking
289 #if !defined(OPENSSL_NO_ERR) && !defined(OPENSSL_NO_AUTOERRINIT)
290 # ifdef OPENSSL_INIT_DEBUG
291 fprintf(stderr, "OPENSSL_INIT: ossl_init_load_crypto_strings: "
292 "err_load_crypto_strings_intern()\n");
294 err_load_crypto_strings_intern();
296 load_crypto_strings_inited = 1;
299 static OPENSSL_INIT_ONCE add_all_ciphers = OPENSSL_INIT_ONCE_STATIC_INIT;
300 static void ossl_init_add_all_ciphers(void)
303 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
304 * pulling in all the ciphers during static linking
306 #ifndef OPENSSL_NO_AUTOALGINIT
307 # ifdef OPENSSL_INIT_DEBUG
308 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_ciphers: "
309 "openssl_add_all_ciphers_internal()\n");
311 openssl_add_all_ciphers_internal();
312 # ifndef OPENSSL_NO_ENGINE
313 # if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
314 ENGINE_setup_bsd_cryptodev();
320 static OPENSSL_INIT_ONCE add_all_digests = OPENSSL_INIT_ONCE_STATIC_INIT;
321 static void ossl_init_add_all_digests(void)
324 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
325 * pulling in all the ciphers during static linking
327 #ifndef OPENSSL_NO_AUTOALGINIT
328 # ifdef OPENSSL_INIT_DEBUG
329 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_digests: "
330 "openssl_add_all_digests_internal()\n");
332 openssl_add_all_digests_internal();
333 # ifndef OPENSSL_NO_ENGINE
334 # if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
335 ENGINE_setup_bsd_cryptodev();
341 static void ossl_init_no_add_algs(void)
347 static OPENSSL_INIT_ONCE config = OPENSSL_INIT_ONCE_STATIC_INIT;
348 static int config_inited = 0;
349 static const char *config_filename;
350 static void ossl_init_config(void)
352 #ifdef OPENSSL_INIT_DEBUG
354 "OPENSSL_INIT: ossl_init_config: openssl_config_internal(%s)\n",
355 config_filename==NULL?"NULL":config_filename);
357 openssl_config_internal(config_filename);
360 static void ossl_init_no_config(void)
362 #ifdef OPENSSL_INIT_DEBUG
364 "OPENSSL_INIT: ossl_init_config: openssl_no_config_internal()\n");
366 openssl_no_config_internal();
370 static OPENSSL_INIT_ONCE async = OPENSSL_INIT_ONCE_STATIC_INIT;
371 static int async_inited = 0;
372 static void ossl_init_async(void)
374 #ifdef OPENSSL_INIT_DEBUG
375 fprintf(stderr, "OPENSSL_INIT: ossl_init_async: async_init()\n");
381 #ifndef OPENSSL_NO_ENGINE
382 static int engine_inited = 0;
383 static OPENSSL_INIT_ONCE engine_openssl = OPENSSL_INIT_ONCE_STATIC_INIT;
384 static void ossl_init_engine_openssl(void)
386 # ifdef OPENSSL_INIT_DEBUG
387 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_openssl: "
388 "engine_load_openssl_internal()\n");
390 engine_load_openssl_internal();
393 # if !defined(OPENSSL_NO_HW) && \
394 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
395 static OPENSSL_INIT_ONCE engine_cryptodev = OPENSSL_INIT_ONCE_STATIC_INIT;
396 static void ossl_init_engine_cryptodev(void)
398 # ifdef OPENSSL_INIT_DEBUG
399 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_cryptodev: "
400 "engine_load_cryptodev_internal()\n");
402 engine_load_cryptodev_internal();
407 # ifndef OPENSSL_NO_RDRAND
408 static OPENSSL_INIT_ONCE engine_rdrand = OPENSSL_INIT_ONCE_STATIC_INIT;
409 static void ossl_init_engine_rdrand(void)
411 # ifdef OPENSSL_INIT_DEBUG
412 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_rdrand: "
413 "engine_load_rdrand_internal()\n");
415 engine_load_rdrand_internal();
419 static OPENSSL_INIT_ONCE engine_dynamic = OPENSSL_INIT_ONCE_STATIC_INIT;
420 static void ossl_init_engine_dynamic(void)
422 # ifdef OPENSSL_INIT_DEBUG
423 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dynamic: "
424 "engine_load_dynamic_internal()\n");
426 engine_load_dynamic_internal();
429 # ifndef OPENSSL_NO_STATIC_ENGINE
430 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
431 static OPENSSL_INIT_ONCE engine_padlock = OPENSSL_INIT_ONCE_STATIC_INIT;
432 static void ossl_init_engine_padlock(void)
434 # ifdef OPENSSL_INIT_DEBUG
435 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_padlock: "
436 "engine_load_padlock_internal()\n");
438 engine_load_padlock_internal();
442 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
443 static OPENSSL_INIT_ONCE engine_capi = OPENSSL_INIT_ONCE_STATIC_INIT;
444 static void ossl_init_engine_capi(void)
446 # ifdef OPENSSL_INIT_DEBUG
447 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_capi: "
448 "engine_load_capi_internal()\n");
450 engine_load_capi_internal();
454 static OPENSSL_INIT_ONCE engine_dasync = OPENSSL_INIT_ONCE_STATIC_INIT;
455 static void ossl_init_engine_dasync(void)
457 # ifdef OPENSSL_INIT_DEBUG
458 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dasync: "
459 "engine_load_dasync_internal()\n");
461 engine_load_dasync_internal();
467 static OPENSSL_INIT_ONCE zlib = OPENSSL_INIT_ONCE_STATIC_INIT;
468 static int zlib_inited = 0;
469 static void ossl_init_zlib(void)
471 /* Do nothing - we need to know about this for the later cleanup */
475 static void ossl_init_thread_stop(struct thread_local_inits_st *locals)
477 /* Can't do much about this */
482 #ifdef OPENSSL_INIT_DEBUG
483 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
484 "ASYNC_cleanup_thread()\n");
486 ASYNC_cleanup_thread();
489 if (locals->err_state) {
490 #ifdef OPENSSL_INIT_DEBUG
491 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
492 "ERR_remove_thread_state(NULL)\n");
494 ERR_remove_thread_state(NULL);
497 OPENSSL_free(locals);
498 ossl_init_thread_stop_cleanup();
501 void OPENSSL_INIT_thread_stop(void)
503 ossl_init_thread_stop(
504 (struct thread_local_inits_st *)ossl_init_get_thread_local(0));
507 int ossl_init_thread_start(uint64_t opts)
509 struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);
514 if (opts & OPENSSL_INIT_THREAD_ASYNC) {
515 #ifdef OPENSSL_INIT_DEBUG
516 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
517 "marking thread for async\n");
522 if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
523 #ifdef OPENSSL_INIT_DEBUG
524 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
525 "marking thread for err_state\n");
527 locals->err_state = 1;
533 void OPENSSL_INIT_library_stop(void)
535 OPENSSL_INIT_STOP *currhandler, *lasthandler;
538 * Thread stop may not get automatically called by the thread library for
539 * the very last thread in some situations, so call it directly.
541 ossl_init_thread_stop(ossl_init_get_thread_local(0));
543 currhandler = stop_handlers;
544 while (currhandler != NULL) {
545 currhandler->handler();
546 lasthandler = currhandler;
547 currhandler = currhandler->next;
548 OPENSSL_free(lasthandler);
550 stop_handlers = NULL;
552 * We assume we are single-threaded for this function, i.e. no race
553 * conditions for the various "*_inited" vars below.
557 #ifdef OPENSSL_INIT_DEBUG
558 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
559 "COMP_zlib_cleanup()\n");
563 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&zlib);
566 #ifndef OPENSSL_NO_ENGINE
568 # ifdef OPENSSL_INIT_DEBUG
569 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
570 "ENGINE_cleanup()\n");
574 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_openssl);
575 # if !defined(OPENSSL_NO_HW) && \
576 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
577 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_cryptodev);
579 # ifndef OPENSSL_NO_RDRAND
580 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_rdrand);
582 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_dynamic);
583 # ifndef OPENSSL_NO_STATIC_ENGINE
584 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
585 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_padlock);
587 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
588 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_capi);
590 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_dasync);
596 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&async);
599 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&config);
600 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&add_all_ciphers);
601 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&add_all_digests);
603 if (load_crypto_strings_inited) {
604 #ifdef OPENSSL_INIT_DEBUG
605 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
606 "ERR_free_strings()\n");
609 load_crypto_strings_inited = 0;
610 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&load_crypto_strings);
614 #ifdef OPENSSL_INIT_DEBUG
615 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
616 "CRYPTO_cleanup_all_ex_data()\n");
617 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
619 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
620 "CONF_modules_free()\n");
621 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
624 CRYPTO_cleanup_all_ex_data();
629 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&base);
633 static const OPENSSL_INIT_SETTINGS *ossl_init_get_setting(
634 const OPENSSL_INIT_SETTINGS *settings, int name)
636 if (settings == NULL)
639 while (settings->name != OPENSSL_INIT_SET_END) {
640 if (settings->name == name)
649 * If this function is called with a non NULL settings value then it must be
650 * called prior to any threads making calls to any OpenSSL functions,
651 * i.e. passing a non-null settings value is assumed to be single-threaded.
653 void OPENSSL_INIT_crypto_library_start(uint64_t opts,
654 const OPENSSL_INIT_SETTINGS *settings)
656 ossl_init_once_run(&base, ossl_init_base);
658 if (opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
659 ossl_init_once_run(&load_crypto_strings,
660 ossl_init_no_load_crypto_strings);
662 if (opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
663 ossl_init_once_run(&load_crypto_strings, ossl_init_load_crypto_strings);
665 if (opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
666 ossl_init_once_run(&add_all_ciphers, ossl_init_no_add_algs);
668 if (opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
669 ossl_init_once_run(&add_all_ciphers, ossl_init_add_all_ciphers);
671 if (opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
672 ossl_init_once_run(&add_all_digests, ossl_init_no_add_algs);
674 if (opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
675 ossl_init_once_run(&add_all_digests, ossl_init_add_all_digests);
677 if (opts & OPENSSL_INIT_NO_LOAD_CONFIG) {
678 ossl_init_once_run(&config, ossl_init_no_config);
681 if (opts & OPENSSL_INIT_LOAD_CONFIG) {
682 if (settings != NULL) {
683 const OPENSSL_INIT_SETTINGS *curr;
684 curr = ossl_init_get_setting(settings,
685 OPENSSL_INIT_SET_CONF_FILENAME);
686 config_filename = curr == NULL ? NULL : curr->value.type_string;
688 ossl_init_once_run(&config, ossl_init_config);
691 if (opts & OPENSSL_INIT_ASYNC) {
692 ossl_init_once_run(&async, ossl_init_async);
695 #ifndef OPENSSL_NO_ENGINE
696 if (opts & OPENSSL_INIT_ENGINE_OPENSSL) {
697 ossl_init_once_run(&engine_openssl, ossl_init_engine_openssl);
699 # if !defined(OPENSSL_NO_HW) && \
700 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
701 if (opts & OPENSSL_INIT_ENGINE_CRYPTODEV) {
702 ossl_init_once_run(&engine_cryptodev, ossl_init_engine_cryptodev);
705 # ifndef OPENSSL_NO_RDRAND
706 if (opts & OPENSSL_INIT_ENGINE_RDRAND) {
707 ossl_init_once_run(&engine_rdrand, ossl_init_engine_rdrand);
710 if (opts & OPENSSL_INIT_ENGINE_DYNAMIC) {
711 ossl_init_once_run(&engine_dynamic, ossl_init_engine_dynamic);
713 # ifndef OPENSSL_NO_STATIC_ENGINE
714 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
715 if (opts & OPENSSL_INIT_ENGINE_PADLOCK) {
716 ossl_init_once_run(&engine_padlock, ossl_init_engine_padlock);
719 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
720 if (opts & OPENSSL_INIT_ENGINE_CAPI) {
721 ossl_init_once_run(&engine_capi, ossl_init_engine_capi);
724 if (opts & OPENSSL_INIT_ENGINE_DASYNC) {
725 ossl_init_once_run(&engine_dasync, ossl_init_engine_dasync);
728 if (opts & (OPENSSL_INIT_ENGINE_ALL_BUILTIN
729 | OPENSSL_INIT_ENGINE_DASYNC | OPENSSL_INIT_ENGINE_OPENSSL)) {
730 ENGINE_register_all_complete();
734 if (opts & OPENSSL_INIT_ZLIB) {
735 ossl_init_once_run(&zlib, ossl_init_zlib);
739 int OPENSSL_INIT_register_stop_handler(void (*handler)(void))
741 OPENSSL_INIT_STOP *newhand;
743 newhand = OPENSSL_malloc(sizeof(*newhand));
747 newhand->handler = handler;
748 newhand->next = stop_handlers;
749 stop_handlers = newhand;