summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1997-06-12 12:45:45 +0000
committerphk <phk@FreeBSD.org>1997-06-12 12:45:45 +0000
commit88464dd9dcb625ec445f1186065f9fc8c898fe67 (patch)
treeba573277510782e74a0ae352d43a1d15245c31e6 /lib/libc
parent628c1856e7672afd3ca295aab9a1f0a81ea4e0c5 (diff)
downloadFreeBSD-src-88464dd9dcb625ec445f1186065f9fc8c898fe67.zip
FreeBSD-src-88464dd9dcb625ec445f1186065f9fc8c898fe67.tar.gz
Add yet an option, this time on how to deal with malloc(0) and realloc(ptr.0)
Prompted by: X11 & XFree86
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdlib/malloc.321
-rw-r--r--lib/libc/stdlib/malloc.c14
2 files changed, 27 insertions, 8 deletions
diff --git a/lib/libc/stdlib/malloc.3 b/lib/libc/stdlib/malloc.3
index 9782588..479ab00 100644
--- a/lib/libc/stdlib/malloc.3
+++ b/lib/libc/stdlib/malloc.3
@@ -34,7 +34,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)malloc.3 8.1 (Berkeley) 6/4/93
-.\" $Id: malloc.3,v 1.9 1997/03/22 23:48:12 mpp Exp $
+.\" $Id: malloc.3,v 1.10 1997/05/30 20:39:32 phk Exp $
.\"
.Dd August 27, 1996
.Dt MALLOC 3
@@ -149,6 +149,11 @@ This can substantially aid in compacting memory.
``utrace'' generate entries for ktrace(1) for all operations.
Consult the source for this one.
+.It V
+``sysV'' operations that attempt to allocate zero bytes will
+return a null pointer. Be aware of the conflict if you also
+have ``X'' set.
+
.It X
``xmalloc''
rather than return failure,
@@ -217,7 +222,7 @@ Here is a brief description of the error messages and what they mean:
.Pp
``(ES): mumble mumble mumble'':
malloc have been compiled with -DEXTRA_SANITY and something looks
-fishy in there. Consult sources and or wizards.
+fishy in there. Consult sources and/or wizards.
.Pp
``allocation failed''
if the ``A'' option is specified it is an error for
@@ -272,6 +277,13 @@ would be possible to add a sigblock() around this package,
but it would have a performance penalty that is not acceptable
as the default.
.Pp
+``out of memory''
+The ``X'' flag is active and an allocation of memory failed.
+.Pp
+``open of /dev/zero''
+On certain architectures /dev/zero is used as a source of
+anonymous pages for the page directory, opening failed.
+.Pp
``unknown char in MALLOC_OPTIONS''
we found something we didn't understand.
.Sh SEE ALSO
@@ -286,6 +298,9 @@ The
.Fn malloc
function conforms to
.St -ansiC .
+.Sh BUGS
+It can be argued that returning a null pointer when asked to
+allocate zero bytes is a silly response to a silly question.
.Sh HISTORY
The present implementation of malloc started out as a filesystem on a drum
attached to a 20bit binary challenged computer built with discrete germanium
@@ -293,7 +308,7 @@ transistors, and it has since graduated to handle primary storage rather than
secondary.
.Pp
The main difference from other malloc implementations are believed to be that
-the free pages are not accessed until allocated.
+the free pages are not accessed unless allocated.
Most malloc implementations will store a data structure containing a,
possibly double-, linked list in the free chunks of memory, used to tie
all the free memory together.
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 0327517..446f55d 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: malloc.c,v 1.23 1997/05/30 20:39:32 phk Exp $
+ * $Id: malloc.c,v 1.24 1997/06/04 12:55:49 jb Exp $
*
*/
@@ -216,6 +216,9 @@ static int malloc_hint;
/* xmalloc behaviour ? */
static int malloc_xmalloc;
+/* sysv behaviour for malloc(0) ? */
+static int malloc_sysv;
+
/* zero fill ? */
static int malloc_zero;
@@ -488,6 +491,8 @@ malloc_init ()
case 'J': malloc_junk = 1; break;
case 'u': malloc_utrace = 0; break;
case 'U': malloc_utrace = 1; break;
+ case 'v': malloc_sysv = 0; break;
+ case 'V': malloc_sysv = 1; break;
case 'x': malloc_xmalloc = 0; break;
case 'X': malloc_xmalloc = 1; break;
case 'z': malloc_zero = 0; break;
@@ -774,7 +779,9 @@ imalloc(size_t size)
if (suicide)
abort();
- if ((size + malloc_pagesize) < size) /* Check for overflow */
+ if (malloc_sysv && !size)
+ result = 0;
+ else if ((size + malloc_pagesize) < size) /* Check for overflow */
result = 0;
else if (size <= malloc_maxsize)
result = malloc_bytes(size);
@@ -1179,9 +1186,6 @@ realloc(void *ptr, size_t size)
}
if (!ptr) {
r = imalloc(size);
- } else if (ptr && !size) {
- ifree(ptr);
- r = 0;
} else {
r = irealloc(ptr, size);
}
OpenPOWER on IntegriCloud