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