From 1a582ed7bc900ebabab5537a822307b96f4025c7 Mon Sep 17 00:00:00 2001 From: mpi Date: Wed, 7 Jun 2017 13:30:36 +0000 Subject: [PATCH] Assert that the calling CPU is holding the KERNEL_LOCK() in malloc(9) and free(9). The exception is at early boot when only one CPU is running since we grab the KERNL_LOCK() relatively late in main(). ok kettenis@ --- sys/kern/kern_malloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index eb3f62fb99a..dff635d9ce6 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc.c,v 1.128 2015/03/14 03:38:50 jsg Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.129 2017/06/07 13:30:36 mpi Exp $ */ /* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ /* @@ -164,6 +164,9 @@ malloc(size_t size, int type, int flags) panic("malloc: bogus type %d", type); #endif + if (!cold) + KERNEL_ASSERT_LOCKED(); + KASSERT(flags & (M_WAITOK | M_NOWAIT)); if ((flags & M_NOWAIT) == 0) { @@ -366,6 +369,9 @@ free(void *addr, int type, size_t freedsize) struct kmemstats *ksp = &kmemstats[type]; #endif + if (!cold) + KERNEL_ASSERT_LOCKED(); + if (addr == NULL) return; -- 2.20.1