]> git.ipfire.org Git - thirdparty/glibc.git/blame - malloc/malloc.h
* libio/iopopen.c (_IO_new_proc_open): Don't close child_std_end
[thirdparty/glibc.git] / malloc / malloc.h
CommitLineData
f65fd747 1/* Prototypes and definition for malloc implementation.
9ee4c017 2 Copyright (C) 1996,97,99,2000,2002-2004,2005 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
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
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>
dfd2257a 25# define __malloc_ptr_t void *
f65fd747 26
8a4b65b4 27/* Used by GNU libc internals. */
1b2ba891
UD
28#define __malloc_size_t size_t
29#define __malloc_ptrdiff_t ptrdiff_t
f65fd747 30
8aba992a
UD
31#ifdef __GNUC__
32
8aba992a
UD
33# define __MALLOC_P(args) args __THROW
34/* This macro will be used for functions which might take C++ callback
35 functions. */
36# define __MALLOC_PMT(args) args
37
38#else /* Not GCC. */
39
1b2ba891
UD
40# define __MALLOC_P(args) args
41# define __MALLOC_PMT(args) args
8aba992a
UD
42
43#endif /* GCC. */
f65fd747 44
f65fd747 45
1b2ba891 46__BEGIN_DECLS
f65fd747 47
f65fd747 48/* Allocate SIZE bytes of memory. */
1b2ba891 49extern void *malloc __MALLOC_P ((size_t __size)) __attribute_malloc__ __wur;
f65fd747
UD
50
51/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
1b2ba891 52extern void *calloc __MALLOC_P ((size_t __nmemb, size_t __size))
9ee4c017 53 __attribute_malloc__ __wur;
f65fd747
UD
54
55/* Re-allocate the previously allocated block in __ptr, making the new
56 block SIZE bytes long. */
1b2ba891 57extern void *realloc __MALLOC_P ((void *__ptr, size_t __size))
9ee4c017 58 __attribute_malloc__ __attribute_warn_unused_result__;
f65fd747
UD
59
60/* Free a block allocated by `malloc', `realloc' or `calloc'. */
1b2ba891 61extern void free __MALLOC_P ((void *__ptr));
f65fd747
UD
62
63/* Free a block allocated by `calloc'. */
1b2ba891 64extern void cfree __MALLOC_P ((void *__ptr));
f65fd747
UD
65
66/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
1b2ba891 67extern void *memalign __MALLOC_P ((size_t __alignment, size_t __size))
9ee4c017 68 __attribute_malloc__ __wur;
f65fd747
UD
69
70/* Allocate SIZE bytes on a page boundary. */
1b2ba891 71extern void *valloc __MALLOC_P ((size_t __size))
9ee4c017 72 __attribute_malloc__ __wur;
f65fd747
UD
73
74/* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
75 __size to nearest pagesize. */
1b2ba891 76extern void * pvalloc __MALLOC_P ((size_t __size))
9ee4c017 77 __attribute_malloc__ __wur;
f65fd747
UD
78
79/* Underlying allocation function; successive calls should return
80 contiguous pieces of memory. */
1b2ba891 81extern void *(*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
f65fd747
UD
82
83/* Default value of `__morecore'. */
1b2ba891 84extern void *__default_morecore __MALLOC_P ((ptrdiff_t __size))
e9e9b245 85 __attribute_malloc__;
f65fd747
UD
86
87/* SVID2/XPG mallinfo structure */
fa8d436c 88
f65fd747 89struct mallinfo {
fa8d436c
UD
90 int arena; /* non-mmapped space allocated from system */
91 int ordblks; /* number of free chunks */
92 int smblks; /* number of fastbin blocks */
f65fd747 93 int hblks; /* number of mmapped regions */
fa8d436c
UD
94 int hblkhd; /* space in mmapped regions */
95 int usmblks; /* maximum total allocated space */
96 int fsmblks; /* space available in freed fastbin blocks */
f65fd747 97 int uordblks; /* total allocated space */
fa8d436c 98 int fordblks; /* total free space */
f65fd747
UD
99 int keepcost; /* top-most, releasable (via malloc_trim) space */
100};
101
102/* Returns a copy of the updated current mallinfo. */
103extern struct mallinfo mallinfo __MALLOC_P ((void));
104
105/* SVID2/XPG mallopt options */
106#ifndef M_MXFAST
fa8d436c 107# define M_MXFAST 1 /* maximum request size for "fastbins" */
f65fd747
UD
108#endif
109#ifndef M_NLBLKS
dfd2257a 110# define M_NLBLKS 2 /* UNUSED in this malloc */
f65fd747
UD
111#endif
112#ifndef M_GRAIN
dfd2257a 113# define M_GRAIN 3 /* UNUSED in this malloc */
f65fd747
UD
114#endif
115#ifndef M_KEEP
dfd2257a 116# define M_KEEP 4 /* UNUSED in this malloc */
f65fd747
UD
117#endif
118
119/* mallopt options that actually do something */
120#define M_TRIM_THRESHOLD -1
121#define M_TOP_PAD -2
122#define M_MMAP_THRESHOLD -3
123#define M_MMAP_MAX -4
10dc2a90 124#define M_CHECK_ACTION -5
854278df 125#define M_PERTURB -6
f65fd747
UD
126
127/* General SVID/XPG interface to tunable parameters. */
128extern int mallopt __MALLOC_P ((int __param, int __val));
129
130/* Release all but __pad bytes of freed top-most memory back to the
131 system. Return 1 if successful, else 0. */
132extern int malloc_trim __MALLOC_P ((size_t __pad));
133
134/* Report the number of usable allocated bytes associated with allocated
135 chunk __ptr. */
1b2ba891 136extern size_t malloc_usable_size __MALLOC_P ((void *__ptr));
f65fd747
UD
137
138/* Prints brief summary statistics on stderr. */
139extern void malloc_stats __MALLOC_P ((void));
140
2f6d1f1b 141/* Record the state of all malloc variables in an opaque data structure. */
1b2ba891 142extern void *malloc_get_state __MALLOC_P ((void));
2f6d1f1b
UD
143
144/* Restore the state of all malloc variables from data obtained with
145 malloc_get_state(). */
1b2ba891 146extern int malloc_set_state __MALLOC_P ((void *__ptr));
2f6d1f1b 147
b2f46c3c
UD
148/* Called once when malloc is initialized; redefining this variable in
149 the application provides the preferred way to set up the hook
150 pointers. */
8aba992a 151extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
b2f46c3c 152/* Hooks for debugging and user-defined versions. */
1b2ba891 153extern void (*__free_hook) __MALLOC_PMT ((void *__ptr,
a2b08ee5 154 __const __malloc_ptr_t));
1b2ba891
UD
155extern void *(*__malloc_hook) __MALLOC_PMT ((size_t __size,
156 __const __malloc_ptr_t));
157extern void *(*__realloc_hook) __MALLOC_PMT ((void *__ptr, size_t __size,
158 __const __malloc_ptr_t));
159extern void *(*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
160 size_t __size,
161 __const __malloc_ptr_t));
8aba992a 162extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
10dc2a90 163
a2b08ee5
UD
164/* Activate a standard set of debugging hooks. */
165extern void __malloc_check_init __MALLOC_P ((void));
fa8d436c 166
10dc2a90 167
1b2ba891 168__END_DECLS
f65fd747 169
5107cf1d 170#endif /* malloc.h */