]> git.ipfire.org Git - thirdparty/glibc.git/blame - malloc/malloc.h
Fix http: URL in 'configure'
[thirdparty/glibc.git] / malloc / malloc.h
CommitLineData
f65fd747 1/* Prototypes and definition for malloc implementation.
04277e02 2 Copyright (C) 1996-2019 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 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://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. */
9bf8e29c
AZ
38extern void *malloc (size_t __size) __THROW __attribute_malloc__
39 __attribute_alloc_size__ ((1)) __wur;
f65fd747
UD
40
41/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
cf6bbbd7 42extern void *calloc (size_t __nmemb, size_t __size)
9bf8e29c 43__THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
f65fd747
UD
44
45/* Re-allocate the previously allocated block in __ptr, making the new
46 block SIZE bytes long. */
1c3e748e
UD
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. */
cf6bbbd7 50extern void *realloc (void *__ptr, size_t __size)
9bf8e29c 51__THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));
f65fd747 52
2e0bbbfb
DW
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)
9bf8e29c 59__THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2, 3));
2e0bbbfb 60
f65fd747 61/* Free a block allocated by `malloc', `realloc' or `calloc'. */
cf6bbbd7 62extern void free (void *__ptr) __THROW;
f65fd747 63
f65fd747 64/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
cf6bbbd7 65extern void *memalign (size_t __alignment, size_t __size)
9bf8e29c 66__THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
f65fd747
UD
67
68/* Allocate SIZE bytes on a page boundary. */
9bf8e29c
AZ
69extern void *valloc (size_t __size) __THROW __attribute_malloc__
70 __attribute_alloc_size__ ((1)) __wur;
f65fd747
UD
71
72/* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
73 __size to nearest pagesize. */
9bf8e29c
AZ
74extern void *pvalloc (size_t __size) __THROW __attribute_malloc__
75 __attribute_alloc_size__ ((1)) __wur;
f65fd747
UD
76
77/* Underlying allocation function; successive calls should return
78 contiguous pieces of memory. */
cf6bbbd7 79extern void *(*__morecore) (ptrdiff_t __size);
f65fd747
UD
80
81/* Default value of `__morecore'. */
cf6bbbd7 82extern void *__default_morecore (ptrdiff_t __size)
6c8dbf00 83__THROW __attribute_malloc__;
f65fd747
UD
84
85/* SVID2/XPG mallinfo structure */
fa8d436c 86
cf6bbbd7
UD
87struct mallinfo
88{
fa8d436c
UD
89 int arena; /* non-mmapped space allocated from system */
90 int ordblks; /* number of free chunks */
91 int smblks; /* number of fastbin blocks */
f65fd747 92 int hblks; /* number of mmapped regions */
fa8d436c 93 int hblkhd; /* space in mmapped regions */
ca135f82 94 int usmblks; /* always 0, preserved for backwards compatibility */
fa8d436c 95 int fsmblks; /* space available in freed fastbin blocks */
f65fd747 96 int uordblks; /* total allocated space */
fa8d436c 97 int fordblks; /* total free space */
f65fd747
UD
98 int keepcost; /* top-most, releasable (via malloc_trim) space */
99};
100
101/* Returns a copy of the updated current mallinfo. */
cf6bbbd7 102extern struct mallinfo mallinfo (void) __THROW;
f65fd747
UD
103
104/* SVID2/XPG mallopt options */
105#ifndef M_MXFAST
6c8dbf00 106# define M_MXFAST 1 /* maximum request size for "fastbins" */
f65fd747
UD
107#endif
108#ifndef M_NLBLKS
6c8dbf00 109# define M_NLBLKS 2 /* UNUSED in this malloc */
f65fd747
UD
110#endif
111#ifndef M_GRAIN
6c8dbf00 112# define M_GRAIN 3 /* UNUSED in this malloc */
f65fd747
UD
113#endif
114#ifndef M_KEEP
6c8dbf00 115# define M_KEEP 4 /* UNUSED in this malloc */
f65fd747
UD
116#endif
117
118/* mallopt options that actually do something */
119#define M_TRIM_THRESHOLD -1
120#define M_TOP_PAD -2
121#define M_MMAP_THRESHOLD -3
122#define M_MMAP_MAX -4
10dc2a90 123#define M_CHECK_ACTION -5
6c8dbf00
OB
124#define M_PERTURB -6
125#define M_ARENA_TEST -7
126#define M_ARENA_MAX -8
f65fd747
UD
127
128/* General SVID/XPG interface to tunable parameters. */
cf6bbbd7 129extern int mallopt (int __param, int __val) __THROW;
f65fd747
UD
130
131/* Release all but __pad bytes of freed top-most memory back to the
132 system. Return 1 if successful, else 0. */
cf6bbbd7 133extern int malloc_trim (size_t __pad) __THROW;
f65fd747
UD
134
135/* Report the number of usable allocated bytes associated with allocated
136 chunk __ptr. */
cf6bbbd7 137extern size_t malloc_usable_size (void *__ptr) __THROW;
f65fd747
UD
138
139/* Prints brief summary statistics on stderr. */
cf6bbbd7 140extern void malloc_stats (void) __THROW;
f65fd747 141
bb066545 142/* Output information about state of allocator to stream FP. */
cf6bbbd7 143extern int malloc_info (int __options, FILE *__fp) __THROW;
bb066545 144
b2f46c3c 145/* Hooks for debugging and user-defined versions. */
cf6bbbd7 146extern void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *__ptr,
6c8dbf00
OB
147 const void *)
148__MALLOC_DEPRECATED;
149extern void *(*__MALLOC_HOOK_VOLATILE __malloc_hook)(size_t __size,
150 const void *)
151__MALLOC_DEPRECATED;
152extern void *(*__MALLOC_HOOK_VOLATILE __realloc_hook)(void *__ptr,
153 size_t __size,
154 const void *)
155__MALLOC_DEPRECATED;
156extern void *(*__MALLOC_HOOK_VOLATILE __memalign_hook)(size_t __alignment,
157 size_t __size,
158 const void *)
159__MALLOC_DEPRECATED;
cf6bbbd7 160extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
10dc2a90 161
10dc2a90 162
1b2ba891 163__END_DECLS
5107cf1d 164#endif /* malloc.h */