#ifndef _SYS_WITNESS_H_
#define _SYS_WITNESS_H_
#include <sys/_lock.h>
#define LO_CLASSINDEX(lock) \
((((lock)->lo_flags) & LO_CLASSMASK) >> LO_CLASSSHIFT)
#define LOCK_CLASS(lock) \
(lock_classes[LO_CLASSINDEX((lock))])
#define LOCK_CLASS_MAX \
(LO_CLASSMASK >> LO_CLASSSHIFT)
#define LOP_NEWORDER 0x00000001
#define LOP_QUIET 0x00000002
#define LOP_TRYLOCK 0x00000004
#define LOP_EXCLUSIVE 0x00000008
#define LOP_DUPOK 0x00000010
#define LA_MASKASSERT 0x000000ff
#define LA_UNLOCKED 0x00000000
#define LA_LOCKED 0x00000001
#define LA_SLOCKED 0x00000002
#define LA_XLOCKED 0x00000004
#define LA_RECURSED 0x00000008
#define LA_NOTRECURSED 0x00000010
#ifdef _KERNEL
void witness_initialize(void);
void witness_init(struct lock_object *, const struct lock_type *);
int witness_defineorder(struct lock_object *, struct lock_object *);
void witness_checkorder(struct lock_object *, int, struct lock_object *);
void witness_lock(struct lock_object *, int);
void witness_upgrade(struct lock_object *, int);
void witness_downgrade(struct lock_object *, int);
void witness_unlock(struct lock_object *, int);
void witness_setrelative(struct lock_object *, struct lock_object *, int);
int witness_warn(int, struct lock_object *, const char *, ...);
void witness_assert(const struct lock_object *, int);
void witness_display_spinlock(struct lock_object *, struct proc *,
int (*)(const char *, ...));
void witness_norelease(struct lock_object *);
void witness_releaseok(struct lock_object *);
void witness_thread_exit(struct proc *);
int witness_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int witness_sysctl_watch(void *, size_t *, void *, size_t);
#ifdef WITNESS
#define WARN_KERNELOK 0x01
#define WARN_PANIC 0x02
#define WARN_SLEEPOK 0x04
#define WITNESS_INITIALIZE() \
witness_initialize()
#define WITNESS_INIT(lock, type) \
witness_init((lock), (type))
#define WITNESS_CHECKORDER(lock, flags, interlock) \
witness_checkorder((lock), (flags), (interlock))
#define WITNESS_DEFINEORDER(lock1, lock2) \
witness_defineorder((struct lock_object *)(lock1), \
(struct lock_object *)(lock2))
#define WITNESS_LOCK(lock, flags) \
witness_lock((lock), (flags))
#define WITNESS_UPGRADE(lock, flags) \
witness_upgrade((lock), (flags))
#define WITNESS_DOWNGRADE(lock, flags) \
witness_downgrade((lock), (flags))
#define WITNESS_UNLOCK(lock, flags) \
witness_unlock((lock), (flags))
#define WITNESS_SETCHILD(lock, child) \
witness_setrelative((lock), (child), 0)
#define WITNESS_SETPARENT(lock, parent) \
witness_setrelative((lock), (parent), 1)
#define WITNESS_CHECK(flags, lock, fmt, ...) \
witness_warn((flags), (lock), (fmt), ## __VA_ARGS__)
#define WITNESS_WARN(flags, lock, fmt, ...) \
witness_warn((flags), (lock), (fmt), ## __VA_ARGS__)
#define WITNESS_NORELEASE(lock) \
witness_norelease(&(lock)->lock_object)
#define WITNESS_RELEASEOK(lock) \
witness_releaseok(&(lock)->lock_object)
#define WITNESS_THREAD_EXIT(p) \
witness_thread_exit((p))
#else
#define WITNESS_INITIALIZE() (void)0
#define WITNESS_INIT(lock, type) (void)0
#define WITNESS_DEFINEORDER(lock1, lock2) 0
#define WITNESS_CHECKORDER(lock, flagsi, interlock) (void)0
#define WITNESS_LOCK(lock, flags) (void)0
#define WITNESS_UPGRADE(lock, flags) (void)0
#define WITNESS_DOWNGRADE(lock, flags) (void)0
#define WITNESS_UNLOCK(lock, flags) (void)0
#define WITNESS_SETCHILD(lock, child) (void)0
#define WITNESS_SETPARENT(lock, parent) (void)0
#define WITNESS_CHECK(flags, lock, fmt, ...) 0
#define WITNESS_WARN(flags, lock, fmt, ...) (void)0
#define WITNESS_NORELEASE(lock) (void)0
#define WITNESS_RELEASEOK(lock) (void)0
#define WITNESS_THREAD_EXIT(p) (void)0
#endif
#endif
#endif