astmm.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2006, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Asterisk memory usage debugging
  20. * This file provides headers for MALLOC_DEBUG, a define used for tracking down
  21. * memory leaks. It should never be \#included directly; always use the
  22. * MALLOC_DEBUG definition in menuselect to activate those functions.
  23. */
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef _ASTERISK_ASTMM_H
  28. #define _ASTERISK_ASTMM_H
  29. #ifndef STANDALONE
  30. #define __AST_DEBUG_MALLOC
  31. #include "asterisk.h"
  32. /* Include these now to prevent them from being needed later */
  33. #include <sys/types.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <stdio.h>
  37. #include <stdarg.h>
  38. /* Undefine any macros */
  39. #undef malloc
  40. #undef calloc
  41. #undef realloc
  42. #undef strdup
  43. #undef strndup
  44. #undef asprintf
  45. #undef vasprintf
  46. #undef free
  47. void *ast_std_malloc(size_t size);
  48. void *ast_std_calloc(size_t nmemb, size_t size);
  49. void *ast_std_realloc(void *ptr, size_t size);
  50. void ast_std_free(void *ptr);
  51. void ast_free_ptr(void *ptr);
  52. void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
  53. void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
  54. void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
  55. void __ast_free(void *ptr, const char *file, int lineno, const char *func);
  56. void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
  57. char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
  58. char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
  59. int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
  60. __attribute__((format(printf, 5, 6)));
  61. int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
  62. __attribute__((format(printf, 2, 0)));
  63. void __ast_mm_init_phase_1(void);
  64. void __ast_mm_init_phase_2(void);
  65. /* Provide our own definitions */
  66. #define calloc(a,b) \
  67. __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  68. #define ast_calloc(a,b) \
  69. __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  70. #define ast_calloc_cache(a,b) \
  71. __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  72. #define malloc(a) \
  73. __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  74. #define ast_malloc(a) \
  75. __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  76. #define free(a) \
  77. __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  78. #define ast_free(a) \
  79. __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  80. #define realloc(a,b) \
  81. __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  82. #define ast_realloc(a,b) \
  83. __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  84. #define strdup(a) \
  85. __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  86. #define ast_strdup(a) \
  87. __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  88. #define strndup(a,b) \
  89. __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  90. #define ast_strndup(a,b) \
  91. __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  92. #define asprintf(a, b, c...) \
  93. __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
  94. #define ast_asprintf(a, b, c...) \
  95. __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
  96. #define vasprintf(a,b,c) \
  97. __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  98. #define ast_vasprintf(a,b,c) \
  99. __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  100. #endif /* !STANDALONE */
  101. #else
  102. #error "NEVER INCLUDE astmm.h DIRECTLY!!"
  103. #endif /* _ASTERISK_ASTMM_H */
  104. #ifdef __cplusplus
  105. }
  106. #endif