1 /* Prototypes and definition for malloc implementation.
2 Copyright (C) 1996-2023 Free Software Foundation, Inc.
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
28 # define __MALLOC_HOOK_VOLATILE
29 # define __MALLOC_DEPRECATED
31 # define __MALLOC_HOOK_VOLATILE volatile
32 # define __MALLOC_DEPRECATED __attribute_deprecated__
38 /* Allocate SIZE bytes of memory. */
39 extern void *malloc (size_t __size
) __THROW __attribute_malloc__
40 __attribute_alloc_size__ ((1)) __wur
;
42 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
43 extern void *calloc (size_t __nmemb
, size_t __size
)
44 __THROW __attribute_malloc__
__attribute_alloc_size__ ((1, 2)) __wur
;
46 /* Re-allocate the previously allocated block in __ptr, making the new
47 block SIZE bytes long. */
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. */
51 extern void *realloc (void *__ptr
, size_t __size
)
52 __THROW __attribute_warn_unused_result__
__attribute_alloc_size__ ((2));
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. */
59 extern void *reallocarray (void *__ptr
, size_t __nmemb
, size_t __size
)
60 __THROW __attribute_warn_unused_result__
__attribute_alloc_size__ ((2, 3))
63 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
64 extern void free (void *__ptr
) __THROW
;
66 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
67 extern void *memalign (size_t __alignment
, size_t __size
)
68 __THROW __attribute_malloc__
__attribute_alloc_align__ ((1))
69 __attribute_alloc_size__ ((2)) __wur __attr_dealloc_free
;
71 /* Allocate SIZE bytes on a page boundary. */
72 extern void *valloc (size_t __size
) __THROW __attribute_malloc__
73 __attribute_alloc_size__ ((1)) __wur __attr_dealloc_free
;
75 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
76 __size to nearest pagesize. */
77 extern void *pvalloc (size_t __size
) __THROW __attribute_malloc__
78 __wur __attr_dealloc_free
;
80 /* SVID2/XPG mallinfo structure */
84 int arena
; /* non-mmapped space allocated from system */
85 int ordblks
; /* number of free chunks */
86 int smblks
; /* number of fastbin blocks */
87 int hblks
; /* number of mmapped regions */
88 int hblkhd
; /* space in mmapped regions */
89 int usmblks
; /* always 0, preserved for backwards compatibility */
90 int fsmblks
; /* space available in freed fastbin blocks */
91 int uordblks
; /* total allocated space */
92 int fordblks
; /* total free space */
93 int keepcost
; /* top-most, releasable (via malloc_trim) space */
96 /* SVID2/XPG mallinfo2 structure which can handle allocations
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 */
113 /* Returns a copy of the updated current mallinfo. */
114 extern struct mallinfo
mallinfo (void) __THROW __MALLOC_DEPRECATED
;
116 /* Returns a copy of the updated current mallinfo. */
117 extern struct mallinfo2
mallinfo2 (void) __THROW
;
119 /* SVID2/XPG mallopt options */
121 # define M_MXFAST 1 /* maximum request size for "fastbins" */
124 # define M_NLBLKS 2 /* UNUSED in this malloc */
127 # define M_GRAIN 3 /* UNUSED in this malloc */
130 # define M_KEEP 4 /* UNUSED in this malloc */
133 /* mallopt options that actually do something */
134 #define M_TRIM_THRESHOLD -1
136 #define M_MMAP_THRESHOLD -3
137 #define M_MMAP_MAX -4
138 #define M_CHECK_ACTION -5
140 #define M_ARENA_TEST -7
141 #define M_ARENA_MAX -8
143 /* General SVID/XPG interface to tunable parameters. */
144 extern int mallopt (int __param
, int __val
) __THROW
;
146 /* Release all but __pad bytes of freed top-most memory back to the
147 system. Return 1 if successful, else 0. */
148 extern int malloc_trim (size_t __pad
) __THROW
;
150 /* Report the number of usable allocated bytes associated with allocated
152 extern size_t malloc_usable_size (void *__ptr
) __THROW
;
154 /* Prints brief summary statistics on stderr. */
155 extern void malloc_stats (void) __THROW
;
157 /* Output information about state of allocator to stream FP. */
158 extern int malloc_info (int __options
, FILE *__fp
) __THROW
;
161 #endif /* malloc.h */