1 |
2 |
drasko |
/* Prototypes and definition for malloc implementation.
|
2 |
|
|
Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
|
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
|
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.
|
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
|
13 |
|
|
Lesser General Public License for more details.
|
14 |
|
|
|
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. */
|
19 |
|
|
|
20 |
|
|
#ifndef _MALLOC_H
|
21 |
|
|
#define _MALLOC_H 1
|
22 |
|
|
|
23 |
|
|
#include <features.h>
|
24 |
|
|
|
25 |
|
|
/*
|
26 |
|
|
`ptmalloc', a malloc implementation for multiple threads without
|
27 |
|
|
lock contention, by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>.
|
28 |
|
|
See the files `ptmalloc.c' or `COPYRIGHT' for copying conditions.
|
29 |
|
|
|
30 |
|
|
VERSION 2.6.4-pt Wed Dec 4 00:35:54 MET 1996
|
31 |
|
|
|
32 |
|
|
This work is mainly derived from malloc-2.6.4 by Doug Lea
|
33 |
|
|
<dl@cs.oswego.edu>, which is available from:
|
34 |
|
|
|
35 |
|
|
ftp://g.oswego.edu/pub/misc/malloc.c
|
36 |
|
|
|
37 |
|
|
This trimmed-down header file only provides function prototypes and
|
38 |
|
|
the exported data structures. For more detailed function
|
39 |
|
|
descriptions and compile-time options, see the source file
|
40 |
|
|
`ptmalloc.c'.
|
41 |
|
|
*/
|
42 |
|
|
|
43 |
|
|
#if defined(__STDC__) || defined (__cplusplus)
|
44 |
|
|
# include <stddef.h>
|
45 |
|
|
# define __malloc_ptr_t void *
|
46 |
|
|
#else
|
47 |
|
|
# undef size_t
|
48 |
|
|
# define size_t unsigned int
|
49 |
|
|
# undef ptrdiff_t
|
50 |
|
|
# define ptrdiff_t int
|
51 |
|
|
# define __malloc_ptr_t char *
|
52 |
|
|
#endif
|
53 |
|
|
|
54 |
|
|
#ifdef _LIBC
|
55 |
|
|
/* Used by GNU libc internals. */
|
56 |
|
|
# define __malloc_size_t size_t
|
57 |
|
|
# define __malloc_ptrdiff_t ptrdiff_t
|
58 |
|
|
#elif !defined __attribute_malloc__
|
59 |
|
|
# define __attribute_malloc__
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
#ifdef __GNUC__
|
63 |
|
|
|
64 |
|
|
/* GCC can always grok prototypes. For C++ programs we add throw()
|
65 |
|
|
to help it optimize the function calls. But this works only with
|
66 |
|
|
gcc 2.8.x and egcs. */
|
67 |
|
|
#ifndef __THROW
|
68 |
|
|
# if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
|
69 |
|
|
# define __THROW throw ()
|
70 |
|
|
# else
|
71 |
|
|
# define __THROW
|
72 |
|
|
# endif
|
73 |
|
|
#endif
|
74 |
|
|
# define __MALLOC_P(args) args __THROW
|
75 |
|
|
/* This macro will be used for functions which might take C++ callback
|
76 |
|
|
functions. */
|
77 |
|
|
# define __MALLOC_PMT(args) args
|
78 |
|
|
|
79 |
|
|
#else /* Not GCC. */
|
80 |
|
|
|
81 |
|
|
# define __THROW
|
82 |
|
|
|
83 |
|
|
# if (defined __STDC__ && __STDC__) || defined __cplusplus
|
84 |
|
|
|
85 |
|
|
# define __MALLOC_P(args) args
|
86 |
|
|
# define __MALLOC_PMT(args) args
|
87 |
|
|
|
88 |
|
|
# else /* Not ANSI C or C++. */
|
89 |
|
|
|
90 |
|
|
# define __MALLOC_P(args) () /* No prototypes. */
|
91 |
|
|
# define __MALLOC_PMT(args) ()
|
92 |
|
|
|
93 |
|
|
# endif /* ANSI C or C++. */
|
94 |
|
|
|
95 |
|
|
#endif /* GCC. */
|
96 |
|
|
|
97 |
|
|
#ifndef NULL
|
98 |
|
|
# ifdef __cplusplus
|
99 |
|
|
# define NULL 0
|
100 |
|
|
# else
|
101 |
|
|
# define NULL ((__malloc_ptr_t) 0)
|
102 |
|
|
# endif
|
103 |
|
|
#endif
|
104 |
|
|
|
105 |
|
|
#ifdef __cplusplus
|
106 |
|
|
extern "C" {
|
107 |
|
|
#endif
|
108 |
|
|
|
109 |
|
|
/* Allocate SIZE bytes of memory. */
|
110 |
|
|
extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
|
111 |
|
|
|
112 |
|
|
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
|
113 |
|
|
extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
|
114 |
|
|
__attribute_malloc__;
|
115 |
|
|
|
116 |
|
|
/* Re-allocate the previously allocated block in __ptr, making the new
|
117 |
|
|
block SIZE bytes long. */
|
118 |
|
|
extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
|
119 |
|
|
size_t __size))
|
120 |
|
|
__attribute_malloc__;
|
121 |
|
|
|
122 |
|
|
/* Free a block allocated by `malloc', `realloc' or `calloc'. */
|
123 |
|
|
extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
|
124 |
|
|
|
125 |
|
|
/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
|
126 |
|
|
extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
|
127 |
|
|
|
128 |
|
|
/* Allocate SIZE bytes on a page boundary. */
|
129 |
|
|
extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
|
130 |
|
|
|
131 |
|
|
#ifdef __MALLOC_STANDARD__
|
132 |
|
|
|
133 |
|
|
/* SVID2/XPG mallinfo structure */
|
134 |
|
|
struct mallinfo {
|
135 |
|
|
int arena; /* total space allocated from system */
|
136 |
|
|
int ordblks; /* number of non-inuse chunks */
|
137 |
|
|
int smblks; /* unused -- always zero */
|
138 |
|
|
int hblks; /* number of mmapped regions */
|
139 |
|
|
int hblkhd; /* total space in mmapped regions */
|
140 |
|
|
int usmblks; /* unused -- always zero */
|
141 |
|
|
int fsmblks; /* unused -- always zero */
|
142 |
|
|
int uordblks; /* total allocated space */
|
143 |
|
|
int fordblks; /* total non-inuse space */
|
144 |
|
|
int keepcost; /* top-most, releasable (via malloc_trim) space */
|
145 |
|
|
};
|
146 |
|
|
|
147 |
|
|
/* Returns a copy of the updated current mallinfo. */
|
148 |
|
|
extern struct mallinfo mallinfo __MALLOC_P ((void));
|
149 |
|
|
|
150 |
|
|
/* Release all but __pad bytes of freed top-most memory back to the
|
151 |
|
|
system. Return 1 if successful, else 0. */
|
152 |
|
|
extern int malloc_trim(size_t pad);
|
153 |
|
|
|
154 |
|
|
#include <stdio.h>
|
155 |
|
|
/* Prints brief summary statistics to the specified file.
|
156 |
|
|
* Writes to stderr if file is NULL. */
|
157 |
|
|
extern void malloc_stats(FILE *file);
|
158 |
|
|
|
159 |
|
|
/* SVID2/XPG mallopt options */
|
160 |
|
|
#ifndef M_MXFAST
|
161 |
|
|
# define M_MXFAST 1 /* UNUSED in this malloc */
|
162 |
|
|
#endif
|
163 |
|
|
#ifndef M_NLBLKS
|
164 |
|
|
# define M_NLBLKS 2 /* UNUSED in this malloc */
|
165 |
|
|
#endif
|
166 |
|
|
#ifndef M_GRAIN
|
167 |
|
|
# define M_GRAIN 3 /* UNUSED in this malloc */
|
168 |
|
|
#endif
|
169 |
|
|
#ifndef M_KEEP
|
170 |
|
|
# define M_KEEP 4 /* UNUSED in this malloc */
|
171 |
|
|
#endif
|
172 |
|
|
|
173 |
|
|
/* mallopt options that actually do something */
|
174 |
|
|
#define M_TRIM_THRESHOLD -1
|
175 |
|
|
#define M_TOP_PAD -2
|
176 |
|
|
#define M_MMAP_THRESHOLD -3
|
177 |
|
|
#define M_MMAP_MAX -4
|
178 |
|
|
#define M_CHECK_ACTION -5
|
179 |
|
|
#define M_PERTURB -6
|
180 |
|
|
|
181 |
|
|
/* General SVID/XPG interface to tunable parameters. */
|
182 |
|
|
extern int mallopt __MALLOC_P ((int __param, int __val));
|
183 |
|
|
|
184 |
|
|
#endif /* __MALLOC_STANDARD__ */
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
#ifdef __cplusplus
|
188 |
|
|
} /* end of extern "C" */
|
189 |
|
|
#endif
|
190 |
|
|
|
191 |
|
|
#endif /* malloc.h */
|