astmm.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief Asterisk memory usage debugging
00021  * This file provides headers for MALLOC_DEBUG, a define used for tracking down
00022  * memory leaks.  It should never be \#included directly; always use the
00023  * MALLOC_DEBUG definition in menuselect to activate those functions.
00024  */
00025 
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 #ifndef _ASTERISK_ASTMM_H
00032 #define _ASTERISK_ASTMM_H
00033 
00034 #ifndef STANDALONE
00035 
00036 #define __AST_DEBUG_MALLOC
00037 
00038 #include "asterisk.h"
00039 
00040 /* Include these now to prevent them from being needed later */
00041 #include <sys/types.h>
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include <stdio.h>
00045 #include <stdarg.h>
00046 
00047 /* Undefine any macros */
00048 #undef malloc
00049 #undef calloc
00050 #undef realloc
00051 #undef strdup
00052 #undef strndup
00053 #undef asprintf
00054 #undef vasprintf
00055 #undef free
00056 
00057 void *ast_std_malloc(size_t size);
00058 void *ast_std_calloc(size_t nmemb, size_t size);
00059 void *ast_std_realloc(void *ptr, size_t size);
00060 void ast_std_free(void *ptr);
00061 void ast_free_ptr(void *ptr);
00062 
00063 void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
00064 void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
00065 void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
00066 void __ast_free(void *ptr, const char *file, int lineno, const char *func);
00067 void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
00068 char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
00069 char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
00070 int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
00071    __attribute__((format(printf, 5, 6)));
00072 int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
00073    __attribute__((format(printf, 2, 0)));
00074 void __ast_mm_init_phase_1(void);
00075 void __ast_mm_init_phase_2(void);
00076 
00077 /* Redefine libc malloc to our own versions */
00078 
00079 #ifdef WRAP_LIBC_MALLOC
00080 #define calloc(a,b) \
00081    __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00082 #define malloc(a) \
00083    __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00084 #define free(a) \
00085    __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00086 #define realloc(a,b) \
00087    __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00088 #define strdup(a) \
00089    __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00090 #define strndup(a,b) \
00091    __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00092 #define asprintf(a, b, c...) \
00093    __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
00094 #define vasprintf(a,b,c) \
00095    __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00096 #else
00097 #define calloc(a,b) \
00098    Do_not_use_calloc__use_ast_calloc(a,b)
00099 #define malloc(a) \
00100    Do_not_use_malloc__use_ast_malloc(a)
00101 #define free(a) \
00102    Do_not_use_free__use_ast_free_or_ast_std_free_for_remotely_allocated_memory(a)
00103 #define realloc(a,b) \
00104    Do_not_use_realloc__use_ast_realloc(a,b)
00105 #define strdup(a) \
00106    Do_not_use_strdup__use_ast_strdup(a)
00107 #define strndup(a,b) \
00108    Do_not_use_strndup__use_ast_strndup(a,b)
00109 #define asprintf(a, b, c...) \
00110    Do_not_use_asprintf__use_ast_asprintf(a,b,c)
00111 #define vasprintf(a,b,c) \
00112    Do_not_use_vasprintf__use_ast_vasprintf(a,b,c)
00113 #endif
00114 
00115 /* Provide our own definitions */
00116 
00117 #define ast_calloc(a,b) \
00118    __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00119 
00120 #define ast_calloc_cache(a,b) \
00121    __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00122 
00123 #define ast_malloc(a) \
00124    __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00125 
00126 #define ast_free(a) \
00127    __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00128 
00129 #define ast_realloc(a,b) \
00130    __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00131 
00132 #define ast_strdup(a) \
00133    __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00134 
00135 #define ast_strndup(a,b) \
00136    __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00137 
00138 #define ast_asprintf(a, b, c...) \
00139    __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
00140 
00141 #define ast_vasprintf(a,b,c) \
00142    __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
00143 
00144 #endif /* !STANDALONE */
00145 
00146 #else
00147 #error "NEVER INCLUDE astmm.h DIRECTLY!!"
00148 #endif /* _ASTERISK_ASTMM_H */
00149 
00150 #ifdef __cplusplus
00151 }
00152 #endif

Generated on Thu Apr 16 06:27:14 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6