| 1 | /* $NetBSD: lockdebug.h,v 1.14 2013/04/27 08:12:34 mlelstv 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 | #define LOCKOPS_CV 2 |
| 46 | |
| 47 | typedef struct lockops { |
| 48 | const char *lo_name; |
| 49 | int lo_type; |
| 50 | void (*lo_dump)(volatile void *); |
| 51 | } lockops_t; |
| 52 | |
| 53 | #define LOCKDEBUG_ABORT(l, o, f, m) lockdebug_abort(l, o, f, m) |
| 54 | |
| 55 | void lockdebug_abort(volatile void *, lockops_t *, |
| 56 | const char *, const char *); |
| 57 | |
| 58 | void lockdebug_lock_print(void *, void (*)(const char *, ...) |
| 59 | __printflike(1, 2)); |
| 60 | |
| 61 | #ifdef LOCKDEBUG |
| 62 | |
| 63 | bool lockdebug_alloc(volatile void *, lockops_t *, uintptr_t); |
| 64 | void lockdebug_free(volatile void *); |
| 65 | void lockdebug_wantlock(volatile void *, uintptr_t, int); |
| 66 | void lockdebug_locked(volatile void *, void *, uintptr_t, int); |
| 67 | void lockdebug_unlocked(volatile void *, uintptr_t, int); |
| 68 | void lockdebug_barrier(volatile void *, int); |
| 69 | void lockdebug_mem_check(const char *, void *, size_t); |
| 70 | void lockdebug_wakeup(volatile void *, uintptr_t); |
| 71 | |
| 72 | #define LOCKDEBUG_ALLOC(lock, ops, addr) lockdebug_alloc(lock, ops, addr) |
| 73 | #define LOCKDEBUG_FREE(dodebug, lock) \ |
| 74 | if (dodebug) lockdebug_free(lock) |
| 75 | #define LOCKDEBUG_WANTLOCK(dodebug, lock, where, s) \ |
| 76 | if (dodebug) lockdebug_wantlock(lock, where, s) |
| 77 | #define LOCKDEBUG_LOCKED(dodebug, lock, al, where, s) \ |
| 78 | if (dodebug) lockdebug_locked(lock, al, where, s) |
| 79 | #define LOCKDEBUG_UNLOCKED(dodebug, lock, where, s) \ |
| 80 | if (dodebug) lockdebug_unlocked(lock, where, s) |
| 81 | #define LOCKDEBUG_BARRIER(lock, slp) lockdebug_barrier(lock, slp) |
| 82 | #define LOCKDEBUG_MEM_CHECK(base, sz) \ |
| 83 | lockdebug_mem_check(__func__, base, sz) |
| 84 | #define LOCKDEBUG_WAKEUP(dodebug, lock, where) \ |
| 85 | if (dodebug) lockdebug_wakeup(lock, where) |
| 86 | |
| 87 | #else /* LOCKDEBUG */ |
| 88 | |
| 89 | #define LOCKDEBUG_ALLOC(lock, ops, addr) false |
| 90 | #define LOCKDEBUG_FREE(dodebug, lock) /* nothing */ |
| 91 | #define LOCKDEBUG_WANTLOCK(dodebug, lock, where, s) /* nothing */ |
| 92 | #define LOCKDEBUG_LOCKED(dodebug, lock, al, where, s) /* nothing */ |
| 93 | #define LOCKDEBUG_UNLOCKED(dodebug, lock, where, s) /* nothing */ |
| 94 | #define LOCKDEBUG_BARRIER(lock, slp) /* nothing */ |
| 95 | #define LOCKDEBUG_MEM_CHECK(base, sz) /* nothing */ |
| 96 | #define LOCKDEBUG_WAKEUP(dodebug, lock, where) /* nothing */ |
| 97 | |
| 98 | #endif /* LOCKDEBUG */ |
| 99 | |
| 100 | #endif /* __SYS_LOCKDEBUG_H__ */ |
| 101 | |