KLD(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… KLD(3) β€” the kld girlies' manual page

ok so this is the KLD(3) page from the library functions manual, and it's basically the two little helper functions that let your userland app poke at kernel modules. no cap, it's short but it slaps. bestie, let's go ✨

πŸŽ€ NAME πŸŽ€

kld_isloaded, kld_load β€” kld utility functions 🧚

πŸ“š LIBRARY πŸ“š

System Utilities Library (libutil, -lutil) πŸ’–

like, that's the whole vibe. you're linking against <pink>libutil</pink> with <pink>-lutil</pink> and that's where these live.

⭐ SYNOPSIS ⭐

#include <libutil.h>

int
kld_isloaded(const char *name);

int
kld_load(const char *name);

yes bestie, that's #include <libutil.h> up top, then two functions that both hand you back an int. iconic. 🫢

🌸 DESCRIPTION 🌸

so these functions are literally here to facilitate loading kernel modules from userland applications. that's the whole job! 😭 they exist so your normal-people program doesn't have to do the scary kernel dance itself.

The kld_isloaded() function takes a name and returns a non-zero value if a module of that name is currently loaded. non-zero = yes bestie, it's there. and the name you pass is flexible in three ways:

  • the name of a module file β€” like cpufreq.ko πŸ’Ύ
  • the same name without the .ko extension β€” like cpufreq
  • the name of a module contained within that file β€” like cpu/ichss πŸ¦‹
⚠️ ok this part matters, don't skip it: only the latter will return correct results if the module is compiled into the kernel. so if it's baked into the kernel itself (not a loadable file situation), you need the cpu/ichss style name or you're gonna get lied to. iykyk πŸ’€

The kld_load() function is a simple wrapper around the kldload(2) function. like, that's it, it's a little guy holding a sign for kldload(2) πŸŽ€. and here's the exact deal: it returns zero if and only if the corresponding kldload() call succeeded or returned EEXIST (which is the signifying-that-the-requested-module-was-already-loaded situation). so <mint>already loaded counts as a win</mint>. slay. πŸ’…

πŸ”₯ SEE ALSO πŸ”₯

go read those too, they're the extended universe πŸ‘‘

πŸ¦‹ HISTORY πŸ¦‹

The kld_isloaded() and kld_load() functions first appeared in FreeBSD 6.3. vintage! ✨

πŸ’œ AUTHORS πŸ’œ

The kld_isloaded() and kld_load() functions and this manual page were written by Dag-Erling SmΓΈrgrav <des@FreeBSD.org>. give them their flowers πŸŒΈπŸ‘‘


and that's the whole page, bestie 🫢 this one came from Debian, dated February 18, 2006 β€” yeah, it's giving vintage but it still ate. go load some modules responsibly πŸ’–βœ¨

πŸ“¦ where this page comes from