Skip to content

spinlock

include/sync/spinlock.h View source View on GitHub
struct spinlock_acq_scope (3 fields) source
§ struct lock_chk_acq_req req
§ struct lock_chk_acq_token token
§ bool checked
struct spinlock_rel_scope (3 fields) source
§ struct lock_chk_rel_req req
§ struct lock_chk_rel_token token
§ bool checked
struct spinlock_acq_scope (1 field) source
§ char unused_
struct spinlock_rel_scope (1 field) source
§ char unused_
struct spinlock_guard (2 fields) source

Scoped guards. TSA can’t connect guard variables to lock expressions. IRQL_RAISED is acquired on entry and released on cleanup, and this prevents sleeping inside the guard. Lock expression is evaluated twice, remember to pass a lock address

§ struct spinlock *lock
§ enum irql irql
void spinlock_init_chk_full(
    struct spinlock *lock,
    const struct lock_chk_class *class,
    enum lock_chk_flags flags
)
source
void spinlock_policy_init_internal(
    struct spinlock *lock,
    enum lock_chk_flags flags
)
source
void spinlock_shallow_init_internal(struct spinlock *lock)
source
void spinlock_map_init_internal(
    struct spinlock *lock,
    const struct lock_chk_class *class,
    enum lock_chk_flags flags
)
source
void spinlock_note_use(
    struct spinlock *lock,
    enum lock_op_flags flags
)
source
bool spinlock_order_checked(struct spinlock *lock)
source
void spinlock_stamp(struct spinlock *lock)
source
TODO

unify stamping at initialization too

