malloc.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* malloc.h -- header file for memory routines. */
  2. #ifndef _INCLUDE_MALLOC_H_
  3. #define _INCLUDE_MALLOC_H_
  4. #include <_ansi.h>
  5. #include <sys/reent.h>
  6. #define __need_size_t
  7. #include <stddef.h>
  8. /* include any machine-specific extensions */
  9. #include <machine/malloc.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /* This version of struct mallinfo must match the one in
  14. libc/stdlib/mallocr.c. */
  15. struct mallinfo {
  16. size_t arena; /* total space allocated from system */
  17. size_t ordblks; /* number of non-inuse chunks */
  18. size_t smblks; /* unused -- always zero */
  19. size_t hblks; /* number of mmapped regions */
  20. size_t hblkhd; /* total space in mmapped regions */
  21. size_t usmblks; /* unused -- always zero */
  22. size_t fsmblks; /* unused -- always zero */
  23. size_t uordblks; /* total allocated space */
  24. size_t fordblks; /* total non-inuse space */
  25. size_t keepcost; /* top-most, releasable (via malloc_trim) space */
  26. };
  27. /* The routines. */
  28. extern void *malloc (size_t);
  29. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  30. #undef _malloc_r
  31. #define _malloc_r(r, s) malloc (s)
  32. #else
  33. extern void *_malloc_r (struct _reent *, size_t);
  34. #endif
  35. extern void free (void *);
  36. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  37. #undef _free_r
  38. #define _free_r(r, p) free (p)
  39. #else
  40. extern void _free_r (struct _reent *, void *);
  41. #endif
  42. extern void *realloc (void *, size_t);
  43. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  44. #undef _realloc_r
  45. #define _realloc_r(r, p, s) realloc (p, s)
  46. #else
  47. extern void *_realloc_r (struct _reent *, void *, size_t);
  48. #endif
  49. extern void *calloc (size_t, size_t);
  50. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  51. #undef _calloc_r
  52. #define _calloc_r(r, s1, s2) calloc (s1, s2);
  53. #else
  54. extern void *_calloc_r (struct _reent *, size_t, size_t);
  55. #endif
  56. extern void *memalign (size_t, size_t);
  57. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  58. #undef _memalign_r
  59. #define _memalign_r(r, s1, s2) memalign (s1, s2);
  60. #else
  61. extern void *_memalign_r (struct _reent *, size_t, size_t);
  62. #endif
  63. extern struct mallinfo mallinfo (void);
  64. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  65. #undef _mallinfo_r
  66. #define _mallinfo_r(r) mallinfo ()
  67. #else
  68. extern struct mallinfo _mallinfo_r (struct _reent *);
  69. #endif
  70. extern void malloc_stats (void);
  71. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  72. #undef _malloc_stats_r
  73. #define _malloc_stats_r(r) malloc_stats ()
  74. #else
  75. extern void _malloc_stats_r (struct _reent *);
  76. #endif
  77. extern int mallopt (int, int);
  78. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  79. #undef _mallopt_r
  80. #define _mallopt_r(i1, i2) mallopt (i1, i2)
  81. #else
  82. extern int _mallopt_r (struct _reent *, int, int);
  83. #endif
  84. extern size_t malloc_usable_size (void *);
  85. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  86. #undef _malloc_usable_size_r
  87. #define _malloc_usable_size_r(r, p) malloc_usable_size (p)
  88. #else
  89. extern size_t _malloc_usable_size_r (struct _reent *, void *);
  90. #endif
  91. /* These aren't too useful on an embedded system, but we define them
  92. anyhow. */
  93. extern void *valloc (size_t);
  94. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  95. #undef _valloc_r
  96. #define _valloc_r(r, s) valloc (s)
  97. #else
  98. extern void *_valloc_r (struct _reent *, size_t);
  99. #endif
  100. extern void *pvalloc (size_t);
  101. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  102. #undef _pvalloc_r
  103. #define _pvalloc_r(r, s) pvalloc (s)
  104. #else
  105. extern void *_pvalloc_r (struct _reent *, size_t);
  106. #endif
  107. extern int malloc_trim (size_t);
  108. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  109. #undef _malloc_trim_r
  110. #define _malloc_trim_r(r, s) malloc_trim (s)
  111. #else
  112. extern int _malloc_trim_r (struct _reent *, size_t);
  113. #endif
  114. extern void __malloc_lock(struct _reent *);
  115. extern void __malloc_unlock(struct _reent *);
  116. /* A compatibility routine for an earlier version of the allocator. */
  117. extern void mstats (char *);
  118. #if defined(__CYGWIN__) || defined(MALLOC_PROVIDED)
  119. #undef _mstats_r
  120. #define _mstats_r(r, p) mstats (p)
  121. #else
  122. extern void _mstats_r (struct _reent *, char *);
  123. #endif
  124. /* SVID2/XPG mallopt options */
  125. #define M_MXFAST 1 /* UNUSED in this malloc */
  126. #define M_NLBLKS 2 /* UNUSED in this malloc */
  127. #define M_GRAIN 3 /* UNUSED in this malloc */
  128. #define M_KEEP 4 /* UNUSED in this malloc */
  129. /* mallopt options that actually do something */
  130. #define M_TRIM_THRESHOLD -1
  131. #define M_TOP_PAD -2
  132. #define M_MMAP_THRESHOLD -3
  133. #define M_MMAP_MAX -4
  134. #ifndef __CYGWIN__
  135. /* Some systems provide this, so do too for compatibility. */
  136. extern void cfree (void *);
  137. #endif /* __CYGWIN__ */
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif /* _INCLUDE_MALLOC_H_ */