__pt_guarded_by(9)
π __pt_guarded_by β the Kernel API Manual girlies are gonna eat this UP
Okay so bestie, we're diving into __pt_guarded_by(9) today, straight out of the Kernel API Manual, and honestly? This one is iconic. It's a struct member and globals attribute, and what it does is declare that the data your pointer points to is only accessible within the active context β like, the vibe check is enforced at compile time, no cap. π
β¨ NAME β¨
__pt_guarded_by β it's the struct member and globals attribute that declares pointed-to data is only accessible within active context. Periodt. π
πΈ SYNOPSIS πΈ
__pt_guarded_by (... );
π¦ ARGUMENTS π¦
...β the context lock instance pointer(s), like, the lock(s) that are literally holding down this whole situation π₯
π DESCRIPTION π
So here's the tea, bestie: this attribute declares that the data pointed to by the struct member pointer (or the global pointer) is only accessible within the context entered by the given context lock(s). It's giving "you shall not pass" but make it concurrency-safe. π§
And the rules? They're lowkey specific, so listen up:
- Read operations on that data require shared access to at least one of the context locks π
- Write operations require exclusive access to all of the listed context locks π
Which is honestly so fair of them. Shared reads, exclusive writes, everyone stays in their lane.
Single lock, one pointer? Simple. Slay:
struct some_state {
spinlock_t lock;
long *counter __pt_guarded_by(lock);
};
Two locks and you need both for writes? Also slay, also still just vibes:
struct some_state {
spinlock_t lock1, lock2;
long *counter __pt_guarded_by(lock1, lock2);
};
No cap, the second one is highkey the main character of the write-path rules. π
π«Ά SEE ALSO π«Ά
Okay so there are so many friends in this extended universe, and they all deserve their moment. This whole crew lives in the kernel file ./include/linux/compiler-context-analysis.h β mwah, obsessed π
__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)
Real talk bestie: these are the context-analysis annotations, so if you're skipping one, you're basically leaving the group chat on read. Don't do that. π«Ά
And that's the whole page, no notes. π This little beauty lives over at ./include/linux and it was dated October 2026 β literally stamped for the future, iykyk. Bye bestie, go annotate something safely! πβ¨π
π¦ 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