void spinlock_classify(
    struct spinlock *lock,
    enum lock_op_flags usage,
    const struct lock_chk_site *site
)
source
bool spinlock_deep_checked(struct spinlock *lock)
source
struct lock_chk_acq_req spinlock_chk_acq_req(
    struct spinlock *lock,
    const struct lock_chk_site *site,
    enum lock_subclass subclass,
    enum lock_op_flags flags
)
source
struct lock_chk_rel_req spinlock_chk_rel_req(
    struct spinlock *lock,
    const struct lock_chk_site *site
)
source
void spinlock_acq_begin(
    struct spinlock_acq_scope *scope,
    struct spinlock *lock,
    const struct lock_chk_site *site,
    enum lock_subclass subclass,
    enum lock_op_flags flags
)
source
void spinlock_acq_commit(struct spinlock_acq_scope *scope)
source
void spinlock_acq_abort(struct spinlock_acq_scope *scope)
source
void spinlock_rel_begin(
    struct spinlock_rel_scope *scope,
    struct spinlock *lock,
    const struct lock_chk_site *site
)
source
void spinlock_rel_commit(struct spinlock_rel_scope *scope)
source
void spinlock_shallow_push(
    struct spinlock *lock,
    enum irql irql,
    const struct lock_chk_site *site
)
source
void spinlock_shallow_validate_top(
    struct spinlock *lock,
    enum irql old,
    const struct lock_chk_site *site
)
source
void spinlock_shallow_pop(struct spinlock *lock)
source
bool spinlock_assert_held_deep(
    struct spinlock *lock,
    bool want_held,
    const struct lock_chk_site *site
)
source
void spinlock_assert_initialized(struct spinlock *lock)
source
void spinlock_policy_set_internal(
    struct spinlock *lock,
    enum lock_chk_flags flags
)
source
void spinlock_policy_init_internal(
    struct spinlock *lock,
    enum lock_chk_flags flags
)
source
void spinlock_shallow_init_internal(struct spinlock *lock)
source
void spinlock_map_init_internal(
    struct spinlock *lock,
    const struct lock_chk_class *class,
    enum lock_chk_flags flags
)
source
void spinlock_note_use(
    struct spinlock *lock,
    enum lock_op_flags flags
)
source
bool spinlock_order_checked(struct spinlock *lock)
source
void spinlock_classify(
    struct spinlock *lock,
    enum lock_op_flags usage,
    const struct lock_chk_site *site
)
source
bool spinlock_deep_checked(struct spinlock *lock)
source
void spinlock_acq_begin(
    struct spinlock_acq_scope *scope,
    struct spinlock *lock,
    const struct lock_chk_site *site,
    enum lock_subclass subclass,
    enum lock_op_flags flags
)
source
void spinlock_acq_commit(struct spinlock_acq_scope *scope)
source
void spinlock_acq_abort(struct spinlock_acq_scope *scope)
source
void spinlock_rel_begin(
    struct spinlock_rel_scope *scope,
    struct spinlock *lock,
    const struct lock_chk_site *site
)
source
void spinlock_rel_commit(struct spinlock_rel_scope *scope)
source
void spinlock_shallow_push(
    struct spinlock *lock,
    enum irql irql,
    const struct lock_chk_site *site
)
source
void spinlock_shallow_validate_top(
    struct spinlock *lock,
    enum irql old,
    const struct lock_chk_site *site
)
source
void spinlock_shallow_pop(struct spinlock *lock)
source
bool spinlock_assert_held_deep(
    struct spinlock *lock,
    bool want_held,
    const struct lock_chk_site *site
)
source
void spinlock_assert_initialized(struct spinlock *lock)
source
void spinlock_policy_set_internal(
    struct spinlock *lock,
    enum lock_chk_flags flags
)
source
cc_warn_unused_result bool spin_trylock_physical(struct spinlock *lock)
source
void spin_lock_physical(struct spinlock *lock)
source
void spin_unlock_physical(struct spinlock *lock)
source
void spinlock_init_chk_full(
    struct spinlock *lock,
    const struct lock_chk_class *class,
    enum lock_chk_flags flags
)
source
void spinlock_restore_interrupts(bool enabled)
source
cc_warn_unused_result bool spin_trylock_raw_full(
    struct spinlock *lock,
    enum lock_subclass sc,
    const struct lock_chk_site *site
)
source
void spin_lock_raw_full(
    struct spinlock *lock,
    enum lock_subclass sc,
    const struct lock_chk_site *site
)
source
void spin_unlock_raw_full(
    struct spinlock *lock,
    const struct lock_chk_site *site
)
source
void spin_unlock_full(
    struct spinlock *lock,
    enum irql old,
    const struct lock_chk_site *site
)
source
irql spin_lock_full(
    struct spinlock *lock,
    enum lock_subclass sc,
    const struct lock_chk_site *site
)
source
irql spin_lock_high_full(
    struct spinlock *lock,
    enum lock_subclass sc,
    const struct lock_chk_site *site
)
source
cc_warn_unused_result bool spin_trylock_full(
    struct spinlock *lock,
    enum irql *out,
    enum lock_subclass sc,
    const struct lock_chk_site *site
)
source
cc_warn_unused_result bool spin_trylock_high_full(
    struct spinlock *lock,
    enum irql *out,
    enum lock_subclass sc,
    const struct lock_chk_site *site
)
source
bool spinlock_locked(struct spinlock *lock)
source
void spinlock_set_chk_flags(
    struct spinlock *lock,
    enum lock_chk_flags flags
)
source
void spinlock_reinit_chk(
    struct spinlock *lock,
    const struct lock_chk_class *class,
    enum lock_chk_flags flags
)
source
void spinlock_assert_held_full(
    struct spinlock *lock,
    const struct lock_chk_site *site
)
source
void spinlock_assert_not_held_full(
    struct spinlock *lock,
    const struct lock_chk_site *site
)
source
void spinlock_guard_assume(struct spinlock *lock)
source
void spinlock_guard_exit(struct spinlock_guard *g)
source
struct spinlock_guard spin_guard_enter(struct spinlock *lock)
source
struct spinlock_guard spin_guard_high_enter(struct spinlock *lock)
source
struct spinlock_guard spin_guard_high_subclass_enter(
    struct spinlock *lock,
    enum lock_subclass sc
)
source
struct spinlock_guard spin_guard_subclass_enter(
    struct spinlock *lock,
    enum lock_subclass sc
)
source
struct raw_spinlock raw
source
struct lock_chk_lock chk
source
atomic(enum lock_op_flags) irq_usage
source
#define SPINLOCK_INIT SPINLOCK_INIT_CHK(NULL, LOCK_CHKD_FULL)
source
#define SPINLOCK_DEFINE(id)
source
Expansion
#define SPINLOCK_DEFINE(id) struct spinlock id = SPINLOCK_INIT
#define SPINLOCK_DEFINE_CHK(id, class_, flags_)
source
Expansion
#define SPINLOCK_DEFINE_CHK(id, class_, flags_) \
    struct spinlock id = SPINLOCK_INIT_CHK((class_), (flags_))
