Changes between 0.9.6 and 0.9.7 [xx XXX 2000]
+ *) Add another call level for memory allocation routines, thereby
+ allowing memory allocation callbacks that can be given file
+ name and line number information. The basic functionality
+ remains, as well as the original possibility to just replace
+ malloc(), realloc() and free(). The new functions that can be
+ registered help users provide variants of malloc(), realloc()
+ and free() that take two extra arguments, a const char* and an
+ int. To register and find out the current settings for those
+ hooks, the following functions are provided:
+
+ CRYPTO_set_mem_ex_functions
+ CRYPTO_set_locked_mem_ex_functions
+ CRYPTO_get_mem_ex_functions
+ CRYPTO_get_locked_mem_ex_functions
+
+ They work the same way as the corresponding CRYPTO_set_mem_functions
+ and friends with one exception: giving NULL as arguments will restore
+ the internal hooks to internal routines and will still make the above
+ functions return 1 and not 0.
+
+ This functionality was created as a direct request to add the
+ possibility to interface with the Windows debugging routines
+ _malloc_dbg, _realloc_dbg and _free_dbg.
+ [Richard Levitte]
+
*) Fix to uni2asc() to cope with zero length Unicode strings.
These are present in some PKCS#12 files.
[Steve Henson]
* call the latter last if you need different functions */
int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));
int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));
+int CRYPTO_set_mem_ex_functions(void *(*m)(size_t,const char *,int),
+ void *(*r)(void *,size_t,const char *,int),
+ void (*f)(void *,const char *,int));
+int CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t,const char *,int),
+ void (*free_func)(void *,const char *,int));
int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
void (*r)(void *,void *,int,const char *,int,int),
void (*f)(void *,int),
long (*go)(void));
void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
+void CRYPTO_get_mem_ex_functions(void *(**m)(size_t,const char *,int),
+ void *(**r)(void *, size_t,const char *,int),
+ void (**f)(void *,const char *,int));
+void CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t,const char *,int),
+ void (**f)(void *,const char *,int));
void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
void (**r)(void *,void *,int,const char *,int,int),
void (**f)(void *,int),
static void *(*realloc_func)(void *, size_t)= realloc;
static void (*free_func)(void *) = free;
+static void *crypto_i_malloc_ex(size_t, const char *file, int line);
+static void *crypto_i_realloc_ex(void *, size_t, const char *file, int line);
+static void crypto_i_free_ex(void *);
+static void *(*malloc_locked_ex_func)(size_t, const char *file, int line)
+ = crypto_i_malloc_ex;
+static void (*free_locked_ex_func)(void *)
+ = crypto_i_free_ex;
+static void *(*malloc_ex_func)(size_t, const char *file, int line)
+ = crypto_i_malloc_ex;
+static void *(*realloc_ex_func)(void *, size_t, const char *file, int line)
+ = crypto_i_realloc_ex;
+static void (*free_ex_func)(void *)
+ = crypto_i_free_ex;
+
/* may be changed as long as `allow_customize_debug' is set */
/* XXX use correct function pointer types */
#ifdef CRYPTO_MDEBUG
return 1;
}
+int CRYPTO_set_mem_ex_functions(
+ void *(*m)(size_t,const char *,int),
+ void *(*r)(void *, size_t,const char *,int),
+ void (*f)(void *))
+ {
+ if (!allow_customize)
+ return 0;
+ if (m == NULL) m = crypto_i_malloc_ex;
+ if (r == NULL) r = crypto_i_realloc_ex;
+ if (f == NULL) f = crypto_i_free_ex;
+ malloc_ex_func=m;
+ realloc_ex_func=r;
+ free_ex_func=f;
+ malloc_locked_ex_func=m;
+ free_locked_ex_func=f;
+ return 1;
+ }
+
int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
{
if (!allow_customize)
return 1;
}
+int CRYPTO_set_locked_mem_ex_functions(
+ void *(*m)(size_t,const char *,int),
+ void (*f)(void *))
+ {
+ if (!allow_customize)
+ return 0;
+ if (m == NULL) m = crypto_i_malloc_ex;
+ if (f == NULL) f = crypto_i_free_ex;
+ malloc_locked_ex_func=m;
+ free_locked_ex_func=f;
+ return 1;
+ }
+
int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
void (*r)(void *,void *,int,const char *,int,int),
void (*f)(void *,int),
if (f != NULL) *f=free_func;
}
+void CRYPTO_get_mem_ex_functions(
+ void *(**m)(size_t,const char *,int),
+ void *(**r)(void *, size_t,const char *,int),
+ void (**f)(void *))
+ {
+ if (m != NULL) *m=malloc_ex_func;
+ if (r != NULL) *r=realloc_ex_func;
+ if (f != NULL) *f=free_ex_func;
+ }
+
void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
{
if (m != NULL) *m=malloc_locked_func;
if (f != NULL) *f=free_locked_func;
}
+void CRYPTO_get_locked_mem_ex_functions(
+ void *(**m)(size_t,const char *,int),
+ void (**f)(void *))
+ {
+ if (m != NULL) *m=malloc_locked_ex_func;
+ if (f != NULL) *f=free_locked_ex_func;
+ }
+
void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
void (**r)(void *,void *,int,const char *,int,int),
void (**f)(void *,int),
allow_customize_debug = 0;
malloc_debug_func(NULL, num, file, line, 0);
}
- ret = malloc_locked_func(num);
+ ret = malloc_locked_ex_func(num,file,line);
#ifdef LEVITTE_DEBUG_MEM
fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num);
#endif
#ifdef LEVITTE_DEBUG_MEM
fprintf(stderr, "LEVITTE_DEBUG_MEM: < 0x%p\n", str);
#endif
- free_locked_func(str);
+ free_locked_ex_func(str);
if (free_debug_func != NULL)
free_debug_func(NULL, 1);
}
allow_customize_debug = 0;
malloc_debug_func(NULL, num, file, line, 0);
}
- ret = malloc_func(num);
+ ret = malloc_ex_func(num,file,line);
#ifdef LEVITTE_DEBUG_MEM
fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num);
#endif
if (realloc_debug_func != NULL)
realloc_debug_func(str, NULL, num, file, line, 0);
- ret = realloc_func(str,num);
+ ret = realloc_ex_func(str,num,file,line);
#ifdef LEVITTE_DEBUG_MEM
fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num);
#endif
#ifdef LEVITTE_DEBUG_MEM
fprintf(stderr, "LEVITTE_DEBUG_MEM: < 0x%p\n", str);
#endif
- free_func(str);
+ free_ex_func(str);
if (free_debug_func != NULL)
free_debug_func(NULL, 1);
}
return get_debug_options_func();
return 0;
}
+
+static void *crypto_i_malloc_ex(size_t num, const char *file, int line)
+ {
+ return malloc_func(num);
+ }
+
+static void *crypto_i_realloc_ex(void *str, size_t num,
+ const char *file, int line)
+ {
+ return realloc_func(str,num);
+ }
+
+static void crypto_i_free_ex(void *str)
+ {
+ free_func(str);
+ }