diff options
author | John Baldwin <jhb@FreeBSD.org> | 2007-05-08 21:51:37 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2007-05-08 21:51:37 +0000 |
commit | 0026c92c3eb83a491bb4bdc1c1309752f7e92edd (patch) | |
tree | 666b5595ce1dc5855c3c502c770842207fe32fdc /sys/kern/kern_sx.c | |
parent | c0bfd70306701290fc7529faf499e4d23c41dfef (diff) | |
download | src-0026c92c3eb83a491bb4bdc1c1309752f7e92edd.tar.gz src-0026c92c3eb83a491bb4bdc1c1309752f7e92edd.zip |
Add destroyed cookie values for sx locks and rwlocks as well as extra
KASSERTs so that any lock operations on a destroyed lock will panic or
hang.
Notes
Notes:
svn path=/head/; revision=169394
Diffstat (limited to 'sys/kern/kern_sx.c')
-rw-r--r-- | sys/kern/kern_sx.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index bbb62d063cd2..0204e6a27a8a 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -193,6 +193,7 @@ sx_destroy(struct sx *sx) KASSERT(sx->sx_lock == SX_LOCK_UNLOCKED, ("sx lock still held")); KASSERT(sx->sx_recurse == 0, ("sx lock still recursed")); + sx->sx_lock = SX_LOCK_DESTROYED; lock_profile_object_destroy(&sx->lock_object); lock_destroy(&sx->lock_object); } @@ -202,6 +203,8 @@ _sx_slock(struct sx *sx, const char *file, int line) { MPASS(curthread != NULL); + KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, + ("sx_slock() of destroyed sx @ %s:%d", file, line)); WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER, file, line); __sx_slock(sx, file, line); LOCK_LOG_LOCK("SLOCK", &sx->lock_object, 0, 0, file, line); @@ -215,6 +218,8 @@ _sx_try_slock(struct sx *sx, const char *file, int line) uintptr_t x; x = sx->sx_lock; + KASSERT(x != SX_LOCK_DESTROYED, + ("sx_try_slock() of destroyed sx @ %s:%d", file, line)); if ((x & SX_LOCK_SHARED) && atomic_cmpset_acq_ptr(&sx->sx_lock, x, x + SX_ONE_SHARER)) { LOCK_LOG_TRY("SLOCK", &sx->lock_object, 0, 1, file, line); @@ -232,6 +237,8 @@ _sx_xlock(struct sx *sx, const char *file, int line) { MPASS(curthread != NULL); + KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, + ("sx_xlock() of destroyed sx @ %s:%d", file, line)); WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, line); __sx_xlock(sx, curthread, file, line); @@ -246,6 +253,8 @@ _sx_try_xlock(struct sx *sx, const char *file, int line) int rval; MPASS(curthread != NULL); + KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, + ("sx_try_xlock() of destroyed sx @ %s:%d", file, line)); if (sx_xlocked(sx)) { sx->sx_recurse++; @@ -269,6 +278,8 @@ _sx_sunlock(struct sx *sx, const char *file, int line) { MPASS(curthread != NULL); + KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, + ("sx_sunlock() of destroyed sx @ %s:%d", file, line)); _sx_assert(sx, SX_SLOCKED, file, line); curthread->td_locks--; WITNESS_UNLOCK(&sx->lock_object, 0, file, line); @@ -283,6 +294,8 @@ _sx_xunlock(struct sx *sx, const char *file, int line) { MPASS(curthread != NULL); + KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, + ("sx_xunlock() of destroyed sx @ %s:%d", file, line)); _sx_assert(sx, SX_XLOCKED, file, line); curthread->td_locks--; WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line); @@ -304,6 +317,8 @@ _sx_try_upgrade(struct sx *sx, const char *file, int line) uintptr_t x; int success; + KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, + ("sx_try_upgrade() of destroyed sx @ %s:%d", file, line)); _sx_assert(sx, SX_SLOCKED, file, line); /* @@ -329,6 +344,8 @@ _sx_downgrade(struct sx *sx, const char *file, int line) { uintptr_t x; + KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, + ("sx_downgrade() of destroyed sx @ %s:%d", file, line)); _sx_assert(sx, SX_XLOCKED | SX_NOTRECURSED, file, line); #ifndef INVARIANTS if (sx_recursed(sx)) @@ -916,7 +933,10 @@ db_show_sx(struct lock_object *lock) db_printf(" state: "); if (sx->sx_lock == SX_LOCK_UNLOCKED) db_printf("UNLOCKED\n"); - else if (sx->sx_lock & SX_LOCK_SHARED) + else if (sx->sx_lock == SX_LOCK_DESTROYED) { + db_printf("DESTROYED\n"); + return; + } else if (sx->sx_lock & SX_LOCK_SHARED) db_printf("SLOCK: %ju\n", (uintmax_t)SX_SHARERS(sx->sx_lock)); else { td = sx_xholder(sx); |