#define spinlock_init_1(lock_)
source
Expansion
#define spinlock_init_1(lock_) spinlock_init_2(lock_, LOCK_CHKD_FULL)
#define spinlock_init_2(lock_, flags_)
source
Expansion
#define spinlock_init_2(lock_, flags_) \
    spinlock_init_auto_internal((lock_), (flags_))
#define spinlock_init(...)
source
Expansion
#define spinlock_init(...) PP_CALL(spinlock_init, __VA_ARGS__)
#define __SPINLOCK_SHALLOW_VALUE_INIT
source
Expansion
#define __SPINLOCK_SHALLOW_VALUE_INIT \
    , .irq_usage = ATOMIC_VAR_INIT(LOCK_OP_IRQ_NONE)
#define __SPINLOCK_LOCK_CHK_VALUE_INIT(class_, flags_)
source
Expansion
#define __SPINLOCK_LOCK_CHK_VALUE_INIT(class_, flags_) \
    , .chk = LOCK_CHK_LOCK_VALUE_INIT((class_), (flags_))
#define SPINLOCK_INIT_CHK(class_, flags_)
source
Expansion
#define SPINLOCK_INIT_CHK(class_, flags_) \
    ((struct spinlock) { \
        .raw = RAW_SPINLOCK_INIT __SPINLOCK_LOCK_CHK_VALUE_INIT( \
            (class_), (flags_)) __SPINLOCK_SHALLOW_VALUE_INIT})
#define spinlock_init_chk(lock_, class_, flags_)
source
Expansion
#define spinlock_init_chk(lock_, class_, flags_) \
    spinlock_init_chk_full((lock_), (class_), (flags_))
#define spinlock_init_auto_internal(lock_, flags_)
source
Expansion
#define spinlock_init_auto_internal(lock_, flags_) \
    do { \
        static const struct lock_chk_class __auto_class = { \
            .name = #lock_, \
            .file = __RELFILE__, \
            .line = __LINE__, \
        }; \
        spinlock_init_chk_full((lock_), &__auto_class, (flags_)); \
    } while (0)
#define __SPINLOCK_SHALLOW_VALUE_INIT
source
#define __SPINLOCK_LOCK_CHK_VALUE_INIT(class_, flags_)
source
Expansion
#define __SPINLOCK_LOCK_CHK_VALUE_INIT(class_, flags_)
#define SPINLOCK_INIT_CHK(class_, flags_)
source
Expansion
#define SPINLOCK_INIT_CHK(class_, flags_) \
    ((struct spinlock) {.raw = RAW_SPINLOCK_INIT})
#define spinlock_init_chk(lock_, class_, flags_)
source
Expansion
#define spinlock_init_chk(lock_, class_, flags_) \
    spinlock_init_chk_full((lock_), NULL, LOCK_UNCHKD)
#define spinlock_init_auto_internal(lock_, flags_)
source
Expansion
#define spinlock_init_auto_internal(lock_, flags_) \
    spinlock_init_chk_full((lock_), NULL, LOCK_UNCHKD)
#define spin_lock(lock_)
source
Expansion
#define spin_lock(lock_) \
    spin_lock_full((lock_), LOCK_SUBCLASS_PRIMARY, LOCK_CHK_SITE_HERE())
#define spin_lock_subclass(lock_, subclass_)
source
Expansion
#define spin_lock_subclass(lock_, subclass_) \
    spin_lock_full((lock_), (subclass_), LOCK_CHK_SITE_HERE())
