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