include/sync/lock_chk_types.h View source View on GitHub
struct lock_chk_map {
const struct lock_chk_class *class;
struct lock_chk_class instance_class;
_Atomic (struct lock_chk_node *) base_node;
};
struct lock_chk_held {
struct lock_chk_node *node;
void *instance;
const struct lock_chk_site *acquire_site;
uint64_t acquire_tsc;
enum irql prev_irql;
cpu_id_t cpu;
enum lock_chk_flags flags;
enum lock_chk_type type;
enum lock_chk_mode mode;
uint8_t subclass;
bool trylock;
bool raw_operation;
};
struct lock_chk_thread_data {
struct lock_chk_held held[LOCK_CHK_MAX_HELD_LOCKS];
uint8_t depth;
uint8_t thread_checked_depth;
uint8_t thread_checked_spin_depth;
};
struct lock_chk_acquire_request {
struct lock_chk_map *map;
void *instance;
const struct lock_chk_site *site;
enum lock_chk_flags flags;
enum lock_chk_type type;
enum lock_chk_mode mode;
enum lock_chk_wait_kind wait_kind;
enum irql prev_irql;
uint8_t subclass;
bool raw_operation;
bool irq_safe;
bool irqs_enabled;
bool in_irq;
bool in_nmi;
};
struct lock_chk_acquire_token {
struct lock_chk_node *node;
struct lock_chk_node *context_node;
const struct lock_chk_acquire_request *request;
struct lock_chk_thread_data *thread_data;
bool active;
};
struct lock_chk_release_request {
struct lock_chk_map *map;
void *instance;
const struct lock_chk_site *site;
enum lock_chk_flags flags;
enum lock_chk_type type;
enum lock_chk_mode mode;
};
struct lock_chk_release_token {
struct lock_chk_thread_data *thread_data;
void *instance;
uint8_t held_index;
bool active;
};
struct lock_chk_lock {
enum lock_chk_flags flags;
_Atomic bool used;
struct lock_chk_map map;
void *instance;
enum lock_chk_type type : 4;
bool initialized : 1;
bool manages_irql : 1;
bool raw_operation : 1;
};
enum lock_chk_context_bits : uint8_t {
LOCK_CHK_CTX_THREAD = 1 << 0,
LOCK_CHK_CTX_IRQ = 1 << 1,
LOCK_CHK_CTX_SPIN_DISPATCH = 1 << 2,
LOCK_CHK_CTX_SPIN_HIGH = 1 << 3,
LOCK_CHK_CTX_RAW_OPERATION = 1 << 4,
};
void lock_chk_before_acquire(struct lock_chk_acquire_token *token, const struct lock_chk_acquire_request *request);
void lock_chk_acquired(struct lock_chk_acquire_token *token);
void lock_chk_cancel(struct lock_chk_acquire_token *token);
void lock_chk_before_release(struct lock_chk_release_token *token, const struct lock_chk_release_request *request);
void lock_chk_released(struct lock_chk_release_token *token);
bool lock_chk_assert_held_deep(struct lock_chk_lock *lock, enum lock_chk_mode mode, bool want_held, const struct lock_chk_site *site);
void lock_chk_map_runtime_init(struct lock_chk_map *map, const struct lock_chk_class *class);
struct lock_chk_acquire_request lock_chk_acquire_request_make(struct lock_chk_lock *lock, const struct lock_chk_site *site, enum lock_chk_mode mode, enum lock_chk_wait_kind wait_kind, uint8_t subclass, bool raw_operation, bool irq_safe);
struct lock_chk_release_request lock_chk_release_request_make(struct lock_chk_lock *lock, const struct lock_chk_site *site, enum lock_chk_mode mode);
#define LOCK_CHK_MAX_NODES 1024
#define LOCK_CHK_MAX_EDGES 8192
#define LOCK_CHK_HASH_BUCKETS 1024
#define LOCK_CHK_MAX_HELD_LOCKS 32
#define LOCK_CHK_MAX_SPIN_DEPTH 32
#define LOCK_CHK_MAX_SUBCLASSES 8
#define LOCK_CHK_MODE_STATE_COUNT (LOCK_CHK_MAX_NODES * 2)
#define LOCK_CHK_MAP_VALUE_INIT(class_) \
((struct lock_chk_map) { \
.class = (class_), \
.instance_class = \
{ \
.name = "<instance>", \
.file = __RELFILE__, \
.line = __LINE__, \
}, \
.base_node = ATOMIC_VAR_INIT(NULL), \
})
#define LOCK_CHK_LOCK_VALUE_INIT(class_, flags_) \
((struct lock_chk_lock) { \
.flags = (flags_), \
.initialized = true, \
.used = ATOMIC_VAR_INIT(false), \
.map = LOCK_CHK_MAP_VALUE_INIT(class_), \
})