diff options
author | Boris Popov <bp@FreeBSD.org> | 2001-01-29 12:48:37 +0000 |
---|---|---|
committer | Boris Popov <bp@FreeBSD.org> | 2001-01-29 12:48:37 +0000 |
commit | 9211b0b657e641046e4e0fb4e565ad684283b6f5 (patch) | |
tree | 81543981dd5c3b6be80daa8782a265fe7a928a76 /sys/kern/kern_malloc.c | |
parent | 920c17857f5a57e1e6be3cdea9530335c6840d36 (diff) | |
download | src-9211b0b657e641046e4e0fb4e565ad684283b6f5.tar.gz src-9211b0b657e641046e4e0fb4e565ad684283b6f5.zip |
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
Notes
Notes:
svn path=/head/; revision=71799
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r-- | sys/kern/kern_malloc.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 089d867e4dfe..2186007946f5 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); } |