Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / malloc / malloc.h
1 /* Prototypes and definition for malloc implementation.
2    Copyright (C) 1996-2013 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, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _MALLOC_H
20 #define _MALLOC_H 1
21
22 #include <features.h>
23 #include <stddef.h>
24 #include <stdio.h>
25 # define __malloc_ptr_t  void *
26
27 /* Used by GNU libc internals. */
28 #define __malloc_size_t size_t
29 #define __malloc_ptrdiff_t ptrdiff_t
30
31 #ifdef __GNUC__
32
33 # define __MALLOC_P(args)       args __THROW
34 /* This macro will be used for functions which might take C++ callback
35    functions.  */
36 # define __MALLOC_PMT(args)     args
37
38 # ifdef _LIBC
39 #  define __MALLOC_HOOK_VOLATILE
40 #  define __MALLOC_DEPRECATED
41 # else
42 #  define __MALLOC_HOOK_VOLATILE volatile
43 #  define __MALLOC_DEPRECATED __attribute_deprecated__
44 # endif
45
46 #else   /* Not GCC.  */
47
48 # define __MALLOC_P(args)       args
49 # define __MALLOC_PMT(args)     args
50 # define __MALLOC_HOOK_VOLATILE
51 # define __MALLOC_DEPRECATED __attribute_deprecated__
52
53 #endif  /* GCC.  */
54
55
56 __BEGIN_DECLS
57
58 /* Allocate SIZE bytes of memory.  */
59 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
60
61 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
62 extern void *calloc (size_t __nmemb, size_t __size)
63      __THROW __attribute_malloc__ __wur;
64
65 /* Re-allocate the previously allocated block in __ptr, making the new
66    block SIZE bytes long.  */
67 /* __attribute_malloc__ is not used, because if realloc returns
68    the same pointer that was passed to it, aliasing needs to be allowed
69    between objects pointed by the old and new pointers.  */
70 extern void *realloc (void *__ptr, size_t __size)
71      __THROW __attribute_warn_unused_result__;
72
73 /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
74 extern void free (void *__ptr) __THROW;
75
76 /* Free a block allocated by `calloc'. */
77 extern void cfree (void *__ptr) __THROW;
78
79 /* Allocate SIZE bytes allocated to ALIGNMENT bytes.  */
80 extern void *memalign (size_t __alignment, size_t __size)
81      __THROW __attribute_malloc__ __wur;
82
83 /* Allocate SIZE bytes on a page boundary.  */
84 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
85
86 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
87    __size to nearest pagesize. */
88 extern void * pvalloc (size_t __size) __THROW __attribute_malloc__ __wur;
89
90 /* Underlying allocation function; successive calls should return
91    contiguous pieces of memory.  */
92 extern void *(*__morecore) (ptrdiff_t __size);
93
94 /* Default value of `__morecore'.  */
95 extern void *__default_morecore (ptrdiff_t __size)
96      __THROW __attribute_malloc__;
97
98 /* SVID2/XPG mallinfo structure */
99
100 struct mallinfo
101 {
102   int arena;    /* non-mmapped space allocated from system */
103   int ordblks;  /* number of free chunks */
104   int smblks;   /* number of fastbin blocks */
105   int hblks;    /* number of mmapped regions */
106   int hblkhd;   /* space in mmapped regions */
107   int usmblks;  /* maximum total allocated space */
108   int fsmblks;  /* space available in freed fastbin blocks */
109   int uordblks; /* total allocated space */
110   int fordblks; /* total free space */
111   int keepcost; /* top-most, releasable (via malloc_trim) space */
112 };
113
114 /* Returns a copy of the updated current mallinfo. */
115 extern struct mallinfo mallinfo (void) __THROW;
116
117 /* SVID2/XPG mallopt options */
118 #ifndef M_MXFAST
119 # define M_MXFAST  1    /* maximum request size for "fastbins" */
120 #endif
121 #ifndef M_NLBLKS
122 # define M_NLBLKS  2    /* UNUSED in this malloc */
123 #endif
124 #ifndef M_GRAIN
125 # define M_GRAIN   3    /* UNUSED in this malloc */
126 #endif
127 #ifndef M_KEEP
128 # define M_KEEP    4    /* UNUSED in this malloc */
129 #endif
130
131 /* mallopt options that actually do something */
132 #define M_TRIM_THRESHOLD    -1
133 #define M_TOP_PAD           -2
134 #define M_MMAP_THRESHOLD    -3
135 #define M_MMAP_MAX          -4
136 #define M_CHECK_ACTION      -5
137 #define M_PERTURB           -6
138 #define M_ARENA_TEST        -7
139 #define M_ARENA_MAX         -8
140
141 /* General SVID/XPG interface to tunable parameters. */
142 extern int mallopt (int __param, int __val) __THROW;
143
144 /* Release all but __pad bytes of freed top-most memory back to the
145    system. Return 1 if successful, else 0. */
146 extern int malloc_trim (size_t __pad) __THROW;
147
148 /* Report the number of usable allocated bytes associated with allocated
149    chunk __ptr. */
150 extern size_t malloc_usable_size (void *__ptr) __THROW;
151
152 /* Prints brief summary statistics on stderr. */
153 extern void malloc_stats (void) __THROW;
154
155 /* Output information about state of allocator to stream FP.  */
156 extern int malloc_info (int __options, FILE *__fp) __THROW;
157
158 /* Record the state of all malloc variables in an opaque data structure. */
159 extern void *malloc_get_state (void) __THROW;
160
161 /* Restore the state of all malloc variables from data obtained with
162    malloc_get_state(). */
163 extern int malloc_set_state (void *__ptr) __THROW;
164
165 /* Called once when malloc is initialized; redefining this variable in
166    the application provides the preferred way to set up the hook
167    pointers. */
168 extern void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void)
169      __MALLOC_DEPRECATED;
170 /* Hooks for debugging and user-defined versions. */
171 extern void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *__ptr,
172                                                    const __malloc_ptr_t)
173      __MALLOC_DEPRECATED;
174 extern void *(*__MALLOC_HOOK_VOLATILE __malloc_hook) (size_t __size,
175                                                       const __malloc_ptr_t)
176      __MALLOC_DEPRECATED;
177 extern void *(*__MALLOC_HOOK_VOLATILE __realloc_hook) (void *__ptr,
178                                                        size_t __size,
179                                                        const __malloc_ptr_t)
180      __MALLOC_DEPRECATED;
181 extern void *(*__MALLOC_HOOK_VOLATILE __memalign_hook) (size_t __alignment,
182                                                         size_t __size,
183                                                         const __malloc_ptr_t)
184      __MALLOC_DEPRECATED;
185 extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
186
187 /* Activate a standard set of debugging hooks. */
188 extern void __malloc_check_init (void) __THROW __MALLOC_DEPRECATED;
189
190
191 __END_DECLS
192
193 #endif /* malloc.h */