aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2003-03-10 19:39:53 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2003-03-10 19:39:53 +0000
commitd3c11994e1e3de7445305abd0d41dce2b8d3e6dc (patch)
tree968c512aa3fe86d42039384972c736f2673aa09b /sys/kern/kern_malloc.c
parent0e8677f68bace0ecfc6b7482cc58b41b230bdd41 (diff)
downloadsrc-d3c11994e1e3de7445305abd0d41dce2b8d3e6dc.tar.gz
src-d3c11994e1e3de7445305abd0d41dce2b8d3e6dc.zip
Make malloc and mbuf allocation mode flags nonoverlapping.
Under INVARIANTS whine if we get incompatible flags. Submitted by: imp
Notes
Notes: svn path=/head/; revision=112063
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 04bf4b4ca9d7..978fc6a694aa 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) {