2 Copyright (c) 2001 Wolfram Gloger
3 Copyright (c) 2006 Cavium networks
5 Permission to use, copy, modify, distribute, and sell this software
6 and its documentation for any purpose is hereby granted without fee,
7 provided that (i) the above copyright notices and this permission
8 notice appear in all copies of the software and related documentation,
9 and (ii) the name of Wolfram Gloger may not be used in any advertising
10 or publicity relating to the software.
12 THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
13 EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
14 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 IN NO EVENT SHALL WOLFRAM GLOGER BE LIABLE FOR ANY SPECIAL,
17 INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY
18 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY
20 OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 PERFORMANCE OF THIS SOFTWARE.
33 $Id: malloc.h 30481 2007-12-05 21:46:59Z rfranz $
34 `ptmalloc2', a malloc implementation for multiple threads without
35 lock contention, by Wolfram Gloger <wg@malloc.de>.
39 This work is mainly derived from malloc-2.7.0 by Doug Lea
40 <dl@cs.oswego.edu>, which is available from:
42 ftp://gee.cs.oswego.edu/pub/misc/malloc.c
44 This trimmed-down header file only provides function prototypes and
45 the exported data structures. For more detailed function
46 descriptions and compile-time options, see the source file
52 # define __malloc_ptr_t void *
54 # define size_t unsigned long
56 # define ptrdiff_t long
60 # define __malloc_ptr_t char *
64 /* Used by GNU libc internals. */
65 # define __malloc_size_t size_t
66 # define __malloc_ptrdiff_t ptrdiff_t
67 #elif !defined __attribute_malloc__
68 # define __attribute_malloc__
73 /* GCC can always grok prototypes. For C++ programs we add throw()
74 to help it optimize the function calls. But this works only with
75 gcc 2.8.x and egcs. */
76 # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
77 # define __THROW throw ()
81 # define __MALLOC_P(args) args __THROW
82 /* This macro will be used for functions which might take C++ callback
84 # define __MALLOC_PMT(args) args
90 # if (defined __STDC__ && __STDC__) || defined __cplusplus
92 # define __MALLOC_P(args) args
93 # define __MALLOC_PMT(args) args
95 # else /* Not ANSI C or C++. */
97 # define __MALLOC_P(args) () /* No prototypes. */
98 # define __MALLOC_PMT(args) ()
100 # endif /* ANSI C or C++. */
108 # define NULL ((__malloc_ptr_t) 0)
116 /* Nonzero if the malloc is already initialized. */
118 /* In the GNU libc we rename the global variable
119 `__malloc_initialized' to `__libc_malloc_initialized'. */
120 # define __malloc_initialized __libc_malloc_initialized
122 extern int cvmx__malloc_initialized;
125 /* SVID2/XPG mallinfo structure */
128 int arena; /* non-mmapped space allocated from system */
129 int ordblks; /* number of free chunks */
130 int smblks; /* number of fastbin blocks */
131 int hblks; /* number of mmapped regions */
132 int hblkhd; /* space in mmapped regions */
133 int usmblks; /* maximum total allocated space */
134 int fsmblks; /* space available in freed fastbin blocks */
135 int uordblks; /* total allocated space */
136 int fordblks; /* total free space */
137 int keepcost; /* top-most, releasable (via malloc_trim) space */
140 /* Returns a copy of the updated current mallinfo. */
141 extern struct mallinfo mallinfo __MALLOC_P ((void));
143 /* SVID2/XPG mallopt options */
145 # define M_MXFAST 1 /* maximum request size for "fastbins" */
148 # define M_NLBLKS 2 /* UNUSED in this malloc */
151 # define M_GRAIN 3 /* UNUSED in this malloc */
154 # define M_KEEP 4 /* UNUSED in this malloc */
157 /* mallopt options that actually do something */
158 #define M_TRIM_THRESHOLD -1
160 #define M_MMAP_THRESHOLD -3
161 #define M_MMAP_MAX -4
162 #define M_CHECK_ACTION -5
164 /* General SVID/XPG interface to tunable parameters. */
165 extern int mallopt __MALLOC_P ((int __param, int __val));
167 /* Release all but __pad bytes of freed top-most memory back to the
168 system. Return 1 if successful, else 0. */
169 extern int malloc_trim __MALLOC_P ((size_t __pad));
171 /* Report the number of usable allocated bytes associated with allocated
173 extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
175 /* Prints brief summary statistics on stderr. */
176 extern void malloc_stats __MALLOC_P ((void));
178 /* Record the state of all malloc variables in an opaque data structure. */
179 extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
181 /* Restore the state of all malloc variables from data obtained with
182 malloc_get_state(). */
183 extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
185 /* Called once when malloc is initialized; redefining this variable in
186 the application provides the preferred way to set up the hook
188 extern void (*cmvx__malloc_initialize_hook) __MALLOC_PMT ((void));
189 /* Hooks for debugging and user-defined versions. */
190 extern void (*cvmx__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
191 __const __malloc_ptr_t));
192 extern __malloc_ptr_t (*cvmx__malloc_hook) __MALLOC_PMT ((size_t __size,
193 __const __malloc_ptr_t));
194 extern __malloc_ptr_t (*cvmx__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
196 __const __malloc_ptr_t));
197 extern __malloc_ptr_t (*cvmx__memalign_hook) __MALLOC_PMT ((size_t __alignment,
199 __const __malloc_ptr_t));
200 extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
202 /* Activate a standard set of debugging hooks. */
203 extern void cvmx__malloc_check_init __MALLOC_P ((void));
205 /* Internal routines, operating on "arenas". */
207 typedef struct malloc_state *mstate;
209 }; /* end of extern "C" */
213 #endif /* malloc.h */