#define spin_lock_high(lock_)
source
#define spin_lock_high_subclass(lock_, subclass_)
source
Expansion
#define spin_lock_high_subclass(lock_, subclass_) \
    spin_lock_high_full((lock_), (subclass_), LOCK_CHK_SITE_HERE())
#define spin_trylock(lock_, out_)
source
Expansion
#define spin_trylock(lock_, out_) \
    spin_trylock_full((lock_), (out_), LOCK_SUBCLASS_PRIMARY, \
                      LOCK_CHK_SITE_HERE())
#define spin_trylock_subclass(lock_, out_, subclass_)
source
Expansion
#define spin_trylock_subclass(lock_, out_, subclass_) \
    spin_trylock_full((lock_), (out_), (subclass_), LOCK_CHK_SITE_HERE())
#define spin_trylock_high(lock_, out_)
source
Expansion
#define spin_trylock_high(lock_, out_) \
    spin_trylock_high_full((lock_), (out_), LOCK_SUBCLASS_PRIMARY, \
                           LOCK_CHK_SITE_HERE())
#define spin_trylock_high_subclass(lock_, out_, subclass_)
source
Expansion
#define spin_trylock_high_subclass(lock_, out_, subclass_) \
    spin_trylock_high_full((lock_), (out_) (subclass_), LOCK_CHK_SITE_HERE())
#define spin_unlock(lock_, old_)
source
Expansion
#define spin_unlock(lock_, old_) \
    spin_unlock_full((lock_), (old_), LOCK_CHK_SITE_HERE())
#define spin_lock_raw(lock_)
source
#define spin_lock_raw_subclass(lock_)
source
Expansion
#define spin_lock_raw_subclass(lock_) \
    spin_lock_raw_full((lock_), (subclass_), LOCK_CHK_SITE_HERE())
#define spin_trylock_raw(lock_)
source
#define spin_trylock_raw_subclass(lock_)
source
Expansion
#define spin_trylock_raw_subclass(lock_) \
    spin_trylock_raw_full((lock_), (subclass_), LOCK_CHK_SITE_HERE())
#define spin_unlock_raw(lock_)
source
Expansion
#define spin_unlock_raw(lock_) \
    spin_unlock_raw_full((lock_), LOCK_CHK_SITE_HERE())
#define SPINLOCK_ASSERT_HELD_RAW(l)
source

A raw check to make sure it is locked, but could be by anyone

Expansion
#define SPINLOCK_ASSERT_HELD_RAW(l) \
    enforce(spinlock_locked(l), "spinlock not locked")
#define SPINLOCK_ASSERT_HELD(l)
source
#define SPINLOCK_ASSERT_NOT_HELD(l)
source
#define spin_guard(lock_)
source
Expansion
#define spin_guard(lock_) \
    cc_cleanup(spinlock_guard_exit) struct spinlock_guard PP_CONCAT( \
        spin_guard_, __COUNTER__) = \
        (spinlock_guard_assume(lock_), spin_guard_enter(lock_))
#define spin_guard_subclass(lock_, subclass_)
source
Expansion
#define spin_guard_subclass(lock_, subclass_) \
    cc_cleanup(spinlock_guard_exit) struct spinlock_guard PP_CONCAT( \
        spin_guard_, __COUNTER__) = \
        (spinlock_guard_assume(lock_), \
         spin_guard_subclass_enter((lock_), (subclass_)))
#define spin_guard_high(lock_)
source
Expansion
#define spin_guard_high(lock_) \
    cc_cleanup(spinlock_guard_exit) struct spinlock_guard PP_CONCAT( \
        spin_guard_high_, __COUNTER__) = \
        (spinlock_guard_assume(lock_), spin_guard_high_enter(lock_))
#define spin_guard_high_subclass(lock_, subclass_)
source
Expansion
#define spin_guard_high_subclass(lock_, subclass_) \
    cc_cleanup(spinlock_guard_exit) struct spinlock_guard PP_CONCAT( \
        spin_guard_high_, __COUNTER__) = \
        (spinlock_guard_assume(lock_), \
         spin_guard_high_enter((lock_), (subclass_)))