summaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-06-07 13:30:37 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-06-07 13:30:37 +0000
commit14dd694e0b7c40bb76cbfacea4661af0ed9ac265 (patch)
tree08abe3d97deb100d56a834b6d7d300279499e62c /sys/kern/kern_malloc.c
parent275bbd85f95e1e46cce9b4534166c79813637f94 (diff)
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@
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c8
1 files changed, 7 insertions, 1 deletions
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;