__guarded_by(9)
π
__guarded_by β a Kernel API Manual moment (that's the 9 section bestie, iykyk)
okay so. bestie. imagine a variable that is SO iconic it refuses to be touched by just anyone. it has a whole security detail. that's this. that's __guarded_by. it's the struct member / globals attribute that declares a variable is only accessible from inside the active context, and honestly? main character energy. π₯
β¨ NAME β¨
__guarded_by β the struct member and globals attribute that declares a variable is only accessible within the active context.
periodt. that's the whole vibe. π
πΈ SYNOPSIS πΈ
__guarded_by (... );
π ARGUMENTS π
...β the context lock instance pointer(s). that's it. that's the argument. π«Ά
π DESCRIPTION π
so here's the tea β β __guarded_by declares that a struct member or a global variable is ONLY accessible within the context entered by the given context lock(s). it's literally a velvet rope for your data. β¨
and the rules are very specific, ngl, so pay attention:
- read operations on the data require shared access to at least one of the context locks π
- write operations require exclusive access to ALL listed context locks π
one lock is enough to read, but you need the whole squad for a write. no cap. that's the deal.
like, here's a lil struct with one lock:
struct some_state {
spinlock_t lock;
long counter __guarded_by(lock);
};
and here's one going full "more is more" with two locks:
struct some_state {
spinlock_t lock1, lock2;
long counter __guarded_by(lock1, lock2);
};
obsessed. both of them. iconique. π
π¦ SEE ALSO π¦
the lore goes deep, bestie β there's an entire friend group:
- Kernel file
./include/linux/compiler-context-analysis.hπ (go read it, i'm serious) __pt_guarded_by(9)context_lock_struct(9)disable_context_analysis(9)enable_context_analysis(9)__no_context_analysis(9)context_unsafe(9)__context_unsafe(9)context_unsafe_alias(9)token_context_lock(9)token_context_lock_instance(9)__must_hold(9)__must_not_hold(9)__acquires(9)__cond_acquires(9)__releases(9)__cond_releases(9)__acquire(9)__release(9)__must_hold_shared(9)__acquires_shared(9)__cond_acquires_shared(9)__releases_shared(9)__acquire_shared(9)__release_shared(9)__acquire_ret(9)__acquire_shared_ret(9)
like. that's twenty-six more manpages. a whole group chat. π
π oh and one more thing β standard manpage boilerplate says you can always find this one linked through the kernel file./include/linuxand that this particular glow-up dropped October 2026, and yeah the page is literally called__guarded_by(9)in case you forgot (how?? π). stay safe out there and respect the locks. muah. ππΈπ¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms