DECLARE_MODULE(9)
π DECLARE_MODULE β bestie edition π
okay so welcome to the DECLARE_MODULE(9) page, part of the Kernel Developer's Manual, section 9, and no I will not be normal about this one because it's literally the moment your kernel module goes from "a folder of vibes" to "registered with the actual system". πΈ
β¨ NAME β¨
DECLARE_MODULE β the kernel module declaration macro, aka the glow-up line that makes your module official π
π SYNOPSIS π
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
DECLARE_MODULE(name, moduledata_t data, sub, order);
DECLARE_MODULE_TIED(name, moduledata_t data, sub, order);
π¦ DESCRIPTION π¦
The DECLARE_MODULE() macro declares a generic kernel module. It's how you register the module with the system, and it does that by leaning on the SYSINIT() macro behind the scenes. Sneaky? No. Iconic? Yes. π
DECLARE_MODULE() is usually used within other macros β think DRIVER_MODULE(9), DEV_MODULE(9) and SYSCALL_MODULE(9). But bestie, it can absolutely be called directly too, for example if you want to implement dynamic sysctls. Main character behavior only. β¨
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. Not similar. Not close enough. Identical. π«Ά This declaration should be used by modules that depend on interfaces beyond the stable kernel KBI β like ABI emulators, or hypervisors that rely on internal kernel structures. DECLARE_MODULE() will behave like DECLARE_MODULE_TIED() when compiled with modules built with the kernel. Why do we care? Because it allows locks and other synchronization primitives to be inlined safely. π₯
Now, the arguments, one by one, because we do not skip details in this house:
nameβ the module name. It gets used in theSYSINIT()call to identify the module. That's its whole job and it does it flawlessly. πdataβ amoduledata_tstructure. It holds two main things: the official name of the module (used in themodule_tstructure) and a pointer to the event handler function of typemodeventhand_t.subβ an argument directed to theSYSINIT()macro. Valid values live in thesysinit_sub_idenumeration (peep<sys/kernel.h>) and they specify the type of system startup interfaces. TheDRIVER_MODULE(9)macro uses a value ofSI_SUB_DRIVERShere, for example, since those modules contain a driver for a device. For kernel modules loaded at runtime, a value ofSI_SUB_EXECis common.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>).
π SEE ALSO π
DEV_MODULE(9)DRIVER_MODULE(9)module(9)SYSCALL_MODULE(9)/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>. absolute legends, we stan π«Άβ¨
okay that's the whole page, go forth and declare your modules bestie, ily π
β this cutie was brought to you by Debian, dated February 13, 2018 π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2000 Alexander Langer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms