DECLARE_MODULE(9)
π DECLARE_MODULE(9) β like, the kernel module declaration macro bestie π
okay so this is a page from the Kernel Developer's Manual (section 9, the big-kid kernel section, iykyk) and it's literally all about DECLARE_MODULE β the macro that tells your kernel "hey bestie, here's a module, please register it" π
β¨ NAME β¨
DECLARE_MODULE β the kernel module declaration macro. that's it, that's the vibe π
πΈ SYNOPSIS πΈ
the includes first, always, no skipping:
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
and then the actual stars of the show:
DECLARE_MODULE(name, moduledata_t data, sub, order);
DECLARE_MODULE_TIED(name, moduledata_t data, sub, order);
two macros, same argument shape, very demure, very mindful π¦
π₯ DESCRIPTION π₯
so DECLARE_MODULE() declares a generic kernel module. it's the thing that registers your module with the system, and it does it by using the SYSINIT() macro under the hood (yes, that one π).
fr fr, DECLARE_MODULE() is usually used inside other macros β like DRIVER_MODULE(9), DEV_MODULE(9) and SYSCALL_MODULE(9). those are the popular girlies. but you can absolutely call it directly too, for example if you wanna implement dynamic sysctls. main character energy either way π
π§ the TIED variant (the picky one)
a module declared with DECLARE_MODULE_TIED() will load only if the running kernel version (as specified by __FreeBSD_version) is identical to the one it was built on. like, exact match. no substitutions. periodt π
this declaration should be used by modules that depend on interfaces beyond the stable kernel KBI β think ABI emulators or hypervisors that rely on internal kernel structures. those ones are living dangerously, they need the strict version π
and plot twist: DECLARE_MODULE() will behave like DECLARE_MODULE_TIED() when compiled with modules built with the kernel. why? because that allows locks and other synchronization primitives to be inlined safely. slay, safety first π
π the arguments (all four of them, in order)
nameβ the module name, bestie. it gets used in theSYSINIT()call to identify the module. your name tag at the kernel party πdataβ amoduledata_tstructure. it's holding two main items: the official name of the module name (yes, that's how the page says it β it's the name that'll be used in themodule_tstructure), and a pointer to the event handler function of typemodeventhand_t. so: name + vibes-callback β¨subβ an argument directed to theSYSINIT()macro. valid values for this live in thesysinit_sub_idenumeration (see<sys/kernel.h>) and they specify the type of system startup interfaces. example time: theDRIVER_MODULE(9)macro uses a value ofSI_SUB_DRIVERShere, because those modules contain a driver for a device. and for kernel modules that are loaded at runtime, a value ofSI_SUB_EXECis common. pick your lane πorderβ an argument forSYSINIT(). it represents the KLDs order of initialization within the subsystem. valid values are defined in thesysinit_elem_orderenumeration (<sys/kernel.h>). line up in order, no cutting π§ββοΈ
π¦ SEE ALSO π¦
and the actual files, in case you wanna snoop:
/usr/include/sys/kernel.h/usr/share/examples/kld
π AUTHORS π
this manual page was written by Alexander Langer <alex@FreeBSD.org>, inspired by the KLD Facility Programming Tutorial by Andrew Reiter <arr@watson.org>. legends, both of them π«Ά
ngl, this whole thing is a Debian page dated February 13, 2018 β vintage, iconic, still eating π
that's the page, bestie β go forth and declare your modules π β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2000 Alexander Langer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms