summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorMasao Uebayashi <uebayasi@cvs.openbsd.org>2014-07-13 15:46:22 +0000
committerMasao Uebayashi <uebayasi@cvs.openbsd.org>2014-07-13 15:46:22 +0000
commit11fd22a2eda480d68fba16748257d64de3ce31fc (patch)
tree0e30a8d00ee1b4ff1a7176e01c587f81245d2c19 /sys/kern
parentc5e0588509504ef66c639c117c2c55cc2c3f8d3c (diff)
KERNEL_ASSERT_LOCKED(9): Assertion for kernel lock (Rev. 3)
This adds a new assertion macro, KERNEL_ASSERT_LOCKED(), to assert that kernel_lock is held. In the long process of removing kernel_lock, there will be a lot (hundreds or thousands) of use of this; virtually almost all functions in !MP-safe subsystems should have this assertion. Thus this assertion should have a short, good name. Not only that "KERNEL_ASSERT_LOCKED" is consistent with other KERNEL_* and SCHED_ASSERT_LOCKED() macros. Input from dlg@ guenther@ kettenis@. OK dlg@ guenther@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_fork.c4
-rw-r--r--sys/kern/kern_ktrace.c6
-rw-r--r--sys/kern/kern_lock.c8
-rw-r--r--sys/kern/kern_sig.c10
4 files changed, 14 insertions, 14 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 2e035f17ab2..3efa176192b 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.172 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.173 2014/07/13 15:46:21 uebayasi Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -614,7 +614,7 @@ proc_trampoline_mp(void)
__mp_unlock(&sched_lock);
spl0();
SCHED_ASSERT_UNLOCKED();
- KASSERT(__mp_lock_held(&kernel_lock) == 0);
+ KERNEL_ASSERT_UNLOCKED();
KERNEL_LOCK();
}
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index d0f68be1153..7c3f1d4762d 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_ktrace.c,v 1.68 2014/07/13 15:00:40 tedu Exp $ */
+/* $OpenBSD: kern_ktrace.c,v 1.69 2014/07/13 15:46:21 uebayasi Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */
/*
@@ -332,9 +332,7 @@ ktrstruct(struct proc *p, const char *name, const void *data, size_t datalen)
void *buf;
size_t buflen;
-#ifdef MULTIPROCESSOR
- KASSERT(__mp_lock_held(&kernel_lock) > 0);
-#endif
+ KERNEL_ASSERT_LOCKED();
atomic_setbits_int(&p->p_flag, P_INKTR);
ktrinitheader(&kth, p, KTR_STRUCT);
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index 946fd17e3b3..a9eb9574cd3 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_lock.c,v 1.44 2014/07/09 13:32:00 guenther Exp $ */
+/* $OpenBSD: kern_lock.c,v 1.45 2014/07/13 15:46:21 uebayasi Exp $ */
/*
* Copyright (c) 1995
@@ -134,4 +134,10 @@ _kernel_unlock(void)
{
__mp_unlock(&kernel_lock);
}
+
+int
+_kernel_lock_held(void)
+{
+ return (__mp_lock_held(&kernel_lock));
+}
#endif /* MULTIPROCESSOR */
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 28ebd811904..970507f28b6 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sig.c,v 1.171 2014/07/12 21:21:19 matthew Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.172 2014/07/13 15:46:21 uebayasi Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@@ -1897,9 +1897,7 @@ single_thread_set(struct proc *p, enum single_thread_mode mode, int deep)
struct proc *q;
int error;
-#ifdef MULTIPROCESSOR
- KASSERT(__mp_lock_held(&kernel_lock));
-#endif
+ KERNEL_ASSERT_LOCKED();
if ((error = single_thread_check(p, deep)))
return error;
@@ -1996,9 +1994,7 @@ single_thread_clear(struct proc *p, int flag)
struct proc *q;
KASSERT(pr->ps_single == p);
-#ifdef MULTIPROCESSOR
- KASSERT(__mp_lock_held(&kernel_lock));
-#endif
+ KERNEL_ASSERT_LOCKED();
pr->ps_single = NULL;
atomic_clearbits_int(&pr->ps_flags, PS_SINGLEUNWIND | PS_SINGLEEXIT);