diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 72566305c47f..6a5f213c177d 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #endif +static void assert_lockmgr(struct lock_object *lock, int what); #ifdef DDB #include static void db_show_lockmgr(struct lock_object *lock); @@ -70,6 +71,7 @@ static int unlock_lockmgr(struct lock_object *lock); struct lock_class lock_class_lockmgr = { .lc_name = "lockmgr", .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_lockmgr, #ifdef DDB .lc_ddb_show = db_show_lockmgr, #endif @@ -82,6 +84,13 @@ struct lock_class lock_class_lockmgr = { * Locks provide shared/exclusive sychronization. */ +void +assert_lockmgr(struct lock_object *lock, int what) +{ + + panic("lockmgr locks do not support assertions"); +} + void lock_lockmgr(struct lock_object *lock, int how) { diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 036a2770e8d0..cb054fd38c2b 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$"); #define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK)) +static void assert_mtx(struct lock_object *lock, int what); #ifdef DDB static void db_show_mtx(struct lock_object *lock); #endif @@ -98,6 +99,7 @@ static int unlock_spin(struct lock_object *lock); struct lock_class lock_class_mtx_sleep = { .lc_name = "sleep mutex", .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, + .lc_assert = assert_mtx, #ifdef DDB .lc_ddb_show = db_show_mtx, #endif @@ -107,6 +109,7 @@ struct lock_class lock_class_mtx_sleep = { struct lock_class lock_class_mtx_spin = { .lc_name = "spin mutex", .lc_flags = LC_SPINLOCK | LC_RECURSABLE, + .lc_assert = assert_mtx, #ifdef DDB .lc_ddb_show = db_show_mtx, #endif @@ -134,6 +137,13 @@ static inline void lock_profile_init(void) static inline void lock_profile_init(void) {;} #endif +void +assert_mtx(struct lock_object *lock, int what) +{ + + mtx_assert((struct mtx *)lock, what); +} + void lock_mtx(struct lock_object *lock, int how) { diff --git a/sys/kern/kern_rmlock.c b/sys/kern/kern_rmlock.c index 276aee62606c..cbf5cc5c955b 100644 --- a/sys/kern/kern_rmlock.c +++ b/sys/kern/kern_rmlock.c @@ -71,12 +71,14 @@ static __inline void compiler_memory_barrier(void) { __asm __volatile("":::"memory"); } +static void assert_rm(struct lock_object *lock, int what); static void lock_rm(struct lock_object *lock, int how); static int unlock_rm(struct lock_object *lock); struct lock_class lock_class_rm = { .lc_name = "rm", .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, + .lc_assert = assert_rm, #if 0 #ifdef DDB .lc_ddb_show = db_show_rwlock, @@ -86,6 +88,13 @@ struct lock_class lock_class_rm = { .lc_unlock = unlock_rm, }; +static void +assert_rm(struct lock_object *lock, int what) +{ + + panic("assert_rm called"); +} + static void lock_rm(struct lock_object *lock, int how) { panic("lock_rm called"); diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 809e526c3e7a..315f8875eda1 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -59,12 +59,14 @@ CTASSERT((RW_RECURSE & LO_CLASSFLAGS) == RW_RECURSE); static void db_show_rwlock(struct lock_object *lock); #endif +static void assert_rw(struct lock_object *lock, int what); static void lock_rw(struct lock_object *lock, int how); static int unlock_rw(struct lock_object *lock); struct lock_class lock_class_rw = { .lc_name = "rw", .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_rw, #ifdef DDB .lc_ddb_show = db_show_rwlock, #endif @@ -102,6 +104,13 @@ struct lock_class lock_class_rw = { #define _rw_assert(rw, what, file, line) #endif +void +assert_rw(struct lock_object *lock, int what) +{ + + rw_assert((struct rwlock *)lock, what); +} + void lock_rw(struct lock_object *lock, int how) { diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index 8e99ee35affb..1e3f135eaf7c 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -103,6 +103,7 @@ CTASSERT(((SX_ADAPTIVESPIN | SX_RECURSE) & LO_CLASSFLAGS) == */ #define sx_recursed(sx) ((sx)->sx_recurse != 0) +static void assert_sx(struct lock_object *lock, int what); #ifdef DDB static void db_show_sx(struct lock_object *lock); #endif @@ -112,6 +113,7 @@ static int unlock_sx(struct lock_object *lock); struct lock_class lock_class_sx = { .lc_name = "sx", .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_sx, #ifdef DDB .lc_ddb_show = db_show_sx, #endif @@ -123,6 +125,13 @@ struct lock_class lock_class_sx = { #define _sx_assert(sx, what, file, line) #endif +void +assert_sx(struct lock_object *lock, int what) +{ + + sx_assert((struct sx *)lock, what); +} + void lock_sx(struct lock_object *lock, int how) { diff --git a/sys/sys/lock.h b/sys/sys/lock.h index 2a9c4aa7ddd2..a70e0771a153 100644 --- a/sys/sys/lock.h +++ b/sys/sys/lock.h @@ -57,6 +57,7 @@ struct thread; struct lock_class { const char *lc_name; u_int lc_flags; + void (*lc_assert)(struct lock_object *lock, int what); void (*lc_ddb_show)(struct lock_object *lock); void (*lc_lock)(struct lock_object *lock, int how); int (*lc_unlock)(struct lock_object *lock);