malloc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Prototypes and definition for malloc implementation.
  2. Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _MALLOC_H
  16. #define _MALLOC_H 1
  17. #include <features.h>
  18. /*
  19. `ptmalloc', a malloc implementation for multiple threads without
  20. lock contention, by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>.
  21. See the files `ptmalloc.c' or `COPYRIGHT' for copying conditions.
  22. VERSION 2.6.4-pt Wed Dec 4 00:35:54 MET 1996
  23. This work is mainly derived from malloc-2.6.4 by Doug Lea
  24. <dl@cs.oswego.edu>, which is available from:
  25. ftp://g.oswego.edu/pub/misc/malloc.c
  26. This trimmed-down header file only provides function prototypes and
  27. the exported data structures. For more detailed function
  28. descriptions and compile-time options, see the source file
  29. `ptmalloc.c'.
  30. */
  31. #if defined(__STDC__) || defined (__cplusplus)
  32. # include <stddef.h>
  33. # define __malloc_ptr_t void *
  34. #else
  35. # undef size_t
  36. # define size_t unsigned int
  37. # undef ptrdiff_t
  38. # define ptrdiff_t int
  39. # define __malloc_ptr_t char *
  40. #endif
  41. #ifdef _LIBC
  42. /* Used by GNU libc internals. */
  43. # define __malloc_size_t size_t
  44. # define __malloc_ptrdiff_t ptrdiff_t
  45. #elif !defined __attribute_malloc__
  46. # define __attribute_malloc__
  47. #endif
  48. #ifdef __GNUC__
  49. /* GCC can always grok prototypes. For C++ programs we add throw()
  50. to help it optimize the function calls. But this works only with
  51. gcc 2.8.x and egcs. */
  52. #ifndef __THROW
  53. # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
  54. # define __THROW throw ()
  55. # else
  56. # define __THROW
  57. # endif
  58. #endif
  59. # define __MALLOC_P(args) args __THROW
  60. /* This macro will be used for functions which might take C++ callback
  61. functions. */
  62. # define __MALLOC_PMT(args) args
  63. #else /* Not GCC. */
  64. # define __THROW
  65. # if (defined __STDC__ && __STDC__) || defined __cplusplus
  66. # define __MALLOC_P(args) args
  67. # define __MALLOC_PMT(args) args
  68. # else /* Not ANSI C or C++. */
  69. # define __MALLOC_P(args) () /* No prototypes. */
  70. # define __MALLOC_PMT(args) ()
  71. # endif /* ANSI C or C++. */
  72. #endif /* GCC. */
  73. #ifndef NULL
  74. # ifdef __cplusplus
  75. # define NULL 0
  76. # else
  77. # define NULL ((__malloc_ptr_t) 0)
  78. # endif
  79. #endif
  80. #ifdef __cplusplus
  81. extern "C" {
  82. #endif
  83. /* Allocate SIZE bytes of memory. */
  84. extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  85. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  86. extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
  87. __attribute_malloc__;
  88. /* Re-allocate the previously allocated block in __ptr, making the new
  89. block SIZE bytes long. */
  90. extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
  91. size_t __size))
  92. __attribute_malloc__;
  93. /* Free a block allocated by `malloc', `realloc' or `calloc'. */
  94. extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
  95. /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
  96. extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
  97. libc_hidden_proto(memalign)
  98. #ifdef __UCLIBC_SUSV2_LEGACY__
  99. /* Allocate SIZE bytes on a page boundary. */
  100. extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  101. #endif
  102. #ifdef __MALLOC_STANDARD__
  103. /* SVID2/XPG mallinfo structure */
  104. struct mallinfo {
  105. int arena; /* total space allocated from system */
  106. int ordblks; /* number of non-inuse chunks */
  107. int smblks; /* unused -- always zero */
  108. int hblks; /* number of mmapped regions */
  109. int hblkhd; /* total space in mmapped regions */
  110. int usmblks; /* unused -- always zero */
  111. int fsmblks; /* unused -- always zero */
  112. int uordblks; /* total allocated space */
  113. int fordblks; /* total non-inuse space */
  114. int keepcost; /* top-most, releasable (via malloc_trim) space */
  115. };
  116. /* Returns a copy of the updated current mallinfo. */
  117. extern struct mallinfo mallinfo __MALLOC_P ((void));
  118. libc_hidden_proto(mallinfo)
  119. /* Release all but __pad bytes of freed top-most memory back to the
  120. system. Return 1 if successful, else 0. */
  121. extern int malloc_trim(size_t pad);
  122. #include <stdio.h>
  123. /* Prints brief summary statistics to the specified file.
  124. * Writes to stderr if file is NULL. */
  125. extern void malloc_stats(FILE *file);
  126. /* SVID2/XPG mallopt options */
  127. #ifndef M_MXFAST
  128. # define M_MXFAST 1 /* UNUSED in this malloc */
  129. #endif
  130. #ifndef M_NLBLKS
  131. # define M_NLBLKS 2 /* UNUSED in this malloc */
  132. #endif
  133. #ifndef M_GRAIN
  134. # define M_GRAIN 3 /* UNUSED in this malloc */
  135. #endif
  136. #ifndef M_KEEP
  137. # define M_KEEP 4 /* UNUSED in this malloc */
  138. #endif
  139. /* mallopt options that actually do something */
  140. #define M_TRIM_THRESHOLD -1
  141. #define M_TOP_PAD -2
  142. #define M_MMAP_THRESHOLD -3
  143. #define M_MMAP_MAX -4
  144. #define M_CHECK_ACTION -5
  145. #define M_PERTURB -6
  146. /* General SVID/XPG interface to tunable parameters. */
  147. extern int mallopt __MALLOC_P ((int __param, int __val));
  148. #endif /* __MALLOC_STANDARD__ */
  149. /* uClibc may use malloc internally in situations where user can not be
  150. * notified about out-of-memory condition. In this situation uClibc will
  151. * call __uc_malloc_failed if it is non-NULL, and retry allocation
  152. * if it returns. If __uc_malloc_failed is NULL, uclibc will _exit(1).
  153. * NB: do not use stdio in __uc_malloc_failed handler! */
  154. extern void *__uc_malloc(size_t size);
  155. libc_hidden_proto(__uc_malloc)
  156. extern void (*__uc_malloc_failed)(size_t size);
  157. libc_hidden_proto(__uc_malloc_failed)
  158. #ifdef __cplusplus
  159. } /* end of extern "C" */
  160. #endif
  161. #endif /* malloc.h */