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