malloc.h 6.1 KB

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