KLDLOAD(2)

✨ KLDLOAD(2) β€” the kldload girlies' guide ✨

okay bestie, so you're reading kldload(2), which is a section-2 system call from the System Calls Manual, and it's genuinely iconic, no cap. it's giving "let me shove a whole kernel module into the kernel at runtime" energy and honestly? obsessed. πŸ’–


🌸 NAME 🌸

kldload β€” load KLD files into the kernel πŸ’…

like literally that's it, that's the whole vibe. you hand it a file, the kernel linker takes it, slay.


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc) πŸŽ€

so yeah, just link the normal libc, she's built in, you don't need to do anything extra. periodt.


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/linker.h>

int
kldload(const char *file);

yes the includes are both there, you need both, don't skip <sys/linker.h>, i will know. πŸ™ˆ


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, the kldload() system call loads a kld file into the kernel using the kernel linker. that's the whole job. one file in, kernel linker does its thing, main character energy all around. ⭐

it is not deep, it is not complicated, it is just very very powerful, which is why we're gonna be respectful about it. 🫢


πŸ’œ RETURN VALUES πŸ’œ

if everything goes right, kldload() returns the fileid of the kld file which was loaded into the kernel. remember that number, bestie, that's your little receipt. 🧾✨

but if an error occurs? kldload() will return -1 and set errno to indicate the error. classic. so check your errno, always, every time, i'm not asking. 😀


πŸ’€ ERRORS πŸ’€

the named file is loaded unless one of these little gremlins shows up:

  • [EPERM] β€” you do not have access to read the file or link it with the kernel. you should be the root user to be able to use the kld system calls. yes, root. yes, actually. sorry babe. πŸ‘‘
  • [EFAULT] β€” bad address encountered when adding kld info into the kernel space. that address was not it. πŸ’€
  • [ENOMEM] β€” there is no memory to load the file into the kernel. she's full, there's no room, the club is at capacity. 😭
  • [ENOENT] β€” the file was not found. it's not there. it never was. ghosted. πŸ«₯
  • [ENOEXEC] β€” the file format of file was unrecognized. wrong file, wrong vibe, unrecognized format, we can't work with this. πŸ™…
  • [EEXIST] β€” the supplied file has already been loaded. she's already here, bestie, she's been here, stop trying to double-book her. πŸ’…
heads up: those first one is a permission thing β€” if you're not root, don't be surprised when the kld system calls tell you no. it's not personal, it's just privileges. πŸŽ€

πŸ”— SEE ALSO πŸ”—

the whole friend group, go say hi:


πŸ“œ HISTORY πŸ“œ

the kld interface first appeared in FreeBSD 3.0. she's been around. she's a legacy icon. she ate and left no crumbs. πŸ”₯


okay that's the whole page!! mwah πŸ’–

this one came from the Debian crew, dated March 3, 1999, and it's the KLDLOAD(2) page β€” so yeah, it's old enough to be your cool aunt, but the vibes are still immaculate. love that for us. πŸŒΈπŸ¦‹βœ¨

πŸ“¦ where this page comes from