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 <internal/cryptlib_int.h>
59 #include <openssl/err.h>
60 #include <openssl/evp.h>
61 #include <internal/evp_int.h>
62 #include <internal/conf.h>
63 #include <internal/async.h>
64 #include <internal/engine.h>
65 #include <openssl/comp.h>
66 #include <internal/err.h>
69 static void ossl_init_thread_stop(struct thread_local_inits_st *locals);
71 /* Implement "once" functionality */
72 #if !defined(OPENSSL_THREADS)
73 typedef int OPENSSL_INIT_ONCE;
74 # define OPENSSL_INIT_ONCE_STATIC_INIT 0
75 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = 0)
77 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
79 if (*once == OPENSSL_INIT_ONCE_STATIC_INIT) {
85 static int ossl_init_setup_thread_stop(void)
88 * There are no threads to stop. Do nothing.
93 static void ossl_init_thread_stop_cleanup(void)
97 static struct thread_local_inits_st *local = NULL;
98 void *ossl_init_get_thread_local(int alloc)
100 if (local == NULL && alloc)
101 local = OPENSSL_zalloc(sizeof(*local));
105 #elif defined(OPENSSL_SYS_WINDOWS)
107 # include <windows.h>
109 # if _WIN32_WINNT < 0x0600
112 * Versions before 0x0600 (Windows Vista, Windows Server 2008 or later) do not
113 * have InitOnceExecuteOnce, so we fall back to using a spinlock instead.
115 typedef LONG OPENSSL_INIT_ONCE;
116 # define OPENSSL_INIT_ONCE_STATIC_INIT 0
117 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = 0)
119 # define ONCE_UNINITED 0
120 # define ONCE_ININIT 1
123 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
125 LONG volatile *lock = (LONG *)once;
128 if (*lock == ONCE_DONE)
132 result = InterlockedCompareExchange(lock, ONCE_ININIT, ONCE_UNINITED);
133 if (result == ONCE_UNINITED) {
138 } while (result == ONCE_ININIT);
143 typedef INIT_ONCE OPENSSL_INIT_ONCE;
144 # define OPENSSL_INIT_ONCE_STATIC_INIT INIT_ONCE_STATIC_INIT
145 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) \
146 InitOnceInitialize((PINIT_ONCE)(once))
148 static BOOL CALLBACK once_cb(PINIT_ONCE once, PVOID initfp, PVOID *unused)
150 void (*init)(void) = initfp;
157 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
159 InitOnceExecuteOnce((INIT_ONCE *)once, once_cb, init, NULL);
163 DWORD threadstopkey = TLS_OUT_OF_INDEXES;
165 static int ossl_init_setup_thread_stop(void)
168 * We use a dummy thread local key here. We use the destructor to detect
169 * when the thread is going to stop
171 threadstopkey = TlsAlloc();
172 if (threadstopkey == TLS_OUT_OF_INDEXES)
178 static void ossl_init_thread_stop_cleanup(void)
180 if (threadstopkey != TLS_OUT_OF_INDEXES) {
181 TlsFree(threadstopkey);
185 void *ossl_init_get_thread_local(int alloc)
187 struct thread_local_inits_st *local = TlsGetValue(threadstopkey);
189 if (local == NULL && alloc) {
190 local = OPENSSL_zalloc(sizeof *local);
191 TlsSetValue(threadstopkey, local);
198 # include <pthread.h>
200 pthread_key_t threadstopkey;
202 typedef pthread_once_t OPENSSL_INIT_ONCE;
203 # define OPENSSL_INIT_ONCE_STATIC_INIT PTHREAD_ONCE_INIT
204 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = PTHREAD_ONCE_INIT)
206 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
208 pthread_once(once, init);
211 static void ossl_init_thread_stop_wrap(void *local)
213 ossl_init_thread_stop((struct thread_local_inits_st *)local);
216 static int ossl_init_setup_thread_stop(void)
219 * We use a dummy thread local key here. We use the destructor to detect
220 * when the thread is going to stop
222 return (pthread_key_create(&threadstopkey,
223 ossl_init_thread_stop_wrap) == 0);
226 static void ossl_init_thread_stop_cleanup(void)
230 void *ossl_init_get_thread_local(int alloc)
232 struct thread_local_inits_st *local = pthread_getspecific(threadstopkey);
234 if (local == NULL && alloc) {
235 local = OPENSSL_zalloc(sizeof *local);
236 pthread_setspecific(threadstopkey, local);
244 struct ossl_init_stop_st {
245 void (*handler)(void);
246 OPENSSL_INIT_STOP *next;
249 static OPENSSL_INIT_STOP *stop_handlers = NULL;
251 static OPENSSL_INIT_ONCE base = OPENSSL_INIT_ONCE_STATIC_INIT;
252 static int base_inited = 0;
253 static void ossl_init_base(void)
255 #ifdef OPENSSL_INIT_DEBUG
256 fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
258 ossl_init_setup_thread_stop();
259 atexit(OPENSSL_INIT_library_stop);
260 OPENSSL_cpuid_setup();
264 static OPENSSL_INIT_ONCE load_crypto_strings = OPENSSL_INIT_ONCE_STATIC_INIT;
265 static int load_crypto_strings_inited = 0;
266 static void ossl_init_no_load_crypto_strings(void)
268 /* Do nothing in this case */
272 static void ossl_init_load_crypto_strings(void)
275 * OPENSSL_NO_AUTOERRINIT is provided here to prevent at compile time
276 * pulling in all the error strings during static linking
278 #if !defined(OPENSSL_NO_ERR) && !defined(OPENSSL_NO_AUTOERRINIT)
279 # ifdef OPENSSL_INIT_DEBUG
280 fprintf(stderr, "OPENSSL_INIT: ossl_init_load_crypto_strings: "
281 "err_load_crypto_strings_intern()\n");
283 err_load_crypto_strings_intern();
285 load_crypto_strings_inited = 1;
288 static OPENSSL_INIT_ONCE add_all_ciphers = OPENSSL_INIT_ONCE_STATIC_INIT;
289 static void ossl_init_add_all_ciphers(void)
292 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
293 * pulling in all the ciphers during static linking
295 #ifndef OPENSSL_NO_AUTOALGINIT
296 # ifdef OPENSSL_INIT_DEBUG
297 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_ciphers: "
298 "openssl_add_all_ciphers_internal()\n");
300 openssl_add_all_ciphers_internal();
301 # ifndef OPENSSL_NO_ENGINE
302 # if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
303 ENGINE_setup_bsd_cryptodev();
309 static OPENSSL_INIT_ONCE add_all_digests = OPENSSL_INIT_ONCE_STATIC_INIT;
310 static void ossl_init_add_all_digests(void)
313 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
314 * pulling in all the ciphers during static linking
316 #ifndef OPENSSL_NO_AUTOALGINIT
317 # ifdef OPENSSL_INIT_DEBUG
318 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_digests: "
319 "openssl_add_all_digests_internal()\n");
321 openssl_add_all_digests_internal();
322 # ifndef OPENSSL_NO_ENGINE
323 # if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
324 ENGINE_setup_bsd_cryptodev();
330 static void ossl_init_no_add_algs(void)
336 static OPENSSL_INIT_ONCE config = OPENSSL_INIT_ONCE_STATIC_INIT;
337 static int config_inited = 0;
338 static const char *config_filename;
339 static void ossl_init_config(void)
341 #ifdef OPENSSL_INIT_DEBUG
343 "OPENSSL_INIT: ossl_init_config: openssl_config_internal(%s)\n",
344 config_filename==NULL?"NULL":config_filename);
346 openssl_config_internal(config_filename);
349 static void ossl_init_no_config(void)
351 #ifdef OPENSSL_INIT_DEBUG
353 "OPENSSL_INIT: ossl_init_config: openssl_no_config_internal()\n");
355 openssl_no_config_internal();
359 static OPENSSL_INIT_ONCE async = OPENSSL_INIT_ONCE_STATIC_INIT;
360 static int async_inited = 0;
361 static void ossl_init_async(void)
363 #ifdef OPENSSL_INIT_DEBUG
364 fprintf(stderr, "OPENSSL_INIT: ossl_init_async: async_init()\n");
370 #ifndef OPENSSL_NO_ENGINE
371 static int engine_inited = 0;
372 static OPENSSL_INIT_ONCE engine_openssl = OPENSSL_INIT_ONCE_STATIC_INIT;
373 static void ossl_init_engine_openssl(void)
375 # ifdef OPENSSL_INIT_DEBUG
376 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_openssl: "
377 "engine_load_openssl_internal()\n");
379 engine_load_openssl_internal();
382 # if !defined(OPENSSL_NO_HW) && \
383 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
384 static OPENSSL_INIT_ONCE engine_cryptodev = OPENSSL_INIT_ONCE_STATIC_INIT;
385 static void ossl_init_engine_cryptodev(void)
387 # ifdef OPENSSL_INIT_DEBUG
388 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_cryptodev: "
389 "engine_load_cryptodev_internal()\n");
391 engine_load_cryptodev_internal();
396 # ifndef OPENSSL_NO_RDRAND
397 static OPENSSL_INIT_ONCE engine_rdrand = OPENSSL_INIT_ONCE_STATIC_INIT;
398 static void ossl_init_engine_rdrand(void)
400 # ifdef OPENSSL_INIT_DEBUG
401 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_rdrand: "
402 "engine_load_rdrand_internal()\n");
404 engine_load_rdrand_internal();
408 static OPENSSL_INIT_ONCE engine_dynamic = OPENSSL_INIT_ONCE_STATIC_INIT;
409 static void ossl_init_engine_dynamic(void)
411 # ifdef OPENSSL_INIT_DEBUG
412 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dynamic: "
413 "engine_load_dynamic_internal()\n");
415 engine_load_dynamic_internal();
418 # ifndef OPENSSL_NO_STATIC_ENGINE
419 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
420 static OPENSSL_INIT_ONCE engine_padlock = OPENSSL_INIT_ONCE_STATIC_INIT;
421 static void ossl_init_engine_padlock(void)
423 # ifdef OPENSSL_INIT_DEBUG
424 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_padlock: "
425 "engine_load_padlock_internal()\n");
427 engine_load_padlock_internal();
431 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
432 static OPENSSL_INIT_ONCE engine_capi = OPENSSL_INIT_ONCE_STATIC_INIT;
433 static void ossl_init_engine_capi(void)
435 # ifdef OPENSSL_INIT_DEBUG
436 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_capi: "
437 "engine_load_capi_internal()\n");
439 engine_load_capi_internal();
443 static OPENSSL_INIT_ONCE engine_dasync = OPENSSL_INIT_ONCE_STATIC_INIT;
444 static void ossl_init_engine_dasync(void)
446 # ifdef OPENSSL_INIT_DEBUG
447 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dasync: "
448 "engine_load_dasync_internal()\n");
450 engine_load_dasync_internal();
456 static OPENSSL_INIT_ONCE zlib = OPENSSL_INIT_ONCE_STATIC_INIT;
457 static int zlib_inited = 0;
458 static void ossl_init_zlib(void)
460 /* Do nothing - we need to know about this for the later cleanup */
464 static void ossl_init_thread_stop(struct thread_local_inits_st *locals)
466 /* Can't do much about this */
471 #ifdef OPENSSL_INIT_DEBUG
472 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
473 "ASYNC_cleanup_thread()\n");
475 ASYNC_cleanup_thread();
478 if (locals->err_state) {
479 #ifdef OPENSSL_INIT_DEBUG
480 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
481 "ERR_remove_thread_state(NULL)\n");
483 ERR_remove_thread_state(NULL);
486 OPENSSL_free(locals);
487 ossl_init_thread_stop_cleanup();
490 void OPENSSL_INIT_thread_stop(void)
492 ossl_init_thread_stop(
493 (struct thread_local_inits_st *)ossl_init_get_thread_local(0));
496 int ossl_init_thread_start(uint64_t opts)
498 struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);
503 if (opts & OPENSSL_INIT_THREAD_ASYNC) {
504 #ifdef OPENSSL_INIT_DEBUG
505 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
506 "marking thread for async\n");
511 if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
512 #ifdef OPENSSL_INIT_DEBUG
513 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
514 "marking thread for err_state\n");
516 locals->err_state = 1;
522 void OPENSSL_INIT_library_stop(void)
524 OPENSSL_INIT_STOP *currhandler, *lasthandler;
527 * Thread stop may not get automatically called by the thread library for
528 * the very last thread in some situations, so call it directly.
530 ossl_init_thread_stop(ossl_init_get_thread_local(0));
532 currhandler = stop_handlers;
533 while (currhandler != NULL) {
534 currhandler->handler();
535 lasthandler = currhandler;
536 currhandler = currhandler->next;
537 OPENSSL_free(lasthandler);
539 stop_handlers = NULL;
541 * We assume we are single-threaded for this function, i.e. no race
542 * conditions for the various "*_inited" vars below.
546 #ifdef OPENSSL_INIT_DEBUG
547 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
548 "COMP_zlib_cleanup()\n");
552 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&zlib);
555 #ifndef OPENSSL_NO_ENGINE
557 # ifdef OPENSSL_INIT_DEBUG
558 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
559 "ENGINE_cleanup()\n");
563 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_openssl);
564 # if !defined(OPENSSL_NO_HW) && \
565 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
566 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_cryptodev);
568 # ifndef OPENSSL_NO_RDRAND
569 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_rdrand);
571 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_dynamic);
572 # ifndef OPENSSL_NO_STATIC_ENGINE
573 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
574 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_padlock);
576 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
577 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_capi);
579 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_dasync);
585 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&async);
588 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&config);
589 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&add_all_ciphers);
590 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&add_all_digests);
592 if (load_crypto_strings_inited) {
593 #ifdef OPENSSL_INIT_DEBUG
594 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
595 "ERR_free_strings()\n");
598 load_crypto_strings_inited = 0;
599 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&load_crypto_strings);
603 #ifdef OPENSSL_INIT_DEBUG
604 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
605 "CRYPTO_cleanup_all_ex_data()\n");
606 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
608 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
609 "CONF_modules_free()\n");
610 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
613 CRYPTO_cleanup_all_ex_data();
618 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&base);
622 static const OPENSSL_INIT_SETTINGS *ossl_init_get_setting(
623 const OPENSSL_INIT_SETTINGS *settings, int name)
625 if (settings == NULL)
628 while (settings->name != OPENSSL_INIT_SET_END) {
629 if (settings->name == name)
638 * If this function is called with a non NULL settings value then it must be
639 * called prior to any threads making calls to any OpenSSL functions,
640 * i.e. passing a non-null settings value is assumed to be single-threaded.
642 void OPENSSL_INIT_crypto_library_start(uint64_t opts,
643 const OPENSSL_INIT_SETTINGS *settings)
645 ossl_init_once_run(&base, ossl_init_base);
647 if (opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
648 ossl_init_once_run(&load_crypto_strings,
649 ossl_init_no_load_crypto_strings);
651 if (opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
652 ossl_init_once_run(&load_crypto_strings, ossl_init_load_crypto_strings);
654 if (opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
655 ossl_init_once_run(&add_all_ciphers, ossl_init_no_add_algs);
657 if (opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
658 ossl_init_once_run(&add_all_ciphers, ossl_init_add_all_ciphers);
660 if (opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
661 ossl_init_once_run(&add_all_digests, ossl_init_no_add_algs);
663 if (opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
664 ossl_init_once_run(&add_all_digests, ossl_init_add_all_digests);
666 if (opts & OPENSSL_INIT_NO_LOAD_CONFIG) {
667 ossl_init_once_run(&config, ossl_init_no_config);
670 if (opts & OPENSSL_INIT_LOAD_CONFIG) {
671 CRYPTO_w_lock(CRYPTO_LOCK_INIT);
672 if (settings != NULL) {
673 const OPENSSL_INIT_SETTINGS *curr;
674 curr = ossl_init_get_setting(settings,
675 OPENSSL_INIT_SET_CONF_FILENAME);
676 config_filename = (curr == NULL) ? NULL : curr->value.type_string;
678 config_filename = NULL;
680 ossl_init_once_run(&config, ossl_init_config);
681 CRYPTO_w_unlock(CRYPTO_LOCK_INIT);
684 if (opts & OPENSSL_INIT_ASYNC) {
685 ossl_init_once_run(&async, ossl_init_async);
688 #ifndef OPENSSL_NO_ENGINE
689 if (opts & OPENSSL_INIT_ENGINE_OPENSSL) {
690 ossl_init_once_run(&engine_openssl, ossl_init_engine_openssl);
692 # if !defined(OPENSSL_NO_HW) && \
693 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
694 if (opts & OPENSSL_INIT_ENGINE_CRYPTODEV) {
695 ossl_init_once_run(&engine_cryptodev, ossl_init_engine_cryptodev);
698 # ifndef OPENSSL_NO_RDRAND
699 if (opts & OPENSSL_INIT_ENGINE_RDRAND) {
700 ossl_init_once_run(&engine_rdrand, ossl_init_engine_rdrand);
703 if (opts & OPENSSL_INIT_ENGINE_DYNAMIC) {
704 ossl_init_once_run(&engine_dynamic, ossl_init_engine_dynamic);
706 # ifndef OPENSSL_NO_STATIC_ENGINE
707 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
708 if (opts & OPENSSL_INIT_ENGINE_PADLOCK) {
709 ossl_init_once_run(&engine_padlock, ossl_init_engine_padlock);
712 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
713 if (opts & OPENSSL_INIT_ENGINE_CAPI) {
714 ossl_init_once_run(&engine_capi, ossl_init_engine_capi);
717 if (opts & OPENSSL_INIT_ENGINE_DASYNC) {
718 ossl_init_once_run(&engine_dasync, ossl_init_engine_dasync);
721 if (opts & (OPENSSL_INIT_ENGINE_ALL_BUILTIN
722 | OPENSSL_INIT_ENGINE_DASYNC | OPENSSL_INIT_ENGINE_OPENSSL)) {
723 ENGINE_register_all_complete();
727 if (opts & OPENSSL_INIT_ZLIB) {
728 ossl_init_once_run(&zlib, ossl_init_zlib);
732 int OPENSSL_INIT_register_stop_handler(void (*handler)(void))
734 OPENSSL_INIT_STOP *newhand;
736 newhand = OPENSSL_malloc(sizeof(*newhand));
740 newhand->handler = handler;
741 newhand->next = stop_handlers;
742 stop_handlers = newhand;