]> git.ipfire.org Git - thirdparty/glibc.git/blame - malloc/malloc.h
contrib.texi: update
[thirdparty/glibc.git] / malloc / malloc.h
CommitLineData
f65fd747 1/* Prototypes and definition for malloc implementation.
dff8da6b 2 Copyright (C) 1996-2024 Free Software Foundation, Inc.
8a9a5931 3 Copyright The GNU Toolchain Authors.
f65fd747
UD
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
f65fd747
UD
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 14 Lesser General Public License for more details.
f65fd747 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6 17 License along with the GNU C Library; if not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
f65fd747
UD
19
20#ifndef _MALLOC_H
8a4b65b4 21#define _MALLOC_H 1
f65fd747 22
4360eafd 23#include <features.h>
1b2ba891 24#include <stddef.h>
bb066545 25#include <stdio.h>
f65fd747 26
375607b9 27#ifdef _LIBC
cf6bbbd7 28# define __MALLOC_HOOK_VOLATILE
375607b9
JM
29# define __MALLOC_DEPRECATED
30#else
31# define __MALLOC_HOOK_VOLATILE volatile
7d17596c 32# define __MALLOC_DEPRECATED __attribute_deprecated__
375607b9 33#endif
f65fd747 34
f65fd747 35
1b2ba891 36__BEGIN_DECLS
f65fd747 37
f65fd747 38/* Allocate SIZE bytes of memory. */
9bf8e29c
AZ
39extern void *malloc (size_t __size) __THROW __attribute_malloc__
40 __attribute_alloc_size__ ((1)) __wur;
f65fd747
UD
41
42/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
cf6bbbd7 43extern void *calloc (size_t __nmemb, size_t __size)
9bf8e29c 44__THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
f65fd747
UD
45
46/* Re-allocate the previously allocated block in __ptr, making the new
47 block SIZE bytes long. */
1c3e748e
UD
48/* __attribute_malloc__ is not used, because if realloc returns
49 the same pointer that was passed to it, aliasing needs to be allowed
50 between objects pointed by the old and new pointers. */
cf6bbbd7 51extern void *realloc (void *__ptr, size_t __size)
9bf8e29c 52__THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));
f65fd747 53
2e0bbbfb
DW
54/* Re-allocate the previously allocated block in PTR, making the new
55 block large enough for NMEMB elements of SIZE bytes each. */
56/* __attribute_malloc__ is not used, because if reallocarray returns
57 the same pointer that was passed to it, aliasing needs to be allowed
58 between objects pointed by the old and new pointers. */
59extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
c1760eaf
MS
60 __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2, 3))
61 __attr_dealloc_free;
2e0bbbfb 62
f65fd747 63/* Free a block allocated by `malloc', `realloc' or `calloc'. */
cf6bbbd7 64extern void free (void *__ptr) __THROW;
f65fd747 65
f65fd747 66/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
cf6bbbd7 67extern void *memalign (size_t __alignment, size_t __size)
8a9a5931
JW
68 __THROW __attribute_malloc__ __attribute_alloc_align__ ((1))
69 __attribute_alloc_size__ ((2)) __wur __attr_dealloc_free;
f65fd747
UD
70
71/* Allocate SIZE bytes on a page boundary. */
9bf8e29c 72extern void *valloc (size_t __size) __THROW __attribute_malloc__
c1760eaf 73 __attribute_alloc_size__ ((1)) __wur __attr_dealloc_free;
f65fd747
UD
74
75/* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
76 __size to nearest pagesize. */
c1760eaf
MS
77extern void *pvalloc (size_t __size) __THROW __attribute_malloc__
78 __wur __attr_dealloc_free;
f65fd747 79
f65fd747 80/* SVID2/XPG mallinfo structure */
fa8d436c 81
cf6bbbd7
UD
82struct mallinfo
83{
fa8d436c
UD
84 int arena; /* non-mmapped space allocated from system */
85 int ordblks; /* number of free chunks */
86 int smblks; /* number of fastbin blocks */
f65fd747 87 int hblks; /* number of mmapped regions */
fa8d436c 88 int hblkhd; /* space in mmapped regions */
ca135f82 89 int usmblks; /* always 0, preserved for backwards compatibility */
fa8d436c 90 int fsmblks; /* space available in freed fastbin blocks */
f65fd747 91 int uordblks; /* total allocated space */
fa8d436c 92 int fordblks; /* total free space */
f65fd747
UD
93 int keepcost; /* top-most, releasable (via malloc_trim) space */
94};
95
e3960d1c
ML
96/* SVID2/XPG mallinfo2 structure which can handle allocations
97 bigger than 4GB. */
98
99struct mallinfo2
100{
101 size_t arena; /* non-mmapped space allocated from system */
102 size_t ordblks; /* number of free chunks */
103 size_t smblks; /* number of fastbin blocks */
104 size_t hblks; /* number of mmapped regions */
105 size_t hblkhd; /* space in mmapped regions */
106 size_t usmblks; /* always 0, preserved for backwards compatibility */
107 size_t fsmblks; /* space available in freed fastbin blocks */
108 size_t uordblks; /* total allocated space */
109 size_t fordblks; /* total free space */
110 size_t keepcost; /* top-most, releasable (via malloc_trim) space */
111};
112
f65fd747 113/* Returns a copy of the updated current mallinfo. */
30e5069c 114extern struct mallinfo mallinfo (void) __THROW __MALLOC_DEPRECATED;
f65fd747 115
e3960d1c
ML
116/* Returns a copy of the updated current mallinfo. */
117extern struct mallinfo2 mallinfo2 (void) __THROW;
118
f65fd747
UD
119/* SVID2/XPG mallopt options */
120#ifndef M_MXFAST
6c8dbf00 121# define M_MXFAST 1 /* maximum request size for "fastbins" */
f65fd747
UD
122#endif
123#ifndef M_NLBLKS
6c8dbf00 124# define M_NLBLKS 2 /* UNUSED in this malloc */
f65fd747
UD
125#endif
126#ifndef M_GRAIN
6c8dbf00 127# define M_GRAIN 3 /* UNUSED in this malloc */
f65fd747
UD
128#endif
129#ifndef M_KEEP
6c8dbf00 130# define M_KEEP 4 /* UNUSED in this malloc */
f65fd747
UD
131#endif
132
133/* mallopt options that actually do something */
134#define M_TRIM_THRESHOLD -1
135#define M_TOP_PAD -2
136#define M_MMAP_THRESHOLD -3
137#define M_MMAP_MAX -4
10dc2a90 138#define M_CHECK_ACTION -5
6c8dbf00
OB
139#define M_PERTURB -6
140#define M_ARENA_TEST -7
141#define M_ARENA_MAX -8
f65fd747
UD
142
143/* General SVID/XPG interface to tunable parameters. */
cf6bbbd7 144extern int mallopt (int __param, int __val) __THROW;
f65fd747
UD
145
146/* Release all but __pad bytes of freed top-most memory back to the
147 system. Return 1 if successful, else 0. */
cf6bbbd7 148extern int malloc_trim (size_t __pad) __THROW;
f65fd747
UD
149
150/* Report the number of usable allocated bytes associated with allocated
151 chunk __ptr. */
cf6bbbd7 152extern size_t malloc_usable_size (void *__ptr) __THROW;
f65fd747
UD
153
154/* Prints brief summary statistics on stderr. */
cf6bbbd7 155extern void malloc_stats (void) __THROW;
f65fd747 156
bb066545 157/* Output information about state of allocator to stream FP. */
cf6bbbd7 158extern int malloc_info (int __options, FILE *__fp) __THROW;
bb066545 159
1b2ba891 160__END_DECLS
5107cf1d 161#endif /* malloc.h */