2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib_int.h"
12 #include <openssl/err.h>
13 #include "internal/rand_int.h"
14 #include "internal/bio.h"
15 #include <openssl/evp.h>
16 #include "internal/evp_int.h"
17 #include "internal/conf.h"
18 #include "internal/async.h"
19 #include "internal/engine.h"
20 #include "internal/comp.h"
21 #include "internal/err.h"
22 #include "internal/err_int.h"
23 #include "internal/objects.h"
26 #include "internal/thread_once.h"
27 #include "internal/dso_conf.h"
28 #include "internal/dso.h"
29 #include "internal/store.h"
31 static int stopped = 0;
34 * Since per-thread-specific-data destructors are not universally
35 * available, i.e. not on Windows, only below CRYPTO_THREAD_LOCAL key
36 * is assumed to have destructor associated. And then an effort is made
37 * to call this single destructor on non-pthread platform[s].
39 * Initial value is "impossible". It is used as guard value to shortcut
40 * destructor for threads terminating before libcrypto is initialized or
41 * after it's de-initialized. Access to the key doesn't have to be
42 * serialized for the said threads, because they didn't use libcrypto
43 * and it doesn't matter if they pick "impossible" or derefernce real
44 * key value and pull NULL past initialization in the first thread that
45 * intends to use libcrypto.
47 static CRYPTO_THREAD_LOCAL destructor_key = (CRYPTO_THREAD_LOCAL)-1;
49 static void ossl_init_thread_stop(struct thread_local_inits_st *locals);
51 static void ossl_init_thread_destructor(void *local)
53 ossl_init_thread_stop((struct thread_local_inits_st *)local);
56 static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)
58 struct thread_local_inits_st *local =
59 CRYPTO_THREAD_get_local(&destructor_key);
63 && (local = OPENSSL_zalloc(sizeof(*local))) != NULL
64 && !CRYPTO_THREAD_set_local(&destructor_key, local)) {
69 CRYPTO_THREAD_set_local(&destructor_key, NULL);
75 typedef struct ossl_init_stop_st OPENSSL_INIT_STOP;
76 struct ossl_init_stop_st {
77 void (*handler)(void);
78 OPENSSL_INIT_STOP *next;
81 static OPENSSL_INIT_STOP *stop_handlers = NULL;
82 static CRYPTO_RWLOCK *init_lock = NULL;
84 static CRYPTO_ONCE base = CRYPTO_ONCE_STATIC_INIT;
85 static int base_inited = 0;
86 DEFINE_RUN_ONCE_STATIC(ossl_init_base)
88 CRYPTO_THREAD_LOCAL key;
90 #ifdef OPENSSL_INIT_DEBUG
91 fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
93 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
94 ossl_malloc_setup_failures();
96 if (!CRYPTO_THREAD_init_local(&key, ossl_init_thread_destructor))
98 if ((init_lock = CRYPTO_THREAD_lock_new()) == NULL)
100 #ifndef OPENSSL_SYS_UEFI
101 if (atexit(OPENSSL_cleanup) != 0)
104 OPENSSL_cpuid_setup();
106 destructor_key = key;
111 #ifdef OPENSSL_INIT_DEBUG
112 fprintf(stderr, "OPENSSL_INIT: ossl_init_base not ok!\n");
114 CRYPTO_THREAD_lock_free(init_lock);
117 CRYPTO_THREAD_cleanup_local(&key);
121 static CRYPTO_ONCE load_crypto_nodelete = CRYPTO_ONCE_STATIC_INIT;
122 DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_nodelete)
124 #ifdef OPENSSL_INIT_DEBUG
125 fprintf(stderr, "OPENSSL_INIT: ossl_init_load_crypto_nodelete()\n");
127 #if !defined(OPENSSL_NO_DSO) && !defined(OPENSSL_USE_NODELETE)
130 HMODULE handle = NULL;
133 /* We don't use the DSO route for WIN32 because there is a better way */
134 ret = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
135 | GET_MODULE_HANDLE_EX_FLAG_PIN,
136 (void *)&base_inited, &handle);
138 # ifdef OPENSSL_INIT_DEBUG
139 fprintf(stderr, "OPENSSL_INIT: obtained DSO reference? %s\n",
140 (ret == TRUE ? "No!" : "Yes."));
142 return (ret == TRUE) ? 1 : 0;
146 * Deliberately leak a reference to ourselves. This will force the library
147 * to remain loaded until the atexit() handler is run at process exit.
153 if (!err_shelve_state(&err))
156 dso = DSO_dsobyaddr(&base_inited, DSO_FLAG_NO_UNLOAD_ON_FREE);
157 # ifdef OPENSSL_INIT_DEBUG
158 fprintf(stderr, "OPENSSL_INIT: obtained DSO reference? %s\n",
159 (dso == NULL ? "No!" : "Yes."));
161 * In case of No!, it is uncertain our exit()-handlers can still be
162 * called. After dlclose() the whole library might have been unloaded
167 err_unshelve_state(err);
175 static CRYPTO_ONCE load_crypto_strings = CRYPTO_ONCE_STATIC_INIT;
176 static int load_crypto_strings_inited = 0;
177 DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_crypto_strings)
179 /* Do nothing in this case */
183 DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
187 * OPENSSL_NO_AUTOERRINIT is provided here to prevent at compile time
188 * pulling in all the error strings during static linking
190 #if !defined(OPENSSL_NO_ERR) && !defined(OPENSSL_NO_AUTOERRINIT)
191 # ifdef OPENSSL_INIT_DEBUG
192 fprintf(stderr, "OPENSSL_INIT: ossl_init_load_crypto_strings: "
193 "err_load_crypto_strings_int()\n");
195 ret = err_load_crypto_strings_int();
196 load_crypto_strings_inited = 1;
201 static CRYPTO_ONCE add_all_ciphers = CRYPTO_ONCE_STATIC_INIT;
202 DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_ciphers)
205 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
206 * pulling in all the ciphers during static linking
208 #ifndef OPENSSL_NO_AUTOALGINIT
209 # ifdef OPENSSL_INIT_DEBUG
210 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_ciphers: "
211 "openssl_add_all_ciphers_int()\n");
213 openssl_add_all_ciphers_int();
218 static CRYPTO_ONCE add_all_digests = CRYPTO_ONCE_STATIC_INIT;
219 DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests)
222 * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time
223 * pulling in all the ciphers during static linking
225 #ifndef OPENSSL_NO_AUTOALGINIT
226 # ifdef OPENSSL_INIT_DEBUG
227 fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_digests: "
228 "openssl_add_all_digests()\n");
230 openssl_add_all_digests_int();
235 DEFINE_RUN_ONCE_STATIC(ossl_init_no_add_algs)
241 static CRYPTO_ONCE config = CRYPTO_ONCE_STATIC_INIT;
242 static int config_inited = 0;
243 static const char *appname;
244 DEFINE_RUN_ONCE_STATIC(ossl_init_config)
246 #ifdef OPENSSL_INIT_DEBUG
248 "OPENSSL_INIT: ossl_init_config: openssl_config(%s)\n",
249 appname == NULL ? "NULL" : appname);
251 openssl_config_int(appname);
255 DEFINE_RUN_ONCE_STATIC(ossl_init_no_config)
257 #ifdef OPENSSL_INIT_DEBUG
259 "OPENSSL_INIT: ossl_init_config: openssl_no_config_int()\n");
261 openssl_no_config_int();
266 static CRYPTO_ONCE async = CRYPTO_ONCE_STATIC_INIT;
267 static int async_inited = 0;
268 DEFINE_RUN_ONCE_STATIC(ossl_init_async)
270 #ifdef OPENSSL_INIT_DEBUG
271 fprintf(stderr, "OPENSSL_INIT: ossl_init_async: async_init()\n");
279 #ifndef OPENSSL_NO_ENGINE
280 static CRYPTO_ONCE engine_openssl = CRYPTO_ONCE_STATIC_INIT;
281 DEFINE_RUN_ONCE_STATIC(ossl_init_engine_openssl)
283 # ifdef OPENSSL_INIT_DEBUG
284 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_openssl: "
285 "engine_load_openssl_int()\n");
287 engine_load_openssl_int();
290 # ifndef OPENSSL_NO_DEVCRYPTOENG
291 static CRYPTO_ONCE engine_devcrypto = CRYPTO_ONCE_STATIC_INIT;
292 DEFINE_RUN_ONCE_STATIC(ossl_init_engine_devcrypto)
294 # ifdef OPENSSL_INIT_DEBUG
295 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_devcrypto: "
296 "engine_load_devcrypto_int()\n");
298 engine_load_devcrypto_int();
303 # ifndef OPENSSL_NO_RDRAND
304 static CRYPTO_ONCE engine_rdrand = CRYPTO_ONCE_STATIC_INIT;
305 DEFINE_RUN_ONCE_STATIC(ossl_init_engine_rdrand)
307 # ifdef OPENSSL_INIT_DEBUG
308 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_rdrand: "
309 "engine_load_rdrand_int()\n");
311 engine_load_rdrand_int();
315 static CRYPTO_ONCE engine_dynamic = CRYPTO_ONCE_STATIC_INIT;
316 DEFINE_RUN_ONCE_STATIC(ossl_init_engine_dynamic)
318 # ifdef OPENSSL_INIT_DEBUG
319 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dynamic: "
320 "engine_load_dynamic_int()\n");
322 engine_load_dynamic_int();
325 # ifndef OPENSSL_NO_STATIC_ENGINE
326 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
327 static CRYPTO_ONCE engine_padlock = CRYPTO_ONCE_STATIC_INIT;
328 DEFINE_RUN_ONCE_STATIC(ossl_init_engine_padlock)
330 # ifdef OPENSSL_INIT_DEBUG
331 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_padlock: "
332 "engine_load_padlock_int()\n");
334 engine_load_padlock_int();
338 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
339 static CRYPTO_ONCE engine_capi = CRYPTO_ONCE_STATIC_INIT;
340 DEFINE_RUN_ONCE_STATIC(ossl_init_engine_capi)
342 # ifdef OPENSSL_INIT_DEBUG
343 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_capi: "
344 "engine_load_capi_int()\n");
346 engine_load_capi_int();
350 # if !defined(OPENSSL_NO_AFALGENG)
351 static CRYPTO_ONCE engine_afalg = CRYPTO_ONCE_STATIC_INIT;
352 DEFINE_RUN_ONCE_STATIC(ossl_init_engine_afalg)
354 # ifdef OPENSSL_INIT_DEBUG
355 fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_afalg: "
356 "engine_load_afalg_int()\n");
358 engine_load_afalg_int();
365 #ifndef OPENSSL_NO_COMP
366 static CRYPTO_ONCE zlib = CRYPTO_ONCE_STATIC_INIT;
368 static int zlib_inited = 0;
369 DEFINE_RUN_ONCE_STATIC(ossl_init_zlib)
371 /* Do nothing - we need to know about this for the later cleanup */
377 static void ossl_init_thread_stop(struct thread_local_inits_st *locals)
379 /* Can't do much about this */
384 #ifdef OPENSSL_INIT_DEBUG
385 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
386 "async_delete_thread_state()\n");
388 async_delete_thread_state();
391 if (locals->err_state) {
392 #ifdef OPENSSL_INIT_DEBUG
393 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
394 "err_delete_thread_state()\n");
396 err_delete_thread_state();
400 #ifdef OPENSSL_INIT_DEBUG
401 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_stop: "
402 "drbg_delete_thread_state()\n");
404 drbg_delete_thread_state();
407 OPENSSL_free(locals);
410 void OPENSSL_thread_stop(void)
412 if (destructor_key != (CRYPTO_THREAD_LOCAL)-1)
413 ossl_init_thread_stop(ossl_init_get_thread_local(0));
416 int ossl_init_thread_start(uint64_t opts)
418 struct thread_local_inits_st *locals;
420 if (!OPENSSL_init_crypto(0, NULL))
423 locals = ossl_init_get_thread_local(1);
428 if (opts & OPENSSL_INIT_THREAD_ASYNC) {
429 #ifdef OPENSSL_INIT_DEBUG
430 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
431 "marking thread for async\n");
436 if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
437 #ifdef OPENSSL_INIT_DEBUG
438 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
439 "marking thread for err_state\n");
441 locals->err_state = 1;
444 if (opts & OPENSSL_INIT_THREAD_RAND) {
445 #ifdef OPENSSL_INIT_DEBUG
446 fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
447 "marking thread for rand\n");
455 void OPENSSL_cleanup(void)
457 OPENSSL_INIT_STOP *currhandler, *lasthandler;
458 CRYPTO_THREAD_LOCAL key;
460 /* If we've not been inited then no need to deinit */
464 /* Might be explicitly called and also by atexit */
470 * Thread stop may not get automatically called by the thread library for
471 * the very last thread in some situations, so call it directly.
473 ossl_init_thread_stop(ossl_init_get_thread_local(0));
475 currhandler = stop_handlers;
476 while (currhandler != NULL) {
477 currhandler->handler();
478 lasthandler = currhandler;
479 currhandler = currhandler->next;
480 OPENSSL_free(lasthandler);
482 stop_handlers = NULL;
484 CRYPTO_THREAD_lock_free(init_lock);
488 * We assume we are single-threaded for this function, i.e. no race
489 * conditions for the various "*_inited" vars below.
492 #ifndef OPENSSL_NO_COMP
494 #ifdef OPENSSL_INIT_DEBUG
495 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
496 "comp_zlib_cleanup_int()\n");
498 comp_zlib_cleanup_int();
503 # ifdef OPENSSL_INIT_DEBUG
504 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
510 if (load_crypto_strings_inited) {
511 #ifdef OPENSSL_INIT_DEBUG
512 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
513 "err_free_strings_int()\n");
515 err_free_strings_int();
518 key = destructor_key;
519 destructor_key = (CRYPTO_THREAD_LOCAL)-1;
520 CRYPTO_THREAD_cleanup_local(&key);
522 #ifdef OPENSSL_INIT_DEBUG
523 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
524 "rand_cleanup_int()\n");
525 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
526 "conf_modules_free_int()\n");
527 #ifndef OPENSSL_NO_ENGINE
528 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
529 "engine_cleanup_int()\n");
531 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
532 "crypto_cleanup_all_ex_data_int()\n");
533 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
534 "bio_sock_cleanup_int()\n");
535 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
537 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
538 "evp_cleanup_int()\n");
539 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
540 "obj_cleanup_int()\n");
541 fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: "
545 * Note that cleanup order is important:
546 * - rand_cleanup_int could call an ENGINE's RAND cleanup function so
547 * must be called before engine_cleanup_int()
548 * - ENGINEs use CRYPTO_EX_DATA and therefore, must be cleaned up
549 * before the ex data handlers are wiped in CRYPTO_cleanup_all_ex_data().
550 * - conf_modules_free_int() can end up in ENGINE code so must be called
551 * before engine_cleanup_int()
552 * - ENGINEs and additional EVP algorithms might use added OIDs names so
553 * obj_cleanup_int() must be called last
556 rand_drbg_cleanup_int();
557 conf_modules_free_int();
558 #ifndef OPENSSL_NO_ENGINE
559 engine_cleanup_int();
561 ossl_store_cleanup_int();
562 crypto_cleanup_all_ex_data_int();
568 CRYPTO_secure_malloc_done();
574 * If this function is called with a non NULL settings value then it must be
575 * called prior to any threads making calls to any OpenSSL functions,
576 * i.e. passing a non-null settings value is assumed to be single-threaded.
578 int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
581 if (!(opts & OPENSSL_INIT_BASE_ONLY))
582 CRYPTOerr(CRYPTO_F_OPENSSL_INIT_CRYPTO, ERR_R_INIT_FAIL);
586 if (!RUN_ONCE(&base, ossl_init_base))
589 if (!(opts & OPENSSL_INIT_BASE_ONLY)
590 && !RUN_ONCE(&load_crypto_nodelete,
591 ossl_init_load_crypto_nodelete))
594 if ((opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
595 && !RUN_ONCE(&load_crypto_strings,
596 ossl_init_no_load_crypto_strings))
599 if ((opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
600 && !RUN_ONCE(&load_crypto_strings, ossl_init_load_crypto_strings))
603 if ((opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
604 && !RUN_ONCE(&add_all_ciphers, ossl_init_no_add_algs))
607 if ((opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
608 && !RUN_ONCE(&add_all_ciphers, ossl_init_add_all_ciphers))
611 if ((opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
612 && !RUN_ONCE(&add_all_digests, ossl_init_no_add_algs))
615 if ((opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
616 && !RUN_ONCE(&add_all_digests, ossl_init_add_all_digests))
619 if ((opts & OPENSSL_INIT_ATFORK)
620 && !openssl_init_fork_handlers())
623 if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG)
624 && !RUN_ONCE(&config, ossl_init_no_config))
627 if (opts & OPENSSL_INIT_LOAD_CONFIG) {
629 CRYPTO_THREAD_write_lock(init_lock);
630 appname = (settings == NULL) ? NULL : settings->appname;
631 ret = RUN_ONCE(&config, ossl_init_config);
632 CRYPTO_THREAD_unlock(init_lock);
637 if ((opts & OPENSSL_INIT_ASYNC)
638 && !RUN_ONCE(&async, ossl_init_async))
641 #ifndef OPENSSL_NO_ENGINE
642 if ((opts & OPENSSL_INIT_ENGINE_OPENSSL)
643 && !RUN_ONCE(&engine_openssl, ossl_init_engine_openssl))
645 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_DEVCRYPTOENG)
646 if ((opts & OPENSSL_INIT_ENGINE_CRYPTODEV)
647 && !RUN_ONCE(&engine_devcrypto, ossl_init_engine_devcrypto))
650 # ifndef OPENSSL_NO_RDRAND
651 if ((opts & OPENSSL_INIT_ENGINE_RDRAND)
652 && !RUN_ONCE(&engine_rdrand, ossl_init_engine_rdrand))
655 if ((opts & OPENSSL_INIT_ENGINE_DYNAMIC)
656 && !RUN_ONCE(&engine_dynamic, ossl_init_engine_dynamic))
658 # ifndef OPENSSL_NO_STATIC_ENGINE
659 # if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
660 if ((opts & OPENSSL_INIT_ENGINE_PADLOCK)
661 && !RUN_ONCE(&engine_padlock, ossl_init_engine_padlock))
664 # if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
665 if ((opts & OPENSSL_INIT_ENGINE_CAPI)
666 && !RUN_ONCE(&engine_capi, ossl_init_engine_capi))
669 # if !defined(OPENSSL_NO_AFALGENG)
670 if ((opts & OPENSSL_INIT_ENGINE_AFALG)
671 && !RUN_ONCE(&engine_afalg, ossl_init_engine_afalg))
675 if (opts & (OPENSSL_INIT_ENGINE_ALL_BUILTIN
676 | OPENSSL_INIT_ENGINE_OPENSSL
677 | OPENSSL_INIT_ENGINE_AFALG)) {
678 ENGINE_register_all_complete();
682 #ifndef OPENSSL_NO_COMP
683 if ((opts & OPENSSL_INIT_ZLIB)
684 && !RUN_ONCE(&zlib, ossl_init_zlib))
691 int OPENSSL_atexit(void (*handler)(void))
693 OPENSSL_INIT_STOP *newhand;
695 #if !defined(OPENSSL_NO_DSO) && !defined(OPENSSL_USE_NODELETE)
702 handlersym.func = handler;
705 HMODULE handle = NULL;
709 * We don't use the DSO route for WIN32 because there is a better
712 ret = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
713 | GET_MODULE_HANDLE_EX_FLAG_PIN,
714 handlersym.sym, &handle);
721 * Deliberately leak a reference to the handler. This will force the
722 * library/code containing the handler to remain loaded until we run the
723 * atexit handler. If -znodelete has been used then this is
730 dso = DSO_dsobyaddr(handlersym.sym, DSO_FLAG_NO_UNLOAD_ON_FREE);
731 # ifdef OPENSSL_INIT_DEBUG
733 "OPENSSL_INIT: OPENSSL_atexit: obtained DSO reference? %s\n",
734 (dso == NULL ? "No!" : "Yes."));
735 /* See same code above in ossl_init_base() for an explanation. */
744 if ((newhand = OPENSSL_malloc(sizeof(*newhand))) == NULL) {
745 CRYPTOerr(CRYPTO_F_OPENSSL_ATEXIT, ERR_R_MALLOC_FAILURE);
749 newhand->handler = handler;
750 newhand->next = stop_handlers;
751 stop_handlers = newhand;
756 #ifdef OPENSSL_SYS_UNIX
758 * The following three functions are for OpenSSL developers. This is
759 * where we set/reset state across fork (called via pthread_atfork when
760 * it exists, or manually by the application when it doesn't).
762 * WARNING! If you put code in either OPENSSL_fork_parent or
763 * OPENSSL_fork_child, you MUST MAKE SURE that they are async-signal-
764 * safe. See this link, for example:
765 * http://man7.org/linux/man-pages/man7/signal-safety.7.html
768 void OPENSSL_fork_prepare(void)
772 void OPENSSL_fork_parent(void)
776 void OPENSSL_fork_child(void)