diff options
author | tholo <> | 1996-09-26 04:19:42 +0000 |
---|---|---|
committer | tholo <> | 1996-09-26 04:19:42 +0000 |
commit | 40954213683da2af94f45d9b0f35806b54e5e306 (patch) | |
tree | 4d52bb67398acd4227bd70258a69403ba2acf910 /src/lib/libc/stdlib/malloc.3 | |
parent | 7bfb6e73ddb58269b8ec906a008d5999e1b70abf (diff) | |
download | openbsd-40954213683da2af94f45d9b0f35806b54e5e306.tar.gz openbsd-40954213683da2af94f45d9b0f35806b54e5e306.tar.bz2 openbsd-40954213683da2af94f45d9b0f35806b54e5e306.zip |
Latest changes from FreeBSD
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
-rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 118 |
1 files changed, 110 insertions, 8 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index 979e77016d..e206245cc2 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
@@ -33,11 +33,11 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" $OpenBSD: malloc.3,v 1.3 1996/08/21 03:12:18 downsj Exp $ | 36 | .\" $OpenBSD: malloc.3,v 1.4 1996/09/26 04:19:41 tholo Exp $ |
37 | .\" | 37 | .\" |
38 | .Dd June 4, 1993 | 38 | .Dd August 27, 1996 |
39 | .Dt MALLOC 3 | 39 | .Dt MALLOC 3 |
40 | .Os BSD 4 | 40 | .Os OpenBSD |
41 | .Sh NAME | 41 | .Sh NAME |
42 | .Nm malloc , | 42 | .Nm malloc , |
43 | .Nd general memory allocation function | 43 | .Nd general memory allocation function |
@@ -58,6 +58,8 @@ | |||
58 | .Fn cfree "void *ptr" | 58 | .Fn cfree "void *ptr" |
59 | .Ft void * | 59 | .Ft void * |
60 | .Fn realloc "void *ptr" "size_t size" | 60 | .Fn realloc "void *ptr" "size_t size" |
61 | .Ft char * | ||
62 | .Va malloc_options | ||
61 | .Sh DESCRIPTION | 63 | .Sh DESCRIPTION |
62 | The | 64 | The |
63 | .Fn malloc | 65 | .Fn malloc |
@@ -120,11 +122,13 @@ is zero and | |||
120 | .Fa ptr | 122 | .Fa ptr |
121 | is not a null pointer, the object it points to is freed. | 123 | is not a null pointer, the object it points to is freed. |
122 | .Pp | 124 | .Pp |
123 | 125 | Malloc will first look for a symbolic link called | |
124 | .Sh ENVIRONMENT | 126 | .Pa /etc/malloc.conf |
125 | This malloc will check the environment for a variable called | 127 | and next check the environment for a variable called |
126 | .Em MALLOC_OPTIONS | 128 | .Ev MALLOC_OPTIONS |
127 | and scan it for flags. | 129 | and finally for the global variable |
130 | .Va malloc_options | ||
131 | and scan them for flags in that order. | ||
128 | Flags are single letters, uppercase means on, lowercase means off. | 132 | Flags are single letters, uppercase means on, lowercase means off. |
129 | .Bl -tag -width indent | 133 | .Bl -tag -width indent |
130 | .It A | 134 | .It A |
@@ -142,21 +146,42 @@ order to have any effect. | |||
142 | ``junk'' fill some junk into the area allocated. | 146 | ``junk'' fill some junk into the area allocated. |
143 | Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-) | 147 | Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-) |
144 | 148 | ||
149 | .It H | ||
150 | ``hint'' pass a hint to the kernel about pages we don't use. If the | ||
151 | machine is paging a lot this may help a bit. | ||
152 | |||
145 | .It R | 153 | .It R |
146 | ``realloc'' always reallocate when | 154 | ``realloc'' always reallocate when |
147 | .Fn realloc | 155 | .Fn realloc |
148 | is called, even if the initial allocation was big enough. | 156 | is called, even if the initial allocation was big enough. |
149 | This can substantially aid in compacting memory. | 157 | This can substantially aid in compacting memory. |
150 | 158 | ||
159 | .It U | ||
160 | ``utrace'' generate entries for ktrace(1) for all operations. | ||
161 | Consult the source for this one. | ||
162 | |||
151 | .It Z | 163 | .It Z |
152 | ``zero'' fill some junk into the area allocated (see ``J''), | 164 | ``zero'' fill some junk into the area allocated (see ``J''), |
153 | except for the exact length the user asked for, which is zeroed. | 165 | except for the exact length the user asked for, which is zeroed. |
154 | 166 | ||
167 | .It < | ||
168 | ``Half the cache size'' Reduce the size of the cache by a factor of two. | ||
169 | |||
170 | .It > | ||
171 | ``Double the cache size'' Double the size of the cache by a factor of two. | ||
155 | .El | 172 | .El |
156 | .Pp | 173 | .Pp |
174 | So to set a systemwide reduction of cache size and coredumps on problems | ||
175 | one would: | ||
176 | .Li ln -s 'A<' /etc/malloc.conf | ||
177 | .Pp | ||
157 | The ``J'' and ``Z'' is mostly for testing and debugging, | 178 | The ``J'' and ``Z'' is mostly for testing and debugging, |
158 | if a program changes behavior if either of these options are used, | 179 | if a program changes behavior if either of these options are used, |
159 | it is buggy. | 180 | it is buggy. |
181 | .Pp | ||
182 | The default cache size is 16 pages. | ||
183 | .Sh ENVIRONMENT | ||
184 | See above. | ||
160 | .Sh RETURN VALUES | 185 | .Sh RETURN VALUES |
161 | The | 186 | The |
162 | .Fn malloc | 187 | .Fn malloc |
@@ -172,12 +197,89 @@ The | |||
172 | .Fn realloc | 197 | .Fn realloc |
173 | function returns either a null pointer or a pointer | 198 | function returns either a null pointer or a pointer |
174 | to the possibly moved allocated space. | 199 | to the possibly moved allocated space. |
200 | .Sh MESSAGES | ||
201 | If | ||
202 | .Fn malloc , | ||
203 | .Fn free | ||
204 | or | ||
205 | .Fn realloc | ||
206 | detects an error or warning condition, | ||
207 | a message will be printed to filedescriptor | ||
208 | 2 (not using stdio). | ||
209 | Errors will always result in the process being | ||
210 | .Xr abort 2 'ed, | ||
211 | If the ``A'' option has been specified, also warnings will | ||
212 | .Xr abort 2 | ||
213 | the process. | ||
214 | .Pp | ||
215 | Here is a brief description of the error messages and what they mean: | ||
216 | .Pp | ||
217 | ``(ES): mumble mumble mumble'': | ||
218 | malloc have been compiled with -DEXTRA_SANITY and something looks | ||
219 | fishy in there. Consult sources and or wizards. | ||
220 | .Pp | ||
221 | ``allocation failed'' | ||
222 | if the ``A'' option is specified it is an error for | ||
223 | .Fn malloc | ||
224 | or | ||
225 | .Fn realloc | ||
226 | to return NULL. | ||
227 | .Pp | ||
228 | ``mmap(2) failed, check limits.'' | ||
229 | This is a rather weird condition that is most likely to mean that | ||
230 | the system is seriously overloaded or that your ulimits are sick. | ||
231 | .Pp | ||
232 | ``freelist is destroyed.'' | ||
233 | mallocs internal freelist has been stomped on. | ||
234 | .Pp | ||
235 | Here is a brief description of the warning messages and what they mean: | ||
236 | .Pp | ||
237 | ``chunk/page is already free.'' | ||
238 | A pointer to a free chunk is attempted freed again. | ||
239 | .Pp | ||
240 | ``junk pointer, too high to make sense.'' | ||
241 | The pointer doesn't make sense. It's above the area of memory that | ||
242 | malloc knows something about. | ||
243 | This could be a pointer from some | ||
244 | .Xr mmap 2 'ed | ||
245 | memory. | ||
246 | .Pp | ||
247 | ``junk pointer, too low to make sense.'' | ||
248 | The pointer doesn't make sense. It's below the area of memory that | ||
249 | malloc knows something about. | ||
250 | This pointer probably came from your data or bss segments. | ||
251 | .Pp | ||
252 | ``malloc() has never been called.'' | ||
253 | Nothing has ever been allocated, yet something is being freed or | ||
254 | realloc'ed. | ||
255 | .Pp | ||
256 | ``modified (chunk-/page-) pointer.'' | ||
257 | The pointer passed to free or realloc has been modified. | ||
258 | .Pp | ||
259 | ``pointer to wrong page.'' | ||
260 | The pointer that malloc is trying to free is not pointing to | ||
261 | a sensible page. | ||
262 | .Pp | ||
263 | ``recursive call.'' | ||
264 | You have tried to call recursively into these functions. | ||
265 | I can only imagine this as happening if you call one of these | ||
266 | functions from a signal function, which happens to be called | ||
267 | while you're already in here. | ||
268 | Well, sorry to say: that's not supported. | ||
269 | If this is a problem for you I'd like to hear about it. It | ||
270 | would be possible to add a sigblock() around this package, | ||
271 | but it would have a performance penalty that is not acceptable | ||
272 | as the default. | ||
273 | .Pp | ||
274 | ``unknown char in MALLOC_OPTIONS'' | ||
275 | we found something we didn't understand. | ||
175 | .Sh SEE ALSO | 276 | .Sh SEE ALSO |
176 | .Xr brk 2 , | 277 | .Xr brk 2 , |
177 | .Xr alloca 3 , | 278 | .Xr alloca 3 , |
178 | .Xr calloc 3 , | 279 | .Xr calloc 3 , |
179 | .Xr getpagesize 3 , | 280 | .Xr getpagesize 3 , |
180 | .Xr memory 3 | 281 | .Xr memory 3 |
282 | .Pa /usr/share/doc/papers/malloc.ascii.gz | ||
181 | .Sh STANDARDS | 283 | .Sh STANDARDS |
182 | The | 284 | The |
183 | .Fn malloc | 285 | .Fn malloc |