TLD_DEFINE_KEY(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ TLD_DEFINE_KEY(9) πŸ¦‹

okay bestie, so this one's from the Kernel API Manual and it's literally the glow-up that lets you define a TLD and the global variable key that goes with it, in one little macro. main character energy fr fr πŸ’…


✨ NAME ✨

TLD_DEFINE_KEY β€” defines a TLD and a global variable key associated with the TLD. that's the whole vibe πŸŽ€


🌸 SYNOPSIS 🌸

TLD_DEFINE_KEY (key , name , size );

πŸ’– ARGUMENTS πŸ’–

  • key β€” the variable name of the key. Cannot exceed TLD_NAME_LEN (respect the limit, queen πŸ‘‘).
  • name β€” the name of the TLD.
  • size β€” the size of the TLD.

🧚 DESCRIPTION 🧚

so here's the tea: the macro can only be used in file scope. like, that's not a suggestion, that's the rule πŸ™ˆ

a global variable key of opaque type, tld_key_t, will be declared and initialized before main starts. (yes, before you even wake up, it's already that girl ✨.) use tld_key_is_err or tld_key_err_or_zero later to check if the key creation succeeded β€” always do your vibe check, bestie. then pass the key to tld_get_data to get a pointer to the TLD. and bpf programs can also fetch the same key by name, which is lowkey iconic πŸ¦‹

also important: the total size of TLDs created using TLD_DEFINE_KEY cannot exceed a page. just enough memory will be allocated for each thread on the first call to tld_get_data β€” so it's efficient and cute, no cap πŸ’€

πŸŽ€ SEE ALSO πŸŽ€


kk that's the whole page, bestie 🫢 β€” this one's straight from ./tools/testing/selftests/bpf/..., dated October 2026, and yeah, it's still TLD_DEFINE_KEY(9) periodt πŸ’œβ­

πŸ“¦ where this page comes from