malloc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Prototypes and definition for malloc implementation.
  2. Copyright (C) 1996-2016 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. #include <stddef.h>
  19. #include <stdio.h>
  20. #ifdef _LIBC
  21. # define __MALLOC_HOOK_VOLATILE
  22. # define __MALLOC_DEPRECATED
  23. #else
  24. # define __MALLOC_HOOK_VOLATILE volatile
  25. # define __MALLOC_DEPRECATED __attribute_deprecated__
  26. #endif
  27. __BEGIN_DECLS
  28. /* Allocate SIZE bytes of memory. */
  29. extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
  30. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  31. extern void *calloc (size_t __nmemb, size_t __size)
  32. __THROW __attribute_malloc__ __wur;
  33. /* Re-allocate the previously allocated block in __ptr, making the new
  34. block SIZE bytes long. */
  35. /* __attribute_malloc__ is not used, because if realloc returns
  36. the same pointer that was passed to it, aliasing needs to be allowed
  37. between objects pointed by the old and new pointers. */
  38. extern void *realloc (void *__ptr, size_t __size)
  39. __THROW __attribute_warn_unused_result__;
  40. /* Free a block allocated by `malloc', `realloc' or `calloc'. */
  41. extern void free (void *__ptr) __THROW;
  42. /* Free a block allocated by `calloc'. */
  43. extern void cfree (void *__ptr) __THROW;
  44. /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
  45. extern void *memalign (size_t __alignment, size_t __size)
  46. __THROW __attribute_malloc__ __wur;
  47. /* Allocate SIZE bytes on a page boundary. */
  48. extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
  49. /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
  50. __size to nearest pagesize. */
  51. extern void *pvalloc (size_t __size) __THROW __attribute_malloc__ __wur;
  52. /* Underlying allocation function; successive calls should return
  53. contiguous pieces of memory. */
  54. extern void *(*__morecore) (ptrdiff_t __size);
  55. /* Default value of `__morecore'. */
  56. extern void *__default_morecore (ptrdiff_t __size)
  57. __THROW __attribute_malloc__;
  58. /* SVID2/XPG mallinfo structure */
  59. struct mallinfo
  60. {
  61. int arena; /* non-mmapped space allocated from system */
  62. int ordblks; /* number of free chunks */
  63. int smblks; /* number of fastbin blocks */
  64. int hblks; /* number of mmapped regions */
  65. int hblkhd; /* space in mmapped regions */
  66. int usmblks; /* maximum total allocated space */
  67. int fsmblks; /* space available in freed fastbin blocks */
  68. int uordblks; /* total allocated space */
  69. int fordblks; /* total free space */
  70. int keepcost; /* top-most, releasable (via malloc_trim) space */
  71. };
  72. /* Returns a copy of the updated current mallinfo. */
  73. extern struct mallinfo mallinfo (void) __THROW;
  74. /* SVID2/XPG mallopt options */
  75. #ifndef M_MXFAST
  76. # define M_MXFAST 1 /* maximum request size for "fastbins" */
  77. #endif
  78. #ifndef M_NLBLKS
  79. # define M_NLBLKS 2 /* UNUSED in this malloc */
  80. #endif
  81. #ifndef M_GRAIN
  82. # define M_GRAIN 3 /* UNUSED in this malloc */
  83. #endif
  84. #ifndef M_KEEP
  85. # define M_KEEP 4 /* UNUSED in this malloc */
  86. #endif
  87. /* mallopt options that actually do something */
  88. #define M_TRIM_THRESHOLD -1
  89. #define M_TOP_PAD -2
  90. #define M_MMAP_THRESHOLD -3
  91. #define M_MMAP_MAX -4
  92. #define M_CHECK_ACTION -5
  93. #define M_PERTURB -6
  94. #define M_ARENA_TEST -7
  95. #define M_ARENA_MAX -8
  96. /* General SVID/XPG interface to tunable parameters. */
  97. extern int mallopt (int __param, int __val) __THROW;
  98. /* Release all but __pad bytes of freed top-most memory back to the
  99. system. Return 1 if successful, else 0. */
  100. extern int malloc_trim (size_t __pad) __THROW;
  101. /* Report the number of usable allocated bytes associated with allocated
  102. chunk __ptr. */
  103. extern size_t malloc_usable_size (void *__ptr) __THROW;
  104. /* Prints brief summary statistics on stderr. */
  105. extern void malloc_stats (void) __THROW;
  106. /* Output information about state of allocator to stream FP. */
  107. extern int malloc_info (int __options, FILE *__fp) __THROW;
  108. /* Record the state of all malloc variables in an opaque data structure. */
  109. extern void *malloc_get_state (void) __THROW;
  110. /* Restore the state of all malloc variables from data obtained with
  111. malloc_get_state(). */
  112. extern int malloc_set_state (void *__ptr) __THROW;
  113. /* Called once when malloc is initialized; redefining this variable in
  114. the application provides the preferred way to set up the hook
  115. pointers. */
  116. extern void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void)
  117. __MALLOC_DEPRECATED;
  118. /* Hooks for debugging and user-defined versions. */
  119. extern void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *__ptr,
  120. const void *)
  121. __MALLOC_DEPRECATED;
  122. extern void *(*__MALLOC_HOOK_VOLATILE __malloc_hook)(size_t __size,
  123. const void *)
  124. __MALLOC_DEPRECATED;
  125. extern void *(*__MALLOC_HOOK_VOLATILE __realloc_hook)(void *__ptr,
  126. size_t __size,
  127. const void *)
  128. __MALLOC_DEPRECATED;
  129. extern void *(*__MALLOC_HOOK_VOLATILE __memalign_hook)(size_t __alignment,
  130. size_t __size,
  131. const void *)
  132. __MALLOC_DEPRECATED;
  133. extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
  134. /* Activate a standard set of debugging hooks. */
  135. extern void __malloc_check_init (void) __THROW __MALLOC_DEPRECATED;
  136. __END_DECLS
  137. #endif /* malloc.h */