diff options
author | 2020-11-12 05:49:26 +0000 | |
---|---|---|
committer | 2020-11-12 05:49:26 +0000 | |
commit | 067f6e2e3ae18625d736080b5bda9dd317588f8b (patch) | |
tree | 96d01edecb3be57c8dea800b8bad47b3c232750b /sys | |
parent | use RWLOCK_INITIALIZER() in DEFINE_MUTEX() (diff) | |
download | wireguard-openbsd-067f6e2e3ae18625d736080b5bda9dd317588f8b.tar.xz wireguard-openbsd-067f6e2e3ae18625d736080b5bda9dd317588f8b.zip |
witness: detect and report uninitialized (or zeroed) lock usage
ok visa@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/subr_witness.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c index 1bb27802207..6ee1619da2b 100644 --- a/sys/kern/subr_witness.c +++ b/sys/kern/subr_witness.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_witness.c,v 1.37 2020/03/15 05:58:48 visa Exp $ */ +/* $OpenBSD: subr_witness.c,v 1.38 2020/11/12 05:49:26 semarie Exp $ */ /*- * Copyright (c) 2008 Isilon Systems, Inc. @@ -390,6 +390,7 @@ static int witness_locktrace = 0; #endif int witness_count = WITNESS_COUNT; +int witness_uninitialized_report = 5; static struct mutex w_mtx; static struct rwlock w_ctlock = RWLOCK_INITIALIZER("w_ctlock"); @@ -761,8 +762,19 @@ witness_checkorder(struct lock_object *lock, int flags, struct witness *w, *w1; int i, j, s; - if (witness_cold || witness_watch < 1 || panicstr != NULL || - db_active || (lock->lo_flags & LO_WITNESS) == 0) + if (witness_cold || witness_watch < 1 || panicstr != NULL || db_active) + return; + + if ((lock->lo_flags & LO_INITIALIZED) == 0) { + if (witness_uninitialized_report > 0) { + witness_uninitialized_report--; + printf("witness: lock_object uninitialized: %p\n", lock); + witness_debugger(1); + } + lock->lo_flags |= LO_INITIALIZED; + } + + if ((lock->lo_flags & LO_WITNESS) == 0) return; w = lock->lo_witness; |