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