ssl_applink.c revision 290001
1/*
2 * include/ssl_applink.c -- common NTP code for openssl/applink.c
3 *
4 * Each program which uses OpenSSL should include this file in _one_
5 * of its source files and call ssl_applink() before any OpenSSL
6 * functions.
7 */
8
9#if defined(OPENSSL) && defined(SYS_WINNT)
10# ifdef _MSC_VER
11#  pragma warning(push)
12#  pragma warning(disable: 4152)
13# endif
14# include <openssl/applink.c>
15# ifdef _MSC_VER
16#  pragma warning(pop)
17# endif
18#endif
19
20#if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
21#define WRAP_DBG_MALLOC
22#endif
23
24#ifdef WRAP_DBG_MALLOC
25void *wrap_dbg_malloc(size_t s, const char *f, int l);
26void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l);
27void wrap_dbg_free(void *p);
28#endif
29
30
31#if defined(OPENSSL) && defined(SYS_WINNT)
32void ssl_applink(void);
33
34void
35ssl_applink(void)
36{
37#ifdef WRAP_DBG_MALLOC
38	CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
39#else
40	CRYPTO_malloc_init();
41#endif
42}
43#else	/* !OPENSSL || !SYS_WINNT */
44#define ssl_applink()	do {} while (0)
45#endif
46
47
48#ifdef WRAP_DBG_MALLOC
49/*
50 * OpenSSL malloc overriding uses different parameters
51 * for DEBUG malloc/realloc/free (lacking block type).
52 * Simple wrappers convert.
53 */
54void *wrap_dbg_malloc(size_t s, const char *f, int l)
55{
56	void *ret;
57
58	ret = _malloc_dbg(s, _NORMAL_BLOCK, f, l);
59	return ret;
60}
61
62void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l)
63{
64	void *ret;
65
66	ret = _realloc_dbg(p, s, _NORMAL_BLOCK, f, l);
67	return ret;
68}
69
70void wrap_dbg_free(void *p)
71{
72	_free_dbg(p, _NORMAL_BLOCK);
73}
74#endif	/* WRAP_DBG_MALLOC */
75