summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authoraaron <>2000-04-20 02:14:26 +0000
committeraaron <>2000-04-20 02:14:26 +0000
commit92b3e44bedaf5a5f85880565a47206cdbf9bfa2a (patch)
tree8d23d613d71ca23616fa162475d6aa3c3abf6cd7 /src/lib
parent6e79b911ce0057b5b91d0f9cedd766e0163fb043 (diff)
downloadopenbsd-92b3e44bedaf5a5f85880565a47206cdbf9bfa2a.tar.gz
openbsd-92b3e44bedaf5a5f85880565a47206cdbf9bfa2a.tar.bz2
openbsd-92b3e44bedaf5a5f85880565a47206cdbf9bfa2a.zip
- Formatting repairs and standardizations.
- s/MESSAGES/DIAGNOSTICS/, and put message descriptions in a nice list. - Talk more about how using malloc() in signal handlers is bad.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/stdlib/malloc.3181
1 files changed, 104 insertions, 77 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index 804f0b9094..8d333f55c2 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -1,3 +1,4 @@
1.\"
1.\" Copyright (c) 1980, 1991, 1993 2.\" Copyright (c) 1980, 1991, 1993
2.\" The Regents of the University of California. All rights reserved. 3.\" The Regents of the University of California. All rights reserved.
3.\" 4.\"
@@ -33,7 +34,7 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 35.\" SUCH DAMAGE.
35.\" 36.\"
36.\" $OpenBSD: malloc.3,v 1.18 2000/01/19 05:36:38 pjanzen Exp $ 37.\" $OpenBSD: malloc.3,v 1.19 2000/04/20 02:14:26 aaron Exp $
37.\" 38.\"
38.Dd August 27, 1996 39.Dd August 27, 1996
39.Dt MALLOC 3 40.Dt MALLOC 3
@@ -72,7 +73,8 @@ space from the appropriate list.
72.Pp 73.Pp
73The allocated space is 74The allocated space is
74suitably aligned (after possible pointer 75suitably aligned (after possible pointer
75coercion) for storage of any type of object. If the space is of 76coercion) for storage of any type of object.
77If the space is of
76.Em pagesize 78.Em pagesize
77or larger, the memory returned will be page-aligned. 79or larger, the memory returned will be page-aligned.
78.Pp 80.Pp
@@ -166,43 +168,54 @@ and finally for the global variable
166and scan them for flags in that order. 168and scan them for flags in that order.
167Flags are single letters, uppercase means on, lowercase means off. 169Flags are single letters, uppercase means on, lowercase means off.
168.Bl -tag -width indent 170.Bl -tag -width indent
169.It A 171.It Cm A
170``abort'' malloc will coredump the process, rather than tolerate failure. 172.Dq Abort .
173.Fn malloc
174will coredump the process, rather than tolerate failure.
171This is a very handy debugging aid, since the core file will represent the 175This is a very handy debugging aid, since the core file will represent the
172time of failure, 176time of failure, rather than when the null pointer was accessed.
173rather than when the null pointer was accessed.
174.Pp 177.Pp
175.It D 178.It Cm D
176``dump'' malloc will dump statistics in a file called ``malloc.out'' at exit. 179.Dq Dump .
180.Fn malloc
181will dump statistics in a file called
182.Pa malloc.out
183at exit.
177This option requires the library to have been compiled with -DMALLOC_STATS in 184This option requires the library to have been compiled with -DMALLOC_STATS in
178order to have any effect. 185order to have any effect.
179.Pp 186.Pp
180.It J 187.It Cm J
181``junk'' fill some junk into the area allocated. 188.Dq Junk .
182Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-) 189Fill some junk into the area allocated.
190Currently junk is bytes of 0xd0; this is pronounced
191.Dq Duh .
192\&:-)
183.Pp 193.Pp
184.It H 194.It Cm H
185``hint'' pass a hint to the kernel about pages we don't use. If the 195.Dq Hint .
186machine is paging a lot this may help a bit. 196Pass a hint to the kernel about pages we don't use.
197If the machine is paging a lot this may help a bit.
187.Pp 198.Pp
188.It N 199.It Cm N
189Do not output warning messages when encountering possible corruption 200Do not output warning messages when encountering possible corruption
190or bad pointers. 201or bad pointers.
191.Pp 202.Pp
192.It R 203.It Cm R
193``realloc'' always reallocate when 204.Dq realloc .
205Always reallocate when
194.Fn realloc 206.Fn realloc
195is called, even if the initial allocation was big enough. 207is called, even if the initial allocation was big enough.
196This can substantially aid in compacting memory. 208This can substantially aid in compacting memory.
197.Pp 209.Pp
198.It U 210.It Cm U
199``utrace'' generate entries for 211.Dq utrace .
212Generate entries for
200.Xr ktrace 1 213.Xr ktrace 1
201for all operations. 214for all operations.
202Consult the source for this one. 215Consult the source for this one.
203.Pp 216.Pp
204.It X 217.It Cm X
205``xmalloc'' 218.Dq xmalloc .
206rather than return failure, 219rather than return failure,
207.Xr abort 3 220.Xr abort 3
208the program with a diagnostic message on stderr. 221the program with a diagnostic message on stderr.
@@ -213,23 +226,31 @@ extern char *malloc_options;
213malloc_options = "X"; 226malloc_options = "X";
214.Ed 227.Ed
215.Pp 228.Pp
216.It Z 229.It Cm Z
217``zero'' fill some junk into the area allocated (see ``J''), 230.Dq Zero .
231Fill some junk into the area allocated (see
232.Cm J ) ,
218except for the exact length the user asked for, which is zeroed. 233except for the exact length the user asked for, which is zeroed.
219.Pp 234.Pp
220.It < 235.It Cm <
221``Half the cache size'' Reduce the size of the cache by a factor of two. 236.Dq Half the cache size .
237Reduce the size of the cache by a factor of two.
222.Pp 238.Pp
223.It > 239.It Cm >
224``Double the cache size'' Double the size of the cache by a factor of two. 240.Dq Double the cache size .
241Double the size of the cache by a factor of two.
225.El 242.El
226.Pp 243.Pp
227So to set a systemwide reduction of cache size and coredumps on problems 244So to set a systemwide reduction of cache size and coredumps on problems
228one would: 245one would:
229.Li ln -s 'A<' /etc/malloc.conf 246.Li ln -s 'A<' /etc/malloc.conf
230.Pp 247.Pp
231The ``J'' and ``Z'' is mostly for testing and debugging, 248The
232if a program changes behavior if either of these options are used, 249.Cm J
250and
251.Cm Z
252is mostly for testing and debugging.
253If a program changes behavior if either of these options are used,
233it is buggy. 254it is buggy.
234.Pp 255.Pp
235The default cache size is 16 pages. 256The default cache size is 16 pages.
@@ -240,8 +261,7 @@ The
240.Fn malloc 261.Fn malloc
241and 262and
242.Fn calloc 263.Fn calloc
243functions return 264functions return a pointer to the allocated space if successful; otherwise,
244a pointer to the allocated space if successful; otherwise,
245a null pointer is returned and 265a null pointer is returned and
246.Va errno 266.Va errno
247is set to 267is set to
@@ -260,11 +280,11 @@ if successful; otherwise, a null pointer is returned and
260.Va errno 280.Va errno
261is set to 281is set to
262.Er ENOMEM . 282.Er ENOMEM .
263.Sh MESSAGES 283.Sh DIAGNOSTICS
264If 284If
265.Fn malloc , 285.Fn malloc ,
266.Fn calloc , 286.Fn calloc ,
267.Fn realloc 287.Fn realloc ,
268or 288or
269.Fn free 289.Fn free
270detect an error or warning condition, 290detect an error or warning condition,
@@ -272,77 +292,84 @@ a message will be printed to file descriptor
2722 (not using stdio). 2922 (not using stdio).
273Errors will always result in the process being 293Errors will always result in the process being
274.Xr abort 3 'ed. 294.Xr abort 3 'ed.
275If the ``A'' option has been specified, warnings will also 295If the
296.Cm A
297option has been specified, warnings will also
276.Xr abort 3 298.Xr abort 3
277the process. 299the process.
278.Pp 300.Pp
279Here is a brief description of the error messages and what they mean: 301Here is a brief description of the error messages and what they mean:
280.Pp 302.Bl -tag -width Fl
281``(ES): mumble mumble mumble'': 303.It Dq (ES): mumble mumble mumble
282malloc have been compiled with -DEXTRA_SANITY and something looks 304.Fn malloc
283fishy in there. Consult sources and or wizards. 305has been compiled with
284.Pp 306.Dv \&-DEXTRA_SANITY
285``allocation failed'' 307and something looks fishy in there.
286if the ``A'' option is specified it is an error for 308Consult sources and/or wizards.
309.It Dq allocation failed
310If the
311.Cm A
312option is specified it is an error for
287.Fn malloc , 313.Fn malloc ,
288.Fn calloc 314.Fn calloc ,
289or 315or
290.Fn realloc 316.Fn realloc
291to return 317to return
292.Dv NULL . 318.Dv NULL .
293.Pp 319.It Dq mmap(2) failed, check limits.
294``mmap(2) failed, check limits.'' 320This is a rather weird condition that is most likely to indicate a
295This is a rather weird condition that is most likely to mean that 321seriously overloaded system or a
296the system is seriously overloaded or that your ulimits are sick. 322.Xr ulimit 1
297.Pp 323restriction.
298``freelist is destroyed.'' 324.It Dq freelist is destroyed.
299mallocs internal freelist has been stomped on. 325.Fn malloc Ns 's
326internal freelist has been stomped on.
327.El
300.Pp 328.Pp
301Here is a brief description of the warning messages and what they mean: 329Here is a brief description of the warning messages and what they mean:
302.Pp 330.Bl -tag -width Fl
303``chunk/page is already free.'' 331.It Dq chunk/page is already free.
304A pointer to a free chunk is attempted freed again. 332A pointer to a free chunk is attempted freed again.
305.Pp 333.It Dq junk pointer, too high to make sense.
306``junk pointer, too high to make sense.'' 334The pointer doesn't make sense.
307The pointer doesn't make sense. It's above the area of memory that 335It's above the area of memory that
308.Fn malloc 336.Fn malloc
309knows something about. 337knows something about.
310This could be a pointer from some 338This could be a pointer from some
311.Xr mmap 2 'ed 339.Xr mmap 2 'ed
312memory. 340memory.
313.Pp 341.It Dq junk pointer, too low to make sense.
314``junk pointer, too low to make sense.'' 342The pointer doesn't make sense.
315The pointer doesn't make sense. It's below the area of memory that 343It's below the area of memory that
316.Fn malloc 344.Fn malloc
317knows something about. 345knows something about.
318This pointer probably came from your data or bss segments. 346This pointer probably came from your data or bss segments.
319.Pp 347.It Dq malloc() has never been called.
320``malloc() has never been called.''
321Nothing has ever been allocated, yet something is being freed or 348Nothing has ever been allocated, yet something is being freed or
322realloc'ed. 349realloc'ed.
323.Pp 350.It Dq modified (chunk-/page-) pointer.
324``modified (chunk-/page-) pointer.''
325The pointer passed to free or realloc has been modified. 351The pointer passed to free or realloc has been modified.
326.Pp 352.It Dq pointer to wrong page.
327``pointer to wrong page.''
328The pointer that 353The pointer that
329.Fn malloc 354.Fn malloc
330is trying to free is not pointing to 355is trying to free is not pointing to
331a sensible page. 356a sensible page.
332.Pp 357.It Dq recursive call.
333``recursive call.'' 358An attempt was made to call recursively into these functions, i.e., from a
334You have tried to call recursively into these functions. 359signal handler.
335I can only imagine this as happening if you call one of these 360This behavior is not supported.
336functions from a signal handler, which happens to be called 361In particular, signal handlers should
337while you're already in here. 362.Em not
338Well, sorry to say: that's not supported. 363use any of the
339If this is a problem for you I'd like to hear about it. It 364.Fn malloc
340would be possible to add a sigblock() around this package, 365functions nor utilize any other functions which may call
341but it would have a performance penalty that is not acceptable 366.Fn malloc
342as the default. 367(e.g.,
343.Pp 368.Xr stdio 3
344``unknown char in MALLOC_OPTIONS'' 369routines).
345we found something we didn't understand. 370.It Dq unknown char in MALLOC_OPTIONS
371We found something we didn't understand.
372.El
346.Sh FILES 373.Sh FILES
347.Bl -tag -width "/etc/malloc.conf" 374.Bl -tag -width "/etc/malloc.conf"
348.It Pa /etc/malloc.conf 375.It Pa /etc/malloc.conf