12b15cb3dSCy Schubert /* 22b15cb3dSCy Schubert * include/ssl_applink.c -- common NTP code for openssl/applink.c 32b15cb3dSCy Schubert * 42b15cb3dSCy Schubert * Each program which uses OpenSSL should include this file in _one_ 52b15cb3dSCy Schubert * of its source files and call ssl_applink() before any OpenSSL 62b15cb3dSCy Schubert * functions. 72b15cb3dSCy Schubert */ 82b15cb3dSCy Schubert 92b15cb3dSCy Schubert #if defined(OPENSSL) && defined(SYS_WINNT) 102b15cb3dSCy Schubert # ifdef _MSC_VER 112b15cb3dSCy Schubert # pragma warning(push) 122b15cb3dSCy Schubert # pragma warning(disable: 4152) 13*f0574f5cSXin LI # ifndef OPENSSL_NO_AUTOLINK 14*f0574f5cSXin LI # include "msvc_ssl_autolib.h" 152b15cb3dSCy Schubert # endif 16*f0574f5cSXin LI # endif 17*f0574f5cSXin LI # if OPENSSL_VERSION_NUMBER < 0x10100000L 182b15cb3dSCy Schubert # include <openssl/applink.c> 19*f0574f5cSXin LI # endif 202b15cb3dSCy Schubert # ifdef _MSC_VER 212b15cb3dSCy Schubert # pragma warning(pop) 222b15cb3dSCy Schubert # endif 232b15cb3dSCy Schubert #endif 242b15cb3dSCy Schubert 252b15cb3dSCy Schubert #if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG) 262b15cb3dSCy Schubert #define WRAP_DBG_MALLOC 272b15cb3dSCy Schubert #endif 282b15cb3dSCy Schubert 292b15cb3dSCy Schubert #ifdef WRAP_DBG_MALLOC 302b15cb3dSCy Schubert void *wrap_dbg_malloc(size_t s, const char *f, int l); 312b15cb3dSCy Schubert void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l); 322b15cb3dSCy Schubert void wrap_dbg_free(void *p); 33*f0574f5cSXin LI void wrap_dbg_free_ex(void *p, const char *f, int l); 342b15cb3dSCy Schubert #endif 352b15cb3dSCy Schubert 362b15cb3dSCy Schubert 372b15cb3dSCy Schubert #if defined(OPENSSL) && defined(SYS_WINNT) 38*f0574f5cSXin LI 392b15cb3dSCy Schubert void ssl_applink(void); 402b15cb3dSCy Schubert 412b15cb3dSCy Schubert void 422b15cb3dSCy Schubert ssl_applink(void) 432b15cb3dSCy Schubert { 44*f0574f5cSXin LI #if OPENSSL_VERSION_NUMBER >= 0x10100000L 45*f0574f5cSXin LI # ifdef WRAP_DBG_MALLOC 46*f0574f5cSXin LI CRYPTO_set_mem_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free_ex); 47*f0574f5cSXin LI # else 48*f0574f5cSXin LI OPENSSL_malloc_init(); 49*f0574f5cSXin LI # endif 50*f0574f5cSXin LI #else 512b15cb3dSCy Schubert # ifdef WRAP_DBG_MALLOC 522b15cb3dSCy Schubert CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free); 532b15cb3dSCy Schubert # else 542b15cb3dSCy Schubert CRYPTO_malloc_init(); 552b15cb3dSCy Schubert # endif 56*f0574f5cSXin LI #endif /* OpenSSL version cascade */ 572b15cb3dSCy Schubert } 582b15cb3dSCy Schubert #else /* !OPENSSL || !SYS_WINNT */ 592b15cb3dSCy Schubert #define ssl_applink() do {} while (0) 602b15cb3dSCy Schubert #endif 612b15cb3dSCy Schubert 622b15cb3dSCy Schubert 632b15cb3dSCy Schubert #ifdef WRAP_DBG_MALLOC 642b15cb3dSCy Schubert /* 652b15cb3dSCy Schubert * OpenSSL malloc overriding uses different parameters 662b15cb3dSCy Schubert * for DEBUG malloc/realloc/free (lacking block type). 672b15cb3dSCy Schubert * Simple wrappers convert. 682b15cb3dSCy Schubert */ 692b15cb3dSCy Schubert void *wrap_dbg_malloc(size_t s, const char *f, int l) 702b15cb3dSCy Schubert { 712b15cb3dSCy Schubert void *ret; 722b15cb3dSCy Schubert 732b15cb3dSCy Schubert ret = _malloc_dbg(s, _NORMAL_BLOCK, f, l); 742b15cb3dSCy Schubert return ret; 752b15cb3dSCy Schubert } 762b15cb3dSCy Schubert 772b15cb3dSCy Schubert void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l) 782b15cb3dSCy Schubert { 792b15cb3dSCy Schubert void *ret; 802b15cb3dSCy Schubert 812b15cb3dSCy Schubert ret = _realloc_dbg(p, s, _NORMAL_BLOCK, f, l); 822b15cb3dSCy Schubert return ret; 832b15cb3dSCy Schubert } 842b15cb3dSCy Schubert 852b15cb3dSCy Schubert void wrap_dbg_free(void *p) 862b15cb3dSCy Schubert { 872b15cb3dSCy Schubert _free_dbg(p, _NORMAL_BLOCK); 882b15cb3dSCy Schubert } 89*f0574f5cSXin LI 90*f0574f5cSXin LI void wrap_dbg_free_ex(void *p, const char *f, int l) 91*f0574f5cSXin LI { 92*f0574f5cSXin LI (void)f; 93*f0574f5cSXin LI (void)l; 94*f0574f5cSXin LI _free_dbg(p, _NORMAL_BLOCK); 95*f0574f5cSXin LI } 962b15cb3dSCy Schubert #endif /* WRAP_DBG_MALLOC */ 97