X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Finit.c;h=a939cb16d462c7d59b8de02f5766deb77e73b20f;hb=3a3f9ed140b0e1feeed1b9655091c270df05332f;hp=332567eae74d44c13b4d2aecfe47a7b90e66865d;hpb=69588edbaa424beb71c6a9b1be416588232cb78c;p=oweals%2Fopenssl.git diff --git a/crypto/init.c b/crypto/init.c index 332567eae7..a939cb16d4 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -23,6 +23,7 @@ #include #include #include +#include static int stopped = 0; @@ -79,6 +80,34 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base) return 0; OPENSSL_cpuid_setup(); base_inited = 1; + +#ifndef OPENSSL_USE_NODELETE +# ifdef DSO_WIN32 + { + HMODULE handle = NULL; + BOOL ret; + + /* We don't use the DSO route for WIN32 because there is a better way */ + ret = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS + | GET_MODULE_HANDLE_EX_FLAG_PIN, + (void *)&base_inited, &handle); + + return (ret == TRUE) ? 1 : 0; + } +# else + /* + * Deliberately leak a reference to ourselves. This will force the library + * to remain loaded until the atexit() handler is run a process exit. + */ + { + DSO *dso = NULL; + + dso = DSO_dsobyaddr(&base_inited, DSO_FLAG_NO_UNLOAD_ON_FREE); + DSO_free(dso); + } +# endif +#endif + return 1; } @@ -103,8 +132,8 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings) "err_load_crypto_strings_int()\n"); # endif ret = err_load_crypto_strings_int(); -#endif load_crypto_strings_inited = 1; +#endif return ret; } @@ -258,16 +287,6 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_engine_capi) return 1; } # endif -static CRYPTO_ONCE engine_dasync = CRYPTO_ONCE_STATIC_INIT; -DEFINE_RUN_ONCE_STATIC(ossl_init_engine_dasync) -{ -# ifdef OPENSSL_INIT_DEBUG - fprintf(stderr, "OPENSSL_INIT: ossl_init_engine_dasync: " - "engine_load_dasync_int()\n"); -# endif - engine_load_dasync_int(); - return 1; -} # if !defined(OPENSSL_NO_AFALGENG) static CRYPTO_ONCE engine_afalg = CRYPTO_ONCE_STATIC_INIT; DEFINE_RUN_ONCE_STATIC(ossl_init_engine_afalg) @@ -559,9 +578,6 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) && !RUN_ONCE(&engine_capi, ossl_init_engine_capi)) return 0; # endif - if ((opts & OPENSSL_INIT_ENGINE_DASYNC) - && !RUN_ONCE(&engine_dasync, ossl_init_engine_dasync)) - return 0; # if !defined(OPENSSL_NO_AFALGENG) if ((opts & OPENSSL_INIT_ENGINE_AFALG) && !RUN_ONCE(&engine_afalg, ossl_init_engine_afalg)) @@ -569,7 +585,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) # endif # endif if (opts & (OPENSSL_INIT_ENGINE_ALL_BUILTIN - | OPENSSL_INIT_ENGINE_DASYNC | OPENSSL_INIT_ENGINE_OPENSSL + | OPENSSL_INIT_ENGINE_OPENSSL | OPENSSL_INIT_ENGINE_AFALG)) { ENGINE_register_all_complete(); } @@ -588,6 +604,47 @@ int OPENSSL_atexit(void (*handler)(void)) { OPENSSL_INIT_STOP *newhand; +#ifndef OPENSSL_USE_NODELETE + { + union { + void *sym; + void (*func)(void); + } handlersym; + + handlersym.func = handler; +# ifdef DSO_WIN32 + { + HMODULE handle = NULL; + BOOL ret; + + /* + * We don't use the DSO route for WIN32 because there is a better + * way + */ + ret = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS + | GET_MODULE_HANDLE_EX_FLAG_PIN, + handlersym.sym, &handle); + + if (!ret) + return 0; + } +# else + /* + * Deliberately leak a reference to the handler. This will force the + * library/code containing the handler to remain loaded until we run the + * atexit handler. If -znodelete has been used then this is + * unneccessary. + */ + { + DSO *dso = NULL; + + dso = DSO_dsobyaddr(handlersym.sym, DSO_FLAG_NO_UNLOAD_ON_FREE); + DSO_free(dso); + } +# endif + } +#endif + newhand = OPENSSL_malloc(sizeof(*newhand)); if (newhand == NULL) return 0;