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