]> sourceware.org Git - glibc.git/blob - malloc/malloc.h
Declare malloc hook variables as volatile.
[glibc.git] / malloc / malloc.h
1 /* Prototypes and definition for malloc implementation.
2 Copyright (C) 1996, 1997, 1999, 2000, 2002-2004, 2005, 2007, 2009, 2011
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #ifndef _MALLOC_H
22 #define _MALLOC_H 1
23
24 #include <features.h>
25 #include <stddef.h>
26 #include <stdio.h>
27 # define __malloc_ptr_t void *
28
29 /* Used by GNU libc internals. */
30 #define __malloc_size_t size_t
31 #define __malloc_ptrdiff_t ptrdiff_t
32
33 #ifdef __GNUC__
34
35 # define __MALLOC_P(args) args __THROW
36 /* This macro will be used for functions which might take C++ callback
37 functions. */
38 # define __MALLOC_PMT(args) args
39
40 # ifdef _LIBC
41 # define __MALLOC_HOOK_VOLATILE
42 # else
43 # define __MALLOC_HOOK_VOLATILE
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
52 #endif /* GCC. */
53
54
55 __BEGIN_DECLS
56
57 /* Allocate SIZE bytes of memory. */
58 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
59
60 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
61 extern void *calloc (size_t __nmemb, size_t __size)
62 __THROW __attribute_malloc__ __wur;
63
64 /* Re-allocate the previously allocated block in __ptr, making the new
65 block SIZE bytes long. */
66 /* __attribute_malloc__ is not used, because if realloc returns
67 the same pointer that was passed to it, aliasing needs to be allowed
68 between objects pointed by the old and new pointers. */
69 extern void *realloc (void *__ptr, size_t __size)
70 __THROW __attribute_warn_unused_result__;
71
72 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
73 extern void free (void *__ptr) __THROW;
74
75 /* Free a block allocated by `calloc'. */
76 extern void cfree (void *__ptr) __THROW;
77
78 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
79 extern void *memalign (size_t __alignment, size_t __size)
80 __THROW __attribute_malloc__ __wur;
81
82 /* Allocate SIZE bytes on a page boundary. */
83 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
84
85 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
86 __size to nearest pagesize. */
87 extern void * pvalloc (size_t __size) __THROW __attribute_malloc__ __wur;
88
89 /* Underlying allocation function; successive calls should return
90 contiguous pieces of memory. */
91 extern void *(*__morecore) (ptrdiff_t __size);
92
93 /* Default value of `__morecore'. */
94 extern void *__default_morecore (ptrdiff_t __size)
95 __THROW __attribute_malloc__;
96
97 /* SVID2/XPG mallinfo structure */
98
99 struct mallinfo
100 {
101 int arena; /* non-mmapped space allocated from system */
102 int ordblks; /* number of free chunks */
103 int smblks; /* number of fastbin blocks */
104 int hblks; /* number of mmapped regions */
105 int hblkhd; /* space in mmapped regions */
106 int usmblks; /* maximum total allocated space */
107 int fsmblks; /* space available in freed fastbin blocks */
108 int uordblks; /* total allocated space */
109 int fordblks; /* total free space */
110 int keepcost; /* top-most, releasable (via malloc_trim) space */
111 };
112
113 /* Returns a copy of the updated current mallinfo. */
114 extern struct mallinfo mallinfo (void) __THROW;
115
116 /* SVID2/XPG mallopt options */
117 #ifndef M_MXFAST
118 # define M_MXFAST 1 /* maximum request size for "fastbins" */
119 #endif
120 #ifndef M_NLBLKS
121 # define M_NLBLKS 2 /* UNUSED in this malloc */
122 #endif
123 #ifndef M_GRAIN
124 # define M_GRAIN 3 /* UNUSED in this malloc */
125 #endif
126 #ifndef M_KEEP
127 # define M_KEEP 4 /* UNUSED in this malloc */
128 #endif
129
130 /* mallopt options that actually do something */
131 #define M_TRIM_THRESHOLD -1
132 #define M_TOP_PAD -2
133 #define M_MMAP_THRESHOLD -3
134 #define M_MMAP_MAX -4
135 #define M_CHECK_ACTION -5
136 #define M_PERTURB -6
137 #define M_ARENA_TEST -7
138 #define M_ARENA_MAX -8
139
140 /* General SVID/XPG interface to tunable parameters. */
141 extern int mallopt (int __param, int __val) __THROW;
142
143 /* Release all but __pad bytes of freed top-most memory back to the
144 system. Return 1 if successful, else 0. */
145 extern int malloc_trim (size_t __pad) __THROW;
146
147 /* Report the number of usable allocated bytes associated with allocated
148 chunk __ptr. */
149 extern size_t malloc_usable_size (void *__ptr) __THROW;
150
151 /* Prints brief summary statistics on stderr. */
152 extern void malloc_stats (void) __THROW;
153
154 /* Output information about state of allocator to stream FP. */
155 extern int malloc_info (int __options, FILE *__fp) __THROW;
156
157 /* Record the state of all malloc variables in an opaque data structure. */
158 extern void *malloc_get_state (void) __THROW;
159
160 /* Restore the state of all malloc variables from data obtained with
161 malloc_get_state(). */
162 extern int malloc_set_state (void *__ptr) __THROW;
163
164 /* Called once when malloc is initialized; redefining this variable in
165 the application provides the preferred way to set up the hook
166 pointers. */
167 extern void (*__malloc_initialize_hook) (void);
168 /* Hooks for debugging and user-defined versions. */
169 extern void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *__ptr,
170 __const __malloc_ptr_t);
171 extern void *(*__MALLOC_HOOK_VOLATILE __malloc_hook) (size_t __size,
172 __const __malloc_ptr_t);
173 extern void *(*__MALLOC_HOOK_VOLATILE __realloc_hook) (void *__ptr,
174 size_t __size,
175 __const __malloc_ptr_t);
176 extern void *(*__MALLOC_HOOK_VOLATILE __memalign_hook) (size_t __alignment,
177 size_t __size,
178 __const __malloc_ptr_t);
179 extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
180
181 /* Activate a standard set of debugging hooks. */
182 extern void __malloc_check_init (void) __THROW;
183
184
185 __END_DECLS
186
187 #endif /* malloc.h */
This page took 0.046965 seconds and 6 git commands to generate.