mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-05 12:56:08 +00:00
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
This commit is contained in:
parent
920c17857f
commit
9211b0b657
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=71799
@ -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 @@ malloc(size, type, flags)
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
@ -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 :-) */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user