1/*
2Copyright (c) 2001 Wolfram Gloger
3Copyright (c) 2006 Cavium networks
4
5Permission to use, copy, modify, distribute, and sell this software
6and its documentation for any purpose is hereby granted without fee,
7provided that (i) the above copyright notices and this permission
8notice appear in all copies of the software and related documentation,
9and (ii) the name of Wolfram Gloger may not be used in any advertising
10or publicity relating to the software.
11
12THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
13EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
14WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15
16IN NO EVENT SHALL WOLFRAM GLOGER BE LIABLE FOR ANY SPECIAL,
17INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY
18DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY
20OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21PERFORMANCE OF THIS SOFTWARE.
22*/
23
24#ifndef _MALLOC_H
25#define _MALLOC_H 1
26
27#undef _LIBC
28#ifdef _LIBC
29#include <features.h>
30#endif
31
32/*
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>.
36
37  VERSION 2.7.0
38
39  This work is mainly derived from malloc-2.7.0 by Doug Lea
40  <dl@cs.oswego.edu>, which is available from:
41
42                 ftp://gee.cs.oswego.edu/pub/misc/malloc.c
43
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
47  `malloc.c'.
48*/
49
50#if 0
51# include <stddef.h>
52# define __malloc_ptr_t  void *
53# undef  size_t
54# define size_t          unsigned long
55# undef  ptrdiff_t
56# define ptrdiff_t       long
57#else
58# undef  Void_t
59# define Void_t       void
60# define __malloc_ptr_t  char *
61#endif
62
63#ifdef _LIBC
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__
69#endif
70
71#ifdef __GNUC__
72
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 ()
78# else
79#  define __THROW
80# endif
81# define __MALLOC_P(args)	args __THROW
82/* This macro will be used for functions which might take C++ callback
83   functions.  */
84# define __MALLOC_PMT(args)	args
85
86#else	/* Not GCC.  */
87
88# define __THROW
89
90# if (defined __STDC__ && __STDC__) || defined __cplusplus
91
92#  define __MALLOC_P(args)	args
93#  define __MALLOC_PMT(args)	args
94
95# else	/* Not ANSI C or C++.  */
96
97#  define __MALLOC_P(args)	()	/* No prototypes.  */
98#  define __MALLOC_PMT(args)	()
99
100# endif	/* ANSI C or C++.  */
101
102#endif	/* GCC.  */
103
104#ifndef NULL
105# ifdef __cplusplus
106#  define NULL	0
107# else
108#  define NULL	((__malloc_ptr_t) 0)
109# endif
110#endif
111
112#ifdef __cplusplus
113extern "C" {
114#endif
115
116/* Nonzero if the malloc is already initialized.  */
117#ifdef _LIBC
118/* In the GNU libc we rename the global variable
119   `__malloc_initialized' to `__libc_malloc_initialized'.  */
120# define __malloc_initialized __libc_malloc_initialized
121#endif
122extern int cvmx__malloc_initialized;
123
124
125/* SVID2/XPG mallinfo structure */
126
127struct mallinfo {
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 */
138};
139
140/* Returns a copy of the updated current mallinfo. */
141extern struct mallinfo mallinfo __MALLOC_P ((void));
142
143/* SVID2/XPG mallopt options */
144#ifndef M_MXFAST
145# define M_MXFAST  1	/* maximum request size for "fastbins" */
146#endif
147#ifndef M_NLBLKS
148# define M_NLBLKS  2	/* UNUSED in this malloc */
149#endif
150#ifndef M_GRAIN
151# define M_GRAIN   3	/* UNUSED in this malloc */
152#endif
153#ifndef M_KEEP
154# define M_KEEP    4	/* UNUSED in this malloc */
155#endif
156
157/* mallopt options that actually do something */
158#define M_TRIM_THRESHOLD    -1
159#define M_TOP_PAD           -2
160#define M_MMAP_THRESHOLD    -3
161#define M_MMAP_MAX          -4
162#define M_CHECK_ACTION      -5
163
164/* General SVID/XPG interface to tunable parameters. */
165extern int mallopt __MALLOC_P ((int __param, int __val));
166
167/* Release all but __pad bytes of freed top-most memory back to the
168   system. Return 1 if successful, else 0. */
169extern int malloc_trim __MALLOC_P ((size_t __pad));
170
171/* Report the number of usable allocated bytes associated with allocated
172   chunk __ptr. */
173extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
174
175/* Prints brief summary statistics on stderr. */
176extern void malloc_stats __MALLOC_P ((void));
177
178/* Record the state of all malloc variables in an opaque data structure. */
179extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
180
181/* Restore the state of all malloc variables from data obtained with
182   malloc_get_state(). */
183extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
184
185/* Called once when malloc is initialized; redefining this variable in
186   the application provides the preferred way to set up the hook
187   pointers. */
188extern void (*cmvx__malloc_initialize_hook) __MALLOC_PMT ((void));
189/* Hooks for debugging and user-defined versions. */
190extern void (*cvmx__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
191					__const __malloc_ptr_t));
192extern __malloc_ptr_t (*cvmx__malloc_hook) __MALLOC_PMT ((size_t __size,
193						    __const __malloc_ptr_t));
194extern __malloc_ptr_t (*cvmx__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
195						     size_t __size,
196						     __const __malloc_ptr_t));
197extern __malloc_ptr_t (*cvmx__memalign_hook) __MALLOC_PMT ((size_t __alignment,
198						      size_t __size,
199						      __const __malloc_ptr_t));
200extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
201
202/* Activate a standard set of debugging hooks. */
203extern void cvmx__malloc_check_init __MALLOC_P ((void));
204
205/* Internal routines, operating on "arenas".  */
206struct malloc_state;
207typedef struct malloc_state *mstate;
208#ifdef __cplusplus
209}; /* end of extern "C" */
210#endif
211
212
213#endif /* malloc.h */
214