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