Managing and Developing Dynamically Loadable Kernel Modules
Managing and Developing Dynamically Loadable Kernel Modules
Developing Dynamically Loadable Kernel Modules
Chapter 12 533
struct modwrapper
module_name
_wrapper = {
MODREV,
module_name
_load,
module_name
_unload,
(void (*)())NULL,
(void *)&
module_name
_conf_data,
module_name
_mod_link
};
When a DLKM module is configured as statically linked, its wrapper is
not used by the system.
Load Function int
module_name
_load (void *
arg
);
A module’s _load() function is called by the DLKM infrastructure
whenever the module is loaded from disk into active memory. The
function may be given any name (typically
module_name
_load); a
pointer to the _load() function is obtained from the module's wrapper.
The _load() function must perform any initialization tasks required by
the module before the module is logically connectedto the kernel. Typical
initialization tasks include acquiring private memory for the module and
initializing devices and data structures.
If the module is unable to initialize itself, the _load() function must
free any memory that it allocated and undo any other action that it took
prior to the failure including canceling all outstanding calls to timeout.
The _load() function should return 0 on success and an errno value on
failure.
The argument passed to the function is type-specific. The use of this
argument is described in “Initializing and Terminating DLKM Modules”
on page 538.
Unload Function int
module_name
_unload (void
*arg
);
The _unload() function is called by the DLKM infrastructure whenever
the module is about to be removed from active memory. The function may
be given any name (typically
module_name
_unload); a pointer to the
_unload() function is obtained from the module's wrapper.