Update.
[platform/upstream/glibc.git] / malloc / malloc.h
1 /* Prototypes and definition for malloc implementation.
2    Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20 #ifndef _MALLOC_H
21 #define _MALLOC_H 1
22
23 #include <features.h>
24
25 /*
26   `ptmalloc', a malloc implementation for multiple threads without
27   lock contention, by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>.
28   See the files `ptmalloc.c' or `COPYRIGHT' for copying conditions.
29
30   VERSION 2.6.4-pt Wed Dec  4 00:35:54 MET 1996
31
32   This work is mainly derived from malloc-2.6.4 by Doug Lea
33   <dl@cs.oswego.edu>, which is available from:
34
35                  ftp://g.oswego.edu/pub/misc/malloc.c
36
37   This trimmed-down header file only provides function prototypes and
38   the exported data structures.  For more detailed function
39   descriptions and compile-time options, see the source file
40   `ptmalloc.c'.
41 */
42
43 #if defined(__STDC__) || defined (__cplusplus)
44 # include <stddef.h>
45 # define __malloc_ptr_t  void *
46 #else
47 # undef  size_t
48 # define size_t          unsigned int
49 # undef  ptrdiff_t
50 # define ptrdiff_t       int
51 # define __malloc_ptr_t  char *
52 #endif
53
54 #ifdef _LIBC
55 /* Used by GNU libc internals. */
56 # define __malloc_size_t size_t
57 # define __malloc_ptrdiff_t ptrdiff_t
58 #elif !defined __attribute_malloc__
59 # define __attribute_malloc__
60 #endif
61
62 #ifdef __GNUC__
63
64 /* GCC can always grok prototypes.  For C++ programs we add throw()
65    to help it optimize the function calls.  But this works only with
66    gcc 2.8.x and egcs.  */
67 # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
68 #  define __THROW       throw ()
69 # else
70 #  define __THROW
71 # endif
72 # define __MALLOC_P(args)       args __THROW
73 /* This macro will be used for functions which might take C++ callback
74    functions.  */
75 # define __MALLOC_PMT(args)     args
76
77 #else   /* Not GCC.  */
78
79 # if (defined __STDC__ && __STDC__) || defined __cplusplus
80
81 #  define __MALLOC_P(args)      args
82 #  define __MALLOC_PMT(args)    args
83
84 # else  /* Not ANSI C or C++.  */
85
86 #  define __MALLOC_P(args)      ()      /* No prototypes.  */
87 #  define __MALLOC_PMT(args)    ()
88
89 # endif /* ANSI C or C++.  */
90
91 #endif  /* GCC.  */
92
93 #ifndef NULL
94 # ifdef __cplusplus
95 #  define NULL  0
96 # else
97 #  define NULL  ((__malloc_ptr_t) 0)
98 # endif
99 #endif
100
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104
105 /* Nonzero if the malloc is already initialized.  */
106 #ifdef _LIBC
107 /* In the GNU libc we rename the global variable
108    `__malloc_initialized' to `__libc_malloc_initialized'.  */
109 # define __malloc_initialized __libc_malloc_initialized
110 #endif
111 extern int __malloc_initialized;
112
113 /* Initialize global configuration.  Not needed with GNU libc. */
114 #ifndef __GLIBC__
115 extern void ptmalloc_init __MALLOC_P ((void));
116 #endif
117
118 /* Allocate SIZE bytes of memory.  */
119 extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
120
121 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
122 extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
123        __attribute_malloc__;
124
125 /* Re-allocate the previously allocated block in __ptr, making the new
126    block SIZE bytes long.  */
127 extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
128                                            size_t __size))
129        __attribute_malloc__;
130
131 /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
132 extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
133
134 /* Free a block allocated by `calloc'. */
135 extern void cfree __MALLOC_P ((__malloc_ptr_t __ptr));
136
137 /* Allocate SIZE bytes allocated to ALIGNMENT bytes.  */
138 extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
139
140 /* Allocate SIZE bytes on a page boundary.  */
141 extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
142
143 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
144    __size to nearest pagesize. */
145 extern __malloc_ptr_t  pvalloc __MALLOC_P ((size_t __size))
146        __attribute_malloc__;
147
148 /* Underlying allocation function; successive calls should return
149    contiguous pieces of memory.  */
150 extern __malloc_ptr_t (*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
151
152 /* Default value of `__morecore'.  */
153 extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size))
154        __attribute_malloc__;
155
156 /* SVID2/XPG mallinfo structure */
157 struct mallinfo {
158   int arena;    /* total space allocated from system */
159   int ordblks;  /* number of non-inuse chunks */
160   int smblks;   /* unused -- always zero */
161   int hblks;    /* number of mmapped regions */
162   int hblkhd;   /* total space in mmapped regions */
163   int usmblks;  /* unused -- always zero */
164   int fsmblks;  /* unused -- always zero */
165   int uordblks; /* total allocated space */
166   int fordblks; /* total non-inuse space */
167   int keepcost; /* top-most, releasable (via malloc_trim) space */
168 };
169
170 /* Returns a copy of the updated current mallinfo. */
171 extern struct mallinfo mallinfo __MALLOC_P ((void));
172
173 /* SVID2/XPG mallopt options */
174 #ifndef M_MXFAST
175 # define M_MXFAST  1    /* UNUSED in this malloc */
176 #endif
177 #ifndef M_NLBLKS
178 # define M_NLBLKS  2    /* UNUSED in this malloc */
179 #endif
180 #ifndef M_GRAIN
181 # define M_GRAIN   3    /* UNUSED in this malloc */
182 #endif
183 #ifndef M_KEEP
184 # define M_KEEP    4    /* UNUSED in this malloc */
185 #endif
186
187 /* mallopt options that actually do something */
188 #define M_TRIM_THRESHOLD    -1
189 #define M_TOP_PAD           -2
190 #define M_MMAP_THRESHOLD    -3
191 #define M_MMAP_MAX          -4
192 #define M_CHECK_ACTION      -5
193
194 /* General SVID/XPG interface to tunable parameters. */
195 extern int mallopt __MALLOC_P ((int __param, int __val));
196
197 /* Release all but __pad bytes of freed top-most memory back to the
198    system. Return 1 if successful, else 0. */
199 extern int malloc_trim __MALLOC_P ((size_t __pad));
200
201 /* Report the number of usable allocated bytes associated with allocated
202    chunk __ptr. */
203 extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
204
205 /* Prints brief summary statistics on stderr. */
206 extern void malloc_stats __MALLOC_P ((void));
207
208 /* Record the state of all malloc variables in an opaque data structure. */
209 extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
210
211 /* Restore the state of all malloc variables from data obtained with
212    malloc_get_state(). */
213 extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
214
215 #if defined __GLIBC__ || defined MALLOC_HOOKS
216 /* Called once when malloc is initialized; redefining this variable in
217    the application provides the preferred way to set up the hook
218    pointers. */
219 extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
220 /* Hooks for debugging and user-defined versions. */
221 extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
222                                         __const __malloc_ptr_t));
223 extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
224                                                     __const __malloc_ptr_t));
225 extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
226                                                      size_t __size,
227                                                      __const __malloc_ptr_t));
228 extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
229                                                       size_t __size,
230                                                       __const __malloc_ptr_t));
231 extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
232
233 /* Activate a standard set of debugging hooks. */
234 extern void __malloc_check_init __MALLOC_P ((void));
235 #endif
236
237 #ifdef __cplusplus
238 }; /* end of extern "C" */
239 #endif
240
241 #endif /* malloc.h */