TLD_DEFINE_KEY(9)
π¦ 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 exceedTLD_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 usingTLD_DEFINE_KEYcannot exceed a page. just enough memory will be allocated for each thread on the first call totld_get_dataβ so it's efficient and cute, no cap π
π SEE ALSO π
- Kernel file
./tools/testing/selftests/bpf/prog_tests/task_local_data.h tld_create_key(9),tld_get_data(9),tld_free(9)π
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
- 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