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