rw_assert_unlocked(9) should check if the current thread is holding
the lock, not if the lock is held by anyone else.  The general check
is racy and I cannot think of any safe way to use it.

Diff below is required for the vm_map_asssert_locked() diff I sent
earlier.

Index: kern/kern_rwlock.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_rwlock.c,v
retrieving revision 1.40
diff -u -p -r1.40 kern_rwlock.c
--- kern/kern_rwlock.c  16 Jul 2019 01:40:49 -0000      1.40
+++ kern/kern_rwlock.c  10 Nov 2019 15:06:51 -0000
@@ -400,7 +400,7 @@ rw_assert_unlocked(struct rwlock *rwl)
        if (panicstr || db_active)
                return;
 
-       if (rwl->rwl_owner != 0L)
+       if (RW_PROC(curproc) == RW_PROC(rwl->rwl_owner))
                panic("%s: lock held", rwl->rwl_name);
 }
 #endif

Reply via email to