summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2014-12-06 18:54:55 +0000
committerschwarze <>2014-12-06 18:54:55 +0000
commit6023656d8c45eb723b7d115cebbb798c866abf5f (patch)
tree3aee91df6b5a17ef10fb591347976ad5ba0195b4 /src
parent46001da00a8d87e0879c23fd670ef1ad33a614e3 (diff)
downloadopenbsd-6023656d8c45eb723b7d115cebbb798c866abf5f.tar.gz
openbsd-6023656d8c45eb723b7d115cebbb798c866abf5f.tar.bz2
openbsd-6023656d8c45eb723b7d115cebbb798c866abf5f.zip
malloc(3) is in the "comp" install set, malloc.conf(5) in "man",
breaking the hardlink between file system entries, confusing apropos(1). Split malloc.conf(5) out of malloc(3) as suggested by deraadt@. Feedback and OK jmc@, OK deraadt@ tedu@ jasper@.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/Makefile.inc4
-rw-r--r--src/lib/libc/stdlib/malloc.3134
2 files changed, 10 insertions, 128 deletions
diff --git a/src/lib/libc/stdlib/Makefile.inc b/src/lib/libc/stdlib/Makefile.inc
index 0c0b1499f8..e95ff11ed6 100644
--- a/src/lib/libc/stdlib/Makefile.inc
+++ b/src/lib/libc/stdlib/Makefile.inc
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile.inc,v 1.54 2014/08/15 04:14:36 guenther Exp $ 1# $OpenBSD: Makefile.inc,v 1.55 2014/12/06 18:54:55 schwarze Exp $
2 2
3# stdlib sources 3# stdlib sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib 4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib
@@ -40,7 +40,7 @@ MLINKS+=insque.3 remque.3
40MLINKS+=labs.3 llabs.3 40MLINKS+=labs.3 llabs.3
41MLINKS+=lsearch.3 lfind.3 41MLINKS+=lsearch.3 lfind.3
42MLINKS+=malloc.3 free.3 malloc.3 realloc.3 malloc.3 calloc.3 42MLINKS+=malloc.3 free.3 malloc.3 realloc.3 malloc.3 calloc.3
43MLINKS+=malloc.3 reallocarray.3 malloc.3 cfree.3 malloc.3 malloc.conf.5 43MLINKS+=malloc.3 reallocarray.3 malloc.3 cfree.3
44MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 44MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3
45MLINKS+=radixsort.3 sradixsort.3 45MLINKS+=radixsort.3 sradixsort.3
46MLINKS+=rand.3 srand.3 rand.3 rand_r.3 46MLINKS+=rand.3 srand.3 rand.3 rand_r.3
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index 3ce9d2e28c..153fd54dbd 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -30,9 +30,9 @@
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE. 31.\" SUCH DAMAGE.
32.\" 32.\"
33.\" $OpenBSD: malloc.3,v 1.85 2014/10/30 21:47:47 deraadt Exp $ 33.\" $OpenBSD: malloc.3,v 1.86 2014/12/06 18:54:55 schwarze Exp $
34.\" 34.\"
35.Dd $Mdocdate: October 30 2014 $ 35.Dd $Mdocdate: December 6 2014 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -285,14 +285,15 @@ Use the following:
285newp = realloc(p, newsize); 285newp = realloc(p, newsize);
286.Ed 286.Ed
287.Sh ENVIRONMENT 287.Sh ENVIRONMENT
288.Bl -tag -width Ev 288.Bl -tag -width "/etc/malloc.conf"
289.It Ev MALLOC_OPTIONS 289.It Ev MALLOC_OPTIONS
290See below. 290String of flags documented in
291.Xr malloc.conf 5 .
291.El 292.El
292.Sh FILES 293.Sh FILES
293.Bl -tag -width "/etc/malloc.conf" 294.Bl -tag -width "/etc/malloc.conf"
294.It Pa /etc/malloc.conf 295.It Pa /etc/malloc.conf
295symbolic link to filename containing option flags 296Symbolic link to filename containing option flags.
296.El 297.El
297.Sh EXAMPLES 298.Sh EXAMPLES
298If 299If
@@ -420,126 +421,6 @@ An inconsistent guard size was detected.
420detected an internal error; 421detected an internal error;
421consult sources and/or wizards. 422consult sources and/or wizards.
422.El 423.El
423.Sh MALLOC_OPTIONS
424Malloc will first look for a symbolic link called
425.Pa /etc/malloc.conf
426and next check the environment for a variable called
427.Ev MALLOC_OPTIONS
428and finally for the global variable
429.Va malloc_options
430and scan them for flags in that order.
431Flags are single letters, uppercase means on, lowercase means off.
432.Bl -tag -width indent
433.It Cm A
434.Dq Abort .
435.Fn malloc
436will coredump the process, rather than tolerate internal
437inconsistencies or incorrect usage.
438This is the default and a very handy debugging aid,
439since the core file represents the time of failure,
440rather than when the bogus pointer was used.
441.It Cm D
442.Dq Dump .
443.Fn malloc
444will dump statistics to the file
445.Pa ./malloc.out ,
446if it already exists,
447at exit.
448This option requires the library to have been compiled with -DMALLOC_STATS in
449order to have any effect.
450.It Cm F
451.Dq Freeguard .
452Enable use after free detection.
453Unused pages on the freelist are read and write protected to
454cause a segmentation fault upon access.
455This will also switch off the delayed freeing of chunks,
456reducing random behaviour but detecting double
457.Fn free
458calls as early as possible.
459This option is intended for debugging rather than improved security
460(use the
461.Cm U
462option for security).
463.It Cm G
464.Dq Guard .
465Enable guard pages.
466Each page size or larger allocation is followed by a guard page that will
467cause a segmentation fault upon any access.
468.It Cm H
469.Dq Hint .
470Pass a hint to the kernel about pages we don't use.
471If the machine is paging a lot this may help a bit.
472.It Cm J
473.Dq Junk .
474Fill some junk into the area allocated.
475Currently junk is bytes of 0xd0 when allocating; this is pronounced
476.Dq Duh .
477\&:-)
478Freed chunks are filled with 0xdf.
479.It Cm j
480.Dq Don't Junk .
481By default, small chunks are always junked, and the first part of pages
482is junked after free.
483This option ensures that no junking is performed.
484.It Cm P
485.Dq Move allocations within a page.
486Allocations larger than half a page but smaller than a page
487are aligned to the end of a page to catch buffer overruns in more
488cases.
489This is the default.
490.It Cm R
491.Dq realloc .
492Always reallocate when
493.Fn realloc
494is called, even if the initial allocation was big enough.
495This can substantially aid in compacting memory.
496.\".Pp
497.\".It Cm U
498.\".Dq utrace .
499.\"Generate entries for
500.\".Xr ktrace 1
501.\"for all operations.
502.\"Consult the source for this one.
503.It Cm S
504Enable all options suitable for security auditing.
505.It Cm U
506.Dq Free unmap .
507Enable use after free protection for larger allocations.
508Unused pages on the freelist are read and write protected to
509cause a segmentation fault upon access.
510.It Cm X
511.Dq xmalloc .
512Rather than return failure,
513.Xr abort 3
514the program with a diagnostic message on stderr.
515It is the intention that this option be set at compile time by
516including in the source:
517.Bd -literal -offset indent
518extern char *malloc_options;
519malloc_options = "X";
520.Ed
521.Pp
522Note that this will cause code that is supposed to handle
523out-of-memory conditions gracefully to abort instead.
524.It Cm <
525.Dq Half the cache size .
526Decrease the size of the free page cache by a factor of two.
527.It Cm >
528.Dq Double the cache size .
529Increase the size of the free page cache by a factor of two.
530.El
531.Pp
532So to set a systemwide reduction of the cache to a quarter of the
533default size and use guard pages:
534.Dl # ln -s 'G<<' /etc/malloc.conf
535.Pp
536The flags are mostly for testing and debugging.
537If a program changes behavior if any of these options (except
538.Cm X )
539are used,
540it is buggy.
541.Pp
542The default number of free pages cached is 64.
543.Sh SEE ALSO 424.Sh SEE ALSO
544.Xr brk 2 , 425.Xr brk 2 ,
545.Xr mmap 2 , 426.Xr mmap 2 ,
@@ -547,7 +428,8 @@ The default number of free pages cached is 64.
547.Xr alloca 3 , 428.Xr alloca 3 ,
548.Xr getpagesize 3 , 429.Xr getpagesize 3 ,
549.Xr posix_memalign 3 , 430.Xr posix_memalign 3 ,
550.Xr sysconf 3 431.Xr sysconf 3 ,
432.Xr malloc.conf 5
551.Sh STANDARDS 433.Sh STANDARDS
552The 434The
553.Fn malloc , 435.Fn malloc ,