OSDN Git Service

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