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 /sys/kern/kern_malloc.c | |
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
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r-- | sys/kern/kern_malloc.c | 19 |
1 files changed, 18 insertions, 1 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) { |