Make malloc and mbuf allocation mode flags nonoverlapping.

Under INVARIANTS whine if we get incompatible flags.

Submitted by:   imp
This commit is contained in:
Poul-Henning Kamp 2003-03-10 19:39:53 +00:00
parent 0e8677f68b
commit d3c11994e1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=112063
4 changed files with 39 additions and 7 deletions

View File

@ -167,11 +167,28 @@ malloc(size, type, flags)
#endif
register struct malloc_type *ksp = type;
/* #ifdef INVARIANTS */
/*
* To make sure that WAITOK or NOWAIT is set, but not more than
* one, and check against the API botches that are common.
*/
indx = flags & (M_WAITOK | M_NOWAIT | M_DONTWAIT | M_TRYWAIT);
if (indx != M_NOWAIT && indx != M_WAITOK) {
static struct timeval lasterr;
static int curerr, once;
if (once == 0 && ppsratecheck(&lasterr, &curerr, 1)) {
printf("Bad malloc flags: %x\n", indx);
backtrace();
flags |= M_WAITOK;
once++;
}
}
/* #endif */
#if 0
if (size == 0)
Debugger("zero size malloc");
#endif
if (!(flags & M_NOWAIT))
if (flags & M_WAITOK)
KASSERT(curthread->td_intr_nesting_level == 0,
("malloc(M_WAITOK) in interrupt context"));
if (size <= KMEM_ZMAX) {

View File

@ -614,6 +614,21 @@ mb_alloc(struct mb_lstmngr *mb_list, int how, short type, short persist,
struct mb_bucket *bucket;
void *m;
/* #ifdef INVARIANTS */
int flags;
flags = how & (M_WAITOK | M_NOWAIT | M_DONTWAIT | M_TRYWAIT);
if (flags != M_DONTWAIT && flags != M_TRYWAIT) {
static struct timeval lasterr;
static int curerr;
if (ppsratecheck(&lasterr, &curerr, 1)) {
printf("Bad mbuf alloc flags: %x\n", flags);
backtrace();
how = M_TRYWAIT;
}
}
/* #endif */
m = NULL;
if ((persist & MBP_PERSISTENT) != 0) {
/*

View File

@ -46,11 +46,11 @@
/*
* flags to malloc.
*/
#define M_WAITOK 0x0000
#define M_NOWAIT 0x0001 /* do not block */
#define M_USE_RESERVE 0x0002 /* can alloc out of reserve memory */
#define M_ZERO 0x0004 /* bzero the allocation */
#define M_NOVM 0x0008 /* don't ask VM for pages */
#define M_WAITOK 0x0002 /* do not block */
#define M_ZERO 0x0100 /* bzero the allocation */
#define M_NOVM 0x0200 /* don't ask VM for pages */
#define M_USE_RESERVE 0x0400 /* can alloc out of reserve memory */
#define M_MAGIC 877983977 /* time when first defined :-) */

View File

@ -269,8 +269,8 @@ struct mbstat {
* M_TRYWAIT means "block for mbuf_wait ticks at most if nothing is
* available."
*/
#define M_DONTWAIT 1
#define M_TRYWAIT 0
#define M_DONTWAIT 0x4 /* don't conflict with M_NOWAIT */
#define M_TRYWAIT 0x8 /* or M_WAITOK */
#define M_WAIT M_TRYWAIT /* XXX: Deprecated. */
#ifdef _KERNEL