2 * include/ssl_applink.c -- common NTP code for openssl/applink.c
4 * Each program which uses OpenSSL should include this file in _one_
5 * of its source files and call ssl_applink() before any OpenSSL
9 #if defined(OPENSSL) && defined(SYS_WINNT)
11 # pragma warning(push)
12 # pragma warning(disable: 4152)
13 # ifndef OPENSSL_NO_AUTOLINK
14 # include "msvc_ssl_autolib.h"
17 # if OPENSSL_VERSION_NUMBER < 0x10100000L
18 # include <openssl/applink.c>
25 #if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
26 #define WRAP_DBG_MALLOC
29 #ifdef WRAP_DBG_MALLOC
30 void *wrap_dbg_malloc(size_t s, const char *f, int l);
31 void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l);
32 void wrap_dbg_free(void *p);
33 void wrap_dbg_free_ex(void *p, const char *f, int l);
37 #if defined(OPENSSL) && defined(SYS_WINNT)
39 void ssl_applink(void);
44 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
45 # ifdef WRAP_DBG_MALLOC
46 CRYPTO_set_mem_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free_ex);
48 OPENSSL_malloc_init();
51 # ifdef WRAP_DBG_MALLOC
52 CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
56 #endif /* OpenSSL version cascade */
58 #else /* !OPENSSL || !SYS_WINNT */
59 #define ssl_applink() do {} while (0)
63 #ifdef WRAP_DBG_MALLOC
65 * OpenSSL malloc overriding uses different parameters
66 * for DEBUG malloc/realloc/free (lacking block type).
67 * Simple wrappers convert.
69 void *wrap_dbg_malloc(size_t s, const char *f, int l)
73 ret = _malloc_dbg(s, _NORMAL_BLOCK, f, l);
77 void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l)
81 ret = _realloc_dbg(p, s, _NORMAL_BLOCK, f, l);
85 void wrap_dbg_free(void *p)
87 _free_dbg(p, _NORMAL_BLOCK);
90 void wrap_dbg_free_ex(void *p, const char *f, int l)
94 _free_dbg(p, _NORMAL_BLOCK);
96 #endif /* WRAP_DBG_MALLOC */