diff options
author | phk <phk@FreeBSD.org> | 2003-03-10 19:39:53 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2003-03-10 19:39:53 +0000 |
commit | b3deffb7e1c58d9f408582b7ba87f3eecdad6d2a (patch) | |
tree | 968c512aa3fe86d42039384972c736f2673aa09b | |
parent | cb710fa095bfc37788e3deb3d0530568ce1b0c27 (diff) | |
download | FreeBSD-src-b3deffb7e1c58d9f408582b7ba87f3eecdad6d2a.zip FreeBSD-src-b3deffb7e1c58d9f408582b7ba87f3eecdad6d2a.tar.gz |
Make malloc and mbuf allocation mode flags nonoverlapping.
Under INVARIANTS whine if we get incompatible flags.
Submitted by: imp
-rw-r--r-- | sys/kern/kern_malloc.c | 19 | ||||
-rw-r--r-- | sys/kern/subr_mbuf.c | 15 | ||||
-rw-r--r-- | sys/sys/malloc.h | 8 | ||||
-rw-r--r-- | sys/sys/mbuf.h | 4 |
4 files changed, 39 insertions, 7 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 04bf4b4..978fc6a 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -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) { diff --git a/sys/kern/subr_mbuf.c b/sys/kern/subr_mbuf.c index 7906ab1..285d376 100644 --- a/sys/kern/subr_mbuf.c +++ b/sys/kern/subr_mbuf.c @@ -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) { /* diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index f610439..3d2d2cf 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -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 :-) */ diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index d13964b..8035b8e 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -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 |