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