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 static void *wrap_dbg_malloc(size_t s, const char *f, int l);
31 static void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l);
32 static void wrap_dbg_free(void *p);
33 static 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
46 # ifdef WRAP_DBG_MALLOC
47 CRYPTO_set_mem_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free_ex);
49 OPENSSL_malloc_init();
54 # ifdef WRAP_DBG_MALLOC
55 CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
60 #endif /* OpenSSL version cascade */
62 #else /* !OPENSSL || !SYS_WINNT */
63 #define ssl_applink() do {} while (0)
67 #ifdef WRAP_DBG_MALLOC
69 * OpenSSL malloc overriding uses different parameters
70 * for DEBUG malloc/realloc/free (lacking block type).
71 * Simple wrappers convert.
73 static void *wrap_dbg_malloc(size_t s, const char *f, int l)
77 ret = _malloc_dbg(s, _NORMAL_BLOCK, f, l);
81 static void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l)
85 ret = _realloc_dbg(p, s, _NORMAL_BLOCK, f, l);
89 static void wrap_dbg_free(void *p)
91 _free_dbg(p, _NORMAL_BLOCK);
94 static void wrap_dbg_free_ex(void *p, const char *f, int l)
98 _free_dbg(p, _NORMAL_BLOCK);
100 #endif /* WRAP_DBG_MALLOC */