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>
73 #include <internal/evp_int.h>
74 #include <internal/conf.h>
75 #include <internal/async.h>
76 #include <internal/engine.h>
78 #include <openssl/conf.h>
79 #include <openssl/async.h>
80 #include <openssl/engine.h>
81 #include <openssl/comp.h>
83 #include <internal/err.h>
87 /* Implement "once" functionality */
88 #if !defined(OPENSSL_THREADS)
89 typedef int OPENSSL_INIT_ONCE;
90 # define OPENSSL_INIT_ONCE_STATIC_INIT 0
91 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = 0)
93 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
95 if (*once == OPENSSL_INIT_ONCE_STATIC_INIT) {
101 static int ossl_init_setup_thread_stop(void)
104 * There are no threads to stop. Do nothing.
109 static void ossl_init_thread_stop_cleanup(void)
113 static struct thread_local_inits_st *local = NULL;
114 void *ossl_init_get_thread_local(int alloc)
116 if (local == NULL && alloc)
117 local = OPENSSL_zalloc(sizeof(*local));
121 #elif defined(OPENSSL_SYS_WINDOWS)
123 # include <windows.h>
125 # if _WIN32_WINNT < 0x0600
128 * Versions before 0x0600 (Windows Vista, Windows Server 2008 or later) do not
129 * have InitOnceExecuteOnce, so we fall back to using a spinlock instead.
131 typedef LONG OPENSSL_INIT_ONCE;
132 # define OPENSSL_INIT_ONCE_STATIC_INIT 0
133 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = 0)
135 # define ONCE_UNINITED 0
136 # define ONCE_ININIT 1
139 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
141 LONG volatile *lock = (LONG *)once;
144 if (*lock == ONCE_DONE)
148 result = InterlockedCompareExchange(lock, ONCE_ININIT, ONCE_UNINITED);
149 if (result == ONCE_UNINITED) {
154 } while (result == ONCE_ININIT);
159 typedef INIT_ONCE OPENSSL_INIT_ONCE;
160 # define OPENSSL_INIT_ONCE_STATIC_INIT INIT_ONCE_STATIC_INIT
161 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) \
162 InitOnceInitialize((PINIT_ONCE)(once))
164 static BOOL CALLBACK once_cb(PINIT_ONCE once, PVOID initfp, PVOID *unused)
166 void (*init)(void) = initfp;
173 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
175 InitOnceExecuteOnce((INIT_ONCE *)once, once_cb, init, NULL);
179 DWORD threadstopkey = TLS_OUT_OF_INDEXES;
181 static int ossl_init_setup_thread_stop(void)
184 * We use a dummy thread local key here. We use the destructor to detect
185 * when the thread is going to stop
187 threadstopkey = TlsAlloc();
188 if (threadstopkey == TLS_OUT_OF_INDEXES)
194 static void ossl_init_thread_stop_cleanup(void)
196 if (threadstopkey != TLS_OUT_OF_INDEXES) {
197 TlsFree(threadstopkey);
201 void *ossl_init_get_thread_local(int alloc)
203 struct thread_local_inits_st *local = TlsGetValue(threadstopkey);
205 if (local == NULL && alloc) {
206 local = OPENSSL_zalloc(sizeof *local);
207 TlsSetValue(threadstopkey, local);
214 # include <pthread.h>
216 pthread_key_t threadstopkey;
218 typedef pthread_once_t OPENSSL_INIT_ONCE;
219 # define OPENSSL_INIT_ONCE_STATIC_INIT PTHREAD_ONCE_INIT
220 # define OPENSSL_INIT_ONCE_DYNAMIC_INIT(once) (*(once) = PTHREAD_ONCE_INIT)
222 static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
224 pthread_once(once, init);
227 static void ossl_init_thread_stop_wrap(void *local)
229 ossl_init_thread_stop((struct thread_local_inits_st *)local);
232 static int ossl_init_setup_thread_stop(void)
235 * We use a dummy thread local key here. We use the destructor to detect
236 * when the thread is going to stop
238 return (pthread_key_create(&threadstopkey,
239 ossl_init_thread_stop_wrap) == 0);
242 static void ossl_init_thread_stop_cleanup(void)
246 void *ossl_init_get_thread_local(int alloc)
248 struct thread_local_inits_st *local = pthread_getspecific(threadstopkey);
250 if (local == NULL && alloc) {
251 local = OPENSSL_zalloc(sizeof *local);
252 pthread_setspecific(threadstopkey, local);
260 struct ossl_init_stop_st {
261 void (*handler)(void);
262 OPENSSL_INIT_STOP *next;
265 static OPENSSL_INIT_STOP *stop_handlers = NULL;
267 static OPENSSL_INIT_ONCE base = OPENSSL_INIT_ONCE_STATIC_INIT;
268 static int base_inited = 0;
269 static void ossl_init_base(void)
271 #ifdef OPENSSL_INIT_DEBUG
272 fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
274 ossl_init_setup_thread_stop();
275 atexit(OPENSSL_INIT_library_stop);
276 OPENSSL_cpuid_setup();
280 static OPENSSL_INIT_ONCE load_crypto_strings = OPENSSL_INIT_ONCE_STATIC_INIT;
281 static int load_crypto_strings_inited = 0;
282 static void ossl_init_no_load_crypto_strings(void)
284 /* Do nothing in this case */
288 static void ossl_init_load_crypto_strings(void)
290 #ifndef OPENSSL_NO_ERR
291 # ifdef OPENSSL_INIT_DEBUG
292 fprintf(stderr, "OPENSSL_INIT: ossl_init_load_crypto_strings: "
293 "err_load_crypto_strings_intern()\n");
296 err_load_crypto_strings_intern();
299 load_crypto_strings_inited = 1;
302 static OPENSSL_INIT_ONCE add_all_ciphers = OPENSSL_INIT_ONCE_STATIC_INIT;
303 static void ossl_init_add_all_ciphers(void)
306 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
307 * pulling in all the ciphers during static linking
309 #ifndef OPENSSL_NO_AUTOALGINIT
310 # ifdef OPENSSL_INIT_DEBUG
311 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_ciphers: "
312 "openssl_add_all_ciphers_internal()\n");
315 openssl_add_all_ciphers_internal();
317 # ifndef OPENSSL_NO_ENGINE
318 # if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
319 ENGINE_setup_bsd_cryptodev();
325 static OPENSSL_INIT_ONCE add_all_digests = OPENSSL_INIT_ONCE_STATIC_INIT;
326 static void ossl_init_add_all_digests(void)
329 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
330 * pulling in all the ciphers during static linking
332 #ifndef OPENSSL_NO_AUTOALGINIT
333 # ifdef OPENSSL_INIT_DEBUG
334 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_digests: "
335 "openssl_add_all_digests_internal()\n");
338 openssl_add_all_digests_internal();
340 # ifndef OPENSSL_NO_ENGINE
341 # if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
342 ENGINE_setup_bsd_cryptodev();
348 static void ossl_init_no_add_algs(void)
354 static OPENSSL_INIT_ONCE config = OPENSSL_INIT_ONCE_STATIC_INIT;
355 static int config_inited = 0;
356 static const char *config_filename;
357 static void ossl_init_config(void)
359 #ifdef OPENSSL_INIT_DEBUG
361 "OPENSSL_INIT: ossl_init_config: openssl_config_internal(%s)\n",
362 config_filename==NULL?"NULL":config_filename);
365 openssl_config_internal(config_filename);
369 static void ossl_init_no_config(void)
371 #ifdef OPENSSL_INIT_DEBUG
373 "OPENSSL_INIT: ossl_init_config: openssl_no_config_internal()\n");
376 openssl_no_config_internal();
381 static OPENSSL_INIT_ONCE async = OPENSSL_INIT_ONCE_STATIC_INIT;
382 static int async_inited = 0;
383 static void ossl_init_async(void)
385 #ifdef OPENSSL_INIT_DEBUG
386 fprintf(stderr, "OPENSSL_INIT: ossl_init_async: async_init()\n");
394 #ifndef OPENSSL_NO_ENGINE
395 static int engine_inited = 0;
396 static OPENSSL_INIT_ONCE engine_openssl = OPENSSL_INIT_ONCE_STATIC_INIT;
397 static void ossl_init_engine_openssl(void)
399 # ifdef OPENSSL_INIT_DEBUG
400 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_openssl: "
401 "engine_load_openssl_internal()\n");
404 engine_load_openssl_internal();
408 # if !defined(OPENSSL_NO_HW) && \
409 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
410 static OPENSSL_INIT_ONCE engine_cryptodev = OPENSSL_INIT_ONCE_STATIC_INIT;
411 static void ossl_init_engine_cryptodev(void)
413 # ifdef OPENSSL_INIT_DEBUG
414 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_cryptodev: "
415 "engine_load_cryptodev_internal()\n");
418 engine_load_cryptodev_internal();
424 # ifndef OPENSSL_NO_RDRAND
425 static OPENSSL_INIT_ONCE engine_rdrand = OPENSSL_INIT_ONCE_STATIC_INIT;
426 static void ossl_init_engine_rdrand(void)
428 # ifdef OPENSSL_INIT_DEBUG
429 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_rdrand: "
430 "engine_load_rdrand_internal()\n");
433 engine_load_rdrand_internal();
438 static OPENSSL_INIT_ONCE engine_dynamic = OPENSSL_INIT_ONCE_STATIC_INIT;
439 static void ossl_init_engine_dynamic(void)
441 # ifdef OPENSSL_INIT_DEBUG
442 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dynamic: "
443 "engine_load_dynamic_internal()\n");
446 engine_load_dynamic_internal();
450 # ifndef OPENSSL_NO_STATIC_ENGINE
451 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
452 static OPENSSL_INIT_ONCE engine_padlock = OPENSSL_INIT_ONCE_STATIC_INIT;
453 static void ossl_init_engine_padlock(void)
455 # ifdef OPENSSL_INIT_DEBUG
456 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_padlock: "
457 "engine_load_padlock_internal()\n");
460 engine_load_padlock_internal();
465 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
466 static OPENSSL_INIT_ONCE engine_capi = OPENSSL_INIT_ONCE_STATIC_INIT;
467 static void ossl_init_engine_capi(void)
469 # ifdef OPENSSL_INIT_DEBUG
470 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_capi: "
471 "engine_load_capi_internal()\n");
474 engine_load_capi_internal();
479 static OPENSSL_INIT_ONCE engine_dasync = OPENSSL_INIT_ONCE_STATIC_INIT;
480 static void ossl_init_engine_dasync(void)
482 # ifdef OPENSSL_INIT_DEBUG
483 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dasync: "
484 "engine_load_dasync_internal()\n");
487 engine_load_dasync_internal();
494 static OPENSSL_INIT_ONCE zlib = OPENSSL_INIT_ONCE_STATIC_INIT;
495 static int zlib_inited = 0;
496 static void ossl_init_zlib(void)
498 /* Do nothing - we need to know about this for the later cleanup */
502 void ossl_init_thread_stop(struct thread_local_inits_st *locals)
504 /* Can't do much about this */
509 #ifdef OPENSSL_INIT_DEBUG
510 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
511 "ASYNC_cleanup_thread()\n");
513 ASYNC_cleanup_thread();
516 if (locals->err_state) {
517 #ifdef OPENSSL_INIT_DEBUG
518 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
519 "ERR_remove_thread_state(NULL)\n");
521 ERR_remove_thread_state(NULL);
524 OPENSSL_free(locals);
525 ossl_init_thread_stop_cleanup();
528 int ossl_init_thread_start(uint64_t opts)
530 struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);
535 if (opts & OPENSSL_INIT_THREAD_ASYNC) {
536 #ifdef OPENSSL_INIT_DEBUG
537 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
538 "marking thread for async\n");
543 if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
544 #ifdef OPENSSL_INIT_DEBUG
545 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
546 "marking thread for err_state\n");
548 locals->err_state = 1;
554 void OPENSSL_INIT_library_stop(void)
556 OPENSSL_INIT_STOP *currhandler, *lasthandler;
559 * Thread stop may not get automatically called by the thread library for
560 * the very last thread in some situations, so call it directly.
562 ossl_init_thread_stop(ossl_init_get_thread_local(0));
564 currhandler = stop_handlers;
565 while (currhandler != NULL) {
566 currhandler->handler();
567 lasthandler = currhandler;
568 currhandler = currhandler->next;
569 OPENSSL_free(lasthandler);
571 stop_handlers = NULL;
573 * We assume we are single-threaded for this function, i.e. no race
574 * conditions for the various "*_inited" vars below.
578 #ifdef OPENSSL_INIT_DEBUG
579 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
580 "COMP_zlib_cleanup()\n");
584 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&zlib);
587 #ifndef OPENSSL_NO_ENGINE
589 # ifdef OPENSSL_INIT_DEBUG
590 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
591 "ENGINE_cleanup()\n");
595 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_openssl);
596 # if !defined(OPENSSL_NO_HW) && \
597 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
598 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_cryptodev);
600 # ifndef OPENSSL_NO_RDRAND
601 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_rdrand);
603 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_dynamic);
604 # ifndef OPENSSL_NO_STATIC_ENGINE
605 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
606 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_padlock);
608 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
609 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_capi);
611 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&engine_dasync);
617 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&async);
620 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&config);
621 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&add_all_ciphers);
622 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&add_all_digests);
624 if (load_crypto_strings_inited) {
625 #ifdef OPENSSL_INIT_DEBUG
626 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
627 "ERR_free_strings()\n");
630 load_crypto_strings_inited = 0;
631 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&load_crypto_strings);
635 #ifdef OPENSSL_INIT_DEBUG
636 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
637 "CRYPTO_cleanup_all_ex_data()\n");
638 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
640 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
641 "CONF_modules_free()\n");
642 fprintf(stderr, "OPENSSL_INIT: OPENSSL_INIT_library_stop: "
645 CRYPTO_cleanup_all_ex_data();
650 OPENSSL_INIT_ONCE_DYNAMIC_INIT(&base);
654 static const OPENSSL_INIT_SETTINGS *ossl_init_get_setting(
655 const OPENSSL_INIT_SETTINGS *settings, int name)
657 if (settings == NULL)
660 while (settings->name != OPENSSL_INIT_SET_END) {
661 if (settings->name == name)
670 * If this function is called with a non NULL settings value then it must be
671 * called prior to any threads making calls to any OpenSSL functions,
672 * i.e. passing a non-null settings value is assumed to be single-threaded.
674 void OPENSSL_INIT_crypto_library_start(uint64_t opts,
675 const OPENSSL_INIT_SETTINGS *settings)
677 ossl_init_once_run(&base, ossl_init_base);
679 if (opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
680 ossl_init_once_run(&load_crypto_strings,
681 ossl_init_no_load_crypto_strings);
683 if (opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
684 ossl_init_once_run(&load_crypto_strings, ossl_init_load_crypto_strings);
686 if (opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
687 ossl_init_once_run(&add_all_ciphers, ossl_init_no_add_algs);
689 if (opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
690 ossl_init_once_run(&add_all_ciphers, ossl_init_add_all_ciphers);
692 if (opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
693 ossl_init_once_run(&add_all_digests, ossl_init_no_add_algs);
695 if (opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
696 ossl_init_once_run(&add_all_digests, ossl_init_add_all_digests);
698 if (opts & OPENSSL_INIT_NO_LOAD_CONFIG) {
699 ossl_init_once_run(&config, ossl_init_no_config);
702 if (opts & OPENSSL_INIT_LOAD_CONFIG) {
703 if (settings != NULL) {
704 const OPENSSL_INIT_SETTINGS *curr;
705 curr = ossl_init_get_setting(settings,
706 OPENSSL_INIT_SET_CONF_FILENAME);
707 config_filename = curr == NULL ? NULL : curr->value.type_string;
709 ossl_init_once_run(&config, ossl_init_config);
712 if (opts & OPENSSL_INIT_ASYNC) {
713 ossl_init_once_run(&async, ossl_init_async);
716 #ifndef OPENSSL_NO_ENGINE
717 if (opts & OPENSSL_INIT_ENGINE_OPENSSL) {
718 ossl_init_once_run(&engine_openssl, ossl_init_engine_openssl);
720 # if !defined(OPENSSL_NO_HW) && \
721 (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
722 if (opts & OPENSSL_INIT_ENGINE_CRYPTODEV) {
723 ossl_init_once_run(&engine_cryptodev, ossl_init_engine_cryptodev);
726 # ifndef OPENSSL_NO_RDRAND
727 if (opts & OPENSSL_INIT_ENGINE_RDRAND) {
728 ossl_init_once_run(&engine_rdrand, ossl_init_engine_rdrand);
731 if (opts & OPENSSL_INIT_ENGINE_DYNAMIC) {
732 ossl_init_once_run(&engine_dynamic, ossl_init_engine_dynamic);
734 # ifndef OPENSSL_NO_STATIC_ENGINE
735 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
736 if (opts & OPENSSL_INIT_ENGINE_PADLOCK) {
737 ossl_init_once_run(&engine_padlock, ossl_init_engine_padlock);
740 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
741 if (opts & OPENSSL_INIT_ENGINE_CAPI) {
742 ossl_init_once_run(&engine_capi, ossl_init_engine_capi);
745 if (opts & OPENSSL_INIT_ENGINE_DASYNC) {
746 ossl_init_once_run(&engine_dasync, ossl_init_engine_dasync);
749 if (opts & (OPENSSL_INIT_ENGINE_ALL_BUILTIN
750 | OPENSSL_INIT_ENGINE_DASYNC | OPENSSL_INIT_ENGINE_OPENSSL)) {
751 ENGINE_register_all_complete();
755 if (opts & OPENSSL_INIT_ZLIB) {
756 ossl_init_once_run(&zlib, ossl_init_zlib);
760 int OPENSSL_INIT_register_stop_handler(void (*handler)(void))
762 OPENSSL_INIT_STOP *newhand;
764 newhand = OPENSSL_malloc(sizeof(*newhand));
768 newhand->handler = handler;
769 newhand->next = stop_handlers;
770 stop_handlers = newhand;