提交 f3a2a044 编写于 作者: R Richard Levitte

- Added more documentation in CHANGES.

 - Made CRYPTO_MDEBUG even less used in crypto.h, giving
   MemCheck_start() and MemCheck_stop() only one possible definition.
 - Made the values of the debug function pointers in mem.c dependent
   on the existence of the CRYPTO_MDEBUG macro, and made the rest of
   the code understand the NULL case.

That's it.  With this code, the old behvior of the debug functionality
is restored, but you can still opt to have it on, even when the
library wasn't compiled with a defined CRYPTO_MDEBUG.
上级 d8df48a9
......@@ -13,11 +13,32 @@
memory leaks, but this gives people a chance to debug other memory
problems.
This change means that a call `CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)'
is no longer dependent on if the macro CRYPTO_MDEBUG or friends were
used when the OpenSSL libcrypto was built. This is under debate and
may change back, but with another option to still get debugging even
if the library wasn't compiled that way.
With these changes, a new set of functions and macros have appeared:
CRYPTO_set_mem_debug_functions() [F]
CRYPTO_get_mem_debug_functions() [F]
CRYPTO_dbg_set_options() [F]
CRYPTO_dbg_get_options() [F]
CRYPTO_melloc_debug_init() [M]
The memory debug functions are NULL by default, unless the library
is compiled with CRYPTO_MDEBUG or friends is defined. If someone
wants to debug memory anyway, CRYPTO_malloc_debug_init() or
CRYPTO_set_mem_debug_functions() must be used.
Also, things like CRYPTO_set_mem_functions will always give the
expected result (the new set of functions is used for allocation
and deallocation) at all times, regardless of platform and compiler
options.
To finish it up, some functions that were never use in any other
way than through macros have a new API and new semantic:
CRYPTO_dbg_malloc()
CRYPTO_dbg_realloc()
CRYPTO_dbg_free()
All macros of value have retained their old syntax.
[Richard Levitte]
*) Some S/MIME fixes. The OID for SMIMECapabilities was wrong, the
......
......@@ -217,8 +217,8 @@ typedef struct crypto_ex_data_func_st
(void (*)())CRYPTO_dbg_realloc,\
(void (*)())CRYPTO_dbg_free,\
(void (*)())CRYPTO_dbg_set_options,\
(void (*)())CRYPTO_dbg_get_options);\
} while(0);
(int (*)())CRYPTO_dbg_get_options);\
} while(0)
#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
......@@ -226,13 +226,8 @@ typedef struct crypto_ex_data_func_st
# endif
#endif
#ifdef CRYPTO_MDEBUG
#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
#else
#define MemCheck_start()
#define MemCheck_stop()
#endif
#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
#define is_MemCheck_on() CRYPTO_mem_check_on()
......
......@@ -68,11 +68,19 @@ static char *(*malloc_func)()= (char *(*)())malloc;
static char *(*realloc_func)()= (char *(*)())realloc;
static void (*free_func)()= (void (*)())free;
#ifdef CRYPTO_MDEBUG
static void (*malloc_debug_func)()= (void (*)())CRYPTO_dbg_malloc;
static void (*realloc_debug_func)()= (void (*)())CRYPTO_dbg_realloc;
static void (*free_debug_func)()= (void (*)())CRYPTO_dbg_free;
static void (*set_debug_options_func)()= (void (*)())CRYPTO_dbg_set_options;
static int (*get_debug_options_func)()= (int (*)())CRYPTO_dbg_get_options;
#else
static void (*malloc_debug_func)()= (void (*)())NULL;
static void (*realloc_debug_func)()= (void (*)())NULL;
static void (*free_debug_func)()= (void (*)())NULL;
static void (*set_debug_options_func)()= (void (*)())NULL;
static int (*get_debug_options_func)()= (int (*)())NULL;
#endif
void CRYPTO_set_mem_functions(char *(*m)(), char *(*r)(), void (*f)())
{
......@@ -128,11 +136,13 @@ void *CRYPTO_malloc_locked(int num, char *file, int line)
{
char *ret = NULL;
if (malloc_debug_func != NULL)
malloc_debug_func(NULL, num, file, line, 0);
ret = malloc_locked_func(num);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: > 0x%p (%d)\n", ret, num);
#endif
if (malloc_debug_func != NULL)
malloc_debug_func(ret, num, file, line, 1);
return ret;
......@@ -140,11 +150,13 @@ void *CRYPTO_malloc_locked(int num, char *file, int line)
void CRYPTO_free_locked(void *str)
{
if (free_debug_func != NULL)
free_debug_func(str, 0);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: < 0x%p\n", str);
#endif
free_locked_func(str);
if (free_debug_func != NULL)
free_debug_func(NULL, 1);
}
......@@ -152,11 +164,13 @@ void *CRYPTO_malloc(int num, char *file, int line)
{
char *ret = NULL;
if (malloc_debug_func != NULL)
malloc_debug_func(NULL, num, file, line, 0);
ret = malloc_func(num);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: > 0x%p (%d)\n", ret, num);
#endif
if (malloc_debug_func != NULL)
malloc_debug_func(ret, num, file, line, 1);
return ret;
......@@ -166,11 +180,13 @@ void *CRYPTO_realloc(void *str, int num, char *file, int line)
{
char *ret = NULL;
if (realloc_debug_func != NULL)
realloc_debug_func(str, NULL, num, file, line, 0);
ret = realloc_func(str,num);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: | 0x%p -> 0x%p (%d)\n", str, ret, num);
#endif
if (realloc_debug_func != NULL)
realloc_debug_func(str, ret, num, file, line, 1);
return ret;
......@@ -178,11 +194,13 @@ void *CRYPTO_realloc(void *str, int num, char *file, int line)
void CRYPTO_free(void *str)
{
if (free_debug_func != NULL)
free_debug_func(str, 0);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: < 0x%p\n", str);
#endif
free_func(str);
if (free_debug_func != NULL)
free_debug_func(NULL, 1);
}
......@@ -196,10 +214,12 @@ void *CRYPTO_remalloc(void *a, int num, char *file, int line)
void CRYPTO_set_mem_debug_options(int bits)
{
if (set_debug_options_func != NULL)
set_debug_options_func(bits);
}
int CRYPTO_get_mem_debug_options()
{
if (get_debug_options_func != NULL)
return get_debug_options_func();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册