summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorbp <bp@FreeBSD.org>2001-01-29 12:48:37 +0000
committerbp <bp@FreeBSD.org>2001-01-29 12:48:37 +0000
commite88e663eb2e5baec6cc42b7e50c7598cb0576a17 (patch)
treec5133bfb6bc1da555674c78ec8eceb8b4ecb1f39 /sys
parent8eddfd2f15c1a1023a50f6b1aecbf02bfbdc652e (diff)
downloadFreeBSD-src-e88e663eb2e5baec6cc42b7e50c7598cb0576a17.zip
FreeBSD-src-e88e663eb2e5baec6cc42b7e50c7598cb0576a17.tar.gz
Add M_PANIC flag to the list of available flags passed to malloc().
With this flag set malloc() will panic if memory allocation failed. This usable only in critical places where failed allocation is fatal. Reviewed by: peter
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_malloc.c8
-rw-r--r--sys/sys/malloc.h1
2 files changed, 7 insertions, 2 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 089d867..2186007 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -164,7 +164,8 @@ malloc(size, type, flags)
if (flags & M_NOWAIT) {
splx(s);
mtx_exit(&malloc_mtx, MTX_DEF);
- return ((void *) NULL);
+ va = NULL;
+ goto checkpanic;
}
if (ksp->ks_limblocks < 65535)
ksp->ks_limblocks++;
@@ -188,7 +189,7 @@ malloc(size, type, flags)
if (va == NULL) {
splx(s);
- return ((void *) NULL);
+ goto checkpanic;
}
/*
* Enter malloc_mtx after the error check to avoid having to
@@ -282,6 +283,9 @@ out:
/* XXX: Do idle pre-zeroing. */
if (va != NULL && (flags & M_ZERO))
bzero(va, size);
+checkpanic:
+ if (va == NULL && (flags & M_PANIC))
+ panic("malloc: failed to allocate %ld bytes", size);
return ((void *) va);
}
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
index 935ec3e..3d59271 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -47,6 +47,7 @@
#define M_USE_RESERVE 0x0002 /* can alloc out of reserve memory */
#define M_ASLEEP 0x0004 /* async sleep on failure */
#define M_ZERO 0x0008 /* bzero the allocation */
+#define M_PANIC 0x0010 /* panic if allocation failed */
#define M_MAGIC 877983977 /* time when first defined :-) */
OpenPOWER on IntegriCloud