Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: lockdebug.h,v 1.22 2020/04/10 17:16:21 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef __SYS_LOCKDEBUG_H__
     33 #define	__SYS_LOCKDEBUG_H__
     34 
     35 #ifdef _KERNEL_OPT
     36 #include "opt_lockdebug.h"
     37 #endif
     38 
     39 #if !defined(_KERNEL) && !defined(_KMEMUSER)
     40 #error "Sorry, nothing of interest to user level programs here."
     41 #endif
     42 
     43 #define	LOCKOPS_SLEEP	0
     44 #define	LOCKOPS_SPIN	1
     45 
     46 typedef void (*lockop_printer_t)(const char *, ...) __printflike(1, 2);
     47 
     48 typedef	struct lockops {
     49 	const char	*lo_name;
     50 	int		lo_type;
     51 	void		(*lo_dump)(const volatile void *, lockop_printer_t);
     52 } lockops_t;
     53 
     54 #define	LOCKDEBUG_ABORT(f, ln, l, o, m) \
     55     lockdebug_abort(f, ln, l, o, m)
     56 
     57 void	lockdebug_dismiss(void);
     58 void	lockdebug_abort(const char *, size_t, const volatile void *,
     59     lockops_t *, const char *);
     60 
     61 void	lockdebug_lock_print(void *, void (*)(const char *, ...)
     62     __printflike(1, 2));
     63 void	lockdebug_show_all_locks(void (*)(const char *, ...) __printflike(1, 2),
     64 	    const char *);
     65 void	lockdebug_show_lockstats(void (*)(const char *, ...) __printflike(1, 2));
     66 
     67 #ifdef LOCKDEBUG
     68 
     69 bool	lockdebug_alloc(const char *, size_t, volatile void *, lockops_t *,
     70     uintptr_t);
     71 void	lockdebug_free(const char *, size_t, volatile void *);
     72 void	lockdebug_wantlock(const char *, size_t, const volatile void *,
     73     uintptr_t, int);
     74 void	lockdebug_locked(const char *, size_t, volatile void *, void *,
     75     uintptr_t, int);
     76 void	lockdebug_unlocked(const char *, size_t, volatile void *,
     77     uintptr_t, int);
     78 void	lockdebug_barrier(const char *, size_t, volatile void *, int);
     79 void	lockdebug_mem_check(const char *, size_t, void *, size_t);
     80 
     81 #define	LOCKDEBUG_ALLOC(lock, ops, addr) \
     82     lockdebug_alloc(__func__, __LINE__, lock, ops, addr)
     83 #define	LOCKDEBUG_FREE(dodebug, lock) \
     84     if (dodebug) lockdebug_free(__func__, __LINE__, lock)
     85 #define	LOCKDEBUG_WANTLOCK(dodebug, lock, where, s) \
     86     if (dodebug) lockdebug_wantlock(__func__, __LINE__, lock, where, s)
     87 #define	LOCKDEBUG_LOCKED(dodebug, lock, al, where, s) \
     88     if (dodebug) lockdebug_locked(__func__, __LINE__, lock, al, where, s)
     89 #define	LOCKDEBUG_UNLOCKED(dodebug, lock, where, s) \
     90     if (dodebug) lockdebug_unlocked(__func__, __LINE__, lock, where, s)
     91 #define	LOCKDEBUG_BARRIER(lock, slp) \
     92     lockdebug_barrier(__func__, __LINE__, lock, slp)
     93 #define	LOCKDEBUG_MEM_CHECK(base, sz)	\
     94     lockdebug_mem_check(__func__, __LINE__, base, sz)
     95 
     96 #else	/* LOCKDEBUG */
     97 
     98 #define	LOCKDEBUG_ALLOC(lock, ops, addr)		false
     99 #define	LOCKDEBUG_FREE(dodebug, lock)			/* nothing */
    100 #define	LOCKDEBUG_WANTLOCK(dodebug, lock, where, s)	/* nothing */
    101 #define	LOCKDEBUG_LOCKED(dodebug, lock, al, where, s)	/* nothing */
    102 #define	LOCKDEBUG_UNLOCKED(dodebug, lock, where, s)	/* nothing */
    103 #define	LOCKDEBUG_BARRIER(lock, slp)			/* nothing */
    104 #define	LOCKDEBUG_MEM_CHECK(base, sz)			/* nothing */
    105 
    106 #endif	/* LOCKDEBUG */
    107 
    108 #endif	/* __SYS_LOCKDEBUG_H__ */
    109