__guarded_by(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __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:

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/linux and 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