update from main archive 970225
[platform/upstream/glibc.git] / malloc / malloc.h
1 /* Prototypes and definition for malloc implementation.
2    Copyright (C) 1996, 1997 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 Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    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    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20 #ifndef _MALLOC_H
21 #define _MALLOC_H 1
22
23 /*
24   `ptmalloc', a malloc implementation for multiple threads without
25   lock contention, by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>.
26   See the files `ptmalloc.c' or `COPYRIGHT' for copying conditions.
27
28   VERSION 2.6.4-pt Wed Dec  4 00:35:54 MET 1996
29
30   This work is mainly derived from malloc-2.6.4 by Doug Lea
31   <dl@cs.oswego.edu>, which is available from:
32
33                  ftp://g.oswego.edu/pub/misc/malloc.c
34
35   This trimmed-down header file only provides function prototypes and
36   the exported data structures.  For more detailed function
37   descriptions and compile-time options, see the source file
38   `ptmalloc.c'.
39 */
40
41 #if defined(__STDC__) || defined (__cplusplus)
42 #include <stddef.h>
43 #define __malloc_ptr_t  void *
44 #else
45 #undef  size_t
46 #define size_t          unsigned int
47 #undef  ptrdiff_t
48 #define ptrdiff_t       int
49 #define __malloc_ptr_t  char *
50 #endif
51
52 #ifdef _LIBC
53 /* Used by GNU libc internals. */
54 #define __malloc_size_t size_t
55 #define __malloc_ptrdiff_t ptrdiff_t
56 #endif
57
58 #if defined (__STDC__) || defined (__cplusplus) || defined (__GNUC__)
59 #define __MALLOC_P(args)        args
60 #else
61 #define __MALLOC_P(args)        ()
62 #endif
63
64 #ifndef NULL
65 #ifdef __cplusplus
66 #define NULL    0
67 #else
68 #define NULL    ((__malloc_ptr_t) 0)
69 #endif
70 #endif
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
76 /* Nonzero if the malloc is already initialized.  */
77 #ifdef _LIBC
78 /* In the GNU libc we rename the global variable
79    `__malloc_initialized' to `__libc_malloc_initialized'.  */
80 #define __malloc_initialized __libc_malloc_initialized
81 #endif
82 extern int __malloc_initialized;
83
84 /* Initialize global configuration.  Not needed with GNU libc. */
85 #ifndef __GLIBC__
86 extern void ptmalloc_init __MALLOC_P ((void));
87 #endif
88
89 /* Allocate SIZE bytes of memory.  */
90 extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size));
91
92 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
93 extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size));
94
95 /* Re-allocate the previously allocated block in __ptr, making the new
96    block SIZE bytes long.  */
97 extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr, size_t __size));
98
99 /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
100 extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
101
102 /* Free a block allocated by `calloc'. */
103 extern void cfree __MALLOC_P ((__malloc_ptr_t __ptr));
104
105 /* Allocate SIZE bytes allocated to ALIGNMENT bytes.  */
106 extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
107
108 /* Allocate SIZE bytes on a page boundary.  */
109 extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size));
110
111 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
112    __size to nearest pagesize. */
113 extern __malloc_ptr_t  pvalloc __MALLOC_P ((size_t __size));
114
115 /* Underlying allocation function; successive calls should return
116    contiguous pieces of memory.  */
117 extern __malloc_ptr_t (*__morecore) __MALLOC_P ((ptrdiff_t __size));
118
119 /* Default value of `__morecore'.  */
120 extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size));
121
122 /* SVID2/XPG mallinfo structure */
123 struct mallinfo {
124   int arena;    /* total space allocated from system */
125   int ordblks;  /* number of non-inuse chunks */
126   int smblks;   /* unused -- always zero */
127   int hblks;    /* number of mmapped regions */
128   int hblkhd;   /* total space in mmapped regions */
129   int usmblks;  /* unused -- always zero */
130   int fsmblks;  /* unused -- always zero */
131   int uordblks; /* total allocated space */
132   int fordblks; /* total non-inuse space */
133   int keepcost; /* top-most, releasable (via malloc_trim) space */
134 };
135
136 /* Returns a copy of the updated current mallinfo. */
137 extern struct mallinfo mallinfo __MALLOC_P ((void));
138
139 /* SVID2/XPG mallopt options */
140 #ifndef M_MXFAST
141 #define M_MXFAST  1    /* UNUSED in this malloc */
142 #endif
143 #ifndef M_NLBLKS
144 #define M_NLBLKS  2    /* UNUSED in this malloc */
145 #endif
146 #ifndef M_GRAIN
147 #define M_GRAIN   3    /* UNUSED in this malloc */
148 #endif
149 #ifndef M_KEEP
150 #define M_KEEP    4    /* UNUSED in this malloc */
151 #endif
152
153 /* mallopt options that actually do something */
154 #define M_TRIM_THRESHOLD    -1
155 #define M_TOP_PAD           -2
156 #define M_MMAP_THRESHOLD    -3
157 #define M_MMAP_MAX          -4
158 #define M_CHECK_ACTION      -5
159
160 /* General SVID/XPG interface to tunable parameters. */
161 extern int mallopt __MALLOC_P ((int __param, int __val));
162
163 /* Release all but __pad bytes of freed top-most memory back to the
164    system. Return 1 if successful, else 0. */
165 extern int malloc_trim __MALLOC_P ((size_t __pad));
166
167 /* Report the number of usable allocated bytes associated with allocated
168    chunk __ptr. */
169 extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
170
171 /* Prints brief summary statistics on stderr. */
172 extern void malloc_stats __MALLOC_P ((void));
173
174 /* Record the state of all malloc variables in an opaque data structure. */
175 extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
176
177 /* Restore the state of all malloc variables from data obtained with
178    malloc_get_state(). */
179 extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
180
181 #if defined(__GLIBC__) || defined(MALLOC_HOOKS)
182
183 /* Hooks for debugging versions. */
184 extern void (*__malloc_initialize_hook) __MALLOC_P ((void));
185 extern void (*__free_hook) __MALLOC_P ((__malloc_ptr_t __ptr));
186 extern __malloc_ptr_t (*__malloc_hook) __MALLOC_P ((size_t __size));
187 extern __malloc_ptr_t (*__realloc_hook) __MALLOC_P ((__malloc_ptr_t __ptr,
188                                                      size_t __size));
189 extern __malloc_ptr_t (*__memalign_hook) __MALLOC_P ((size_t __size,
190                                                       size_t __alignment));
191 extern void (*__after_morecore_hook) __MALLOC_P ((void));
192
193 /* Activate a standard set of debugging hooks. */
194 extern void __malloc_check_init __MALLOC_P ((void));
195
196 #endif
197
198 #ifdef __cplusplus
199 }; /* end of extern "C" */
200 #endif
201
202 #endif /* !defined(_MALLOC_H) */