1/* Define INTERNAL_SIZE_T, SIZE_SZ, MALLOC_ALIGNMENT and MALLOC_ALIGN_MASK
2 for malloc.
3 Copyright (C) 2021-2024 Free Software Foundation, Inc.
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
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.
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
14 Lesser General Public License for more details.
15
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/>. */
19
20#ifndef _GENERIC_MALLOC_SIZE_H
21#define _GENERIC_MALLOC_SIZE_H
22
23/* INTERNAL_SIZE_T is the word-size used for internal bookkeeping of
24 chunk sizes.
25
26 The default version is the same as size_t.
27
28 While not strictly necessary, it is best to define this as an
29 unsigned type, even if size_t is a signed type. This may avoid some
30 artificial size limitations on some systems.
31
32 On a 64-bit machine, you may be able to reduce malloc overhead by
33 defining INTERNAL_SIZE_T to be a 32 bit `unsigned int' at the
34 expense of not being able to handle more than 2^32 of malloced
35 space. If this limitation is acceptable, you are encouraged to set
36 this unless you are on a platform requiring 16byte alignments. In
37 this case the alignment requirements turn out to negate any
38 potential advantages of decreasing size_t word size.
39
40 Implementors: Beware of the possible combinations of:
41 - INTERNAL_SIZE_T might be signed or unsigned, might be 32 or 64 bits,
42 and might be the same width as int or as long
43 - size_t might have different width and signedness as INTERNAL_SIZE_T
44 - int and long might be 32 or 64 bits, and might be the same width
45
46 To deal with this, most comparisons and difference computations
47 among INTERNAL_SIZE_Ts should cast them to unsigned long, being
48 aware of the fact that casting an unsigned int to a wider long does
49 not sign-extend. (This also makes checking for negative numbers
50 awkward.) Some of these casts result in harmless compiler warnings
51 on some systems. */
52#ifndef INTERNAL_SIZE_T
53# define INTERNAL_SIZE_T size_t
54#endif
55
56/* The corresponding word size. */
57#define SIZE_SZ (sizeof (INTERNAL_SIZE_T))
58
59#include <malloc-alignment.h>
60
61/* The corresponding bit mask value. */
62#define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1)
63
64#endif /* _GENERIC_MALLOC_SIZE_H */
65

source code of glibc/sysdeps/generic/malloc-size.h