MODULE(9)
β¨ MODULE(9) β¨
okay bestie, this is the section 9 page about module β the struct that describes a kernel module. it's from the Kernel Developer's Manual, so grab your iced coffee and let's get into it π«Ά
π NAME π
module β the structure that describes a kernel module β¨
πΈ DESCRIPTION πΈ
so every module in the kernel is described by a module_t structure. what's in it? the name of the device, a unique ID number, a pointer to an event handler function, and a pointer to an argument that gets handed to that event handler β plus some kernel internal data. ngl there's a lot going on in there.
and if the event handler function is NULL? no problem, the module just uses a no-operation function handler instead. easy. π
the DECLARE_MODULE(9) macro is what registers the module with the system. that's the main character move. π
when the module is loaded, the event handler function gets called with the what argument set to MOD_LOAD. okay so far so good.
on unload it's first called with what set to MOD_QUIESCE. here's the tea: if the unload wasn't forced, a non-zero return will prevent the unload from happening. so return non-zero if you're not ready to leave, periodt. β
if the unload continues, what is set to MOD_UNLOAD. and if the module returns non-zero to this one? the unload will not happen. simple as that.
now this is the part everyone gets confused about, so listen up π β the difference between MOD_QUIESCE and MOD_UNLOAD:
- the module should fail
MOD_QUIESCEif it is currently in use - whereas
MOD_UNLOADshould only fail if it is impossible to unload the module β for instance, because there are memory references to the module which cannot be revoked
like, in-use vs. literally-cannot-let-go. different vibes entirely. π
when the system is shutting down, what contains the value of MOD_SHUTDOWN. yeah, that happens too.
and for unsupported and unrecognized values of what? the module should return EOPNOTSUPP. that's it, that's the answer. π
π¦ EXAMPLES π¦
here's the whole thing in action, and yes you can copy it exactly:
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
static int foo_handler(module_t mod, int /*modeventtype_t*/ what,
void *arg);
static moduledata_t mod_data= {
"foo",
foo_handler,
NULL
};
MODULE_VERSION(foo, 1);
MODULE_DEPEND(foo, bar, 1, 3, 4);
DECLARE_MODULE(foo, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);
iconic. ate. no notes. π₯
π SEE ALSO π
DECLARE_MODULE(9)DEV_MODULE(9)DRIVER_MODULE(9)MODULE_DEPEND(9)MODULE_PNP_INFO(9)MODULE_VERSION(9)SYSCALL_MODULE(9)/usr/share/examples/kld
π AUTHORS π
This manual page was written by Alexander Langer <alex@FreeBSD.org>.
that's the whole page bestie, go forth and load some modules ππ¦β¨
β this one's from the Debian crew, dated November 11, 2021 (the version is right there in the footer, iykyk) π
π¦ 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