Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


❑ listis a standard list element used by the kernel to keep all loaded modules in a doubly linked
list. Themodulesglobal variable defined inkernel/module.cis used as list header.
❑ namespecifies the name of the module. This name must be unique because it is referenced, for
example, to select the module to be unloaded. In this element, the name of the binary file is usu-
ally given without the suffix.ko — vfat, for example, for the VFAT filesystem.
❑ syms,num_syms,andcrcare used to manage the symbols exported by the module.symsis an
array ofnum_symsentries of thekernel_symboltype and is responsible for assigning identifiers
(name) to memory addresses (value):
<module.h>
struct kernel_symbol
{
unsigned long value;
const char *name;
};
crcsis also an array withnum_symsentries that store checksums for the exported symbols
needed to implement version control (see Section 7.5).
❑ When symbols are exported, the kernel considers not only symbols that may be used by all
modules regardless of their license, but also symbols that may be used only by modules with
GPL and GPL-compatible licenses. The third category consists of modules that may at present
still be used by modules with any license, but will be made GPL-only in the near future. The
gpl_syms,num_gpl_symsandgpl_crcselements are provided for GPL-only symbols, while
gpl_future_syms,num_gpl_future_symsandgpl_future_crcsserve for future GPL-only sym-
bols. They have the same meaning as the entries discussed above but are responsible for manag-
ing symbols that may be used only by GPL-compatible modules now or in the future.
Two more sets of symbols (which are for brevity’s sake omitted from the structure definition
above) are described by the structure membersunused_gpl_symsandunused_syms,together
with the corresponding counter and checksum members. The sets are used to store (GPL-only)
symbols that are exported, but unused by in-tree kernel modules. The kernel prints a warning
message when an out-of-tree module nevertheless uses a symbol of this type.
❑ If a module defines new exceptions (see Chapter 4), their description is held in theextablearray.
num_exentriesspecifies the number of entries in the array.
❑ initis a pointer to a function called when the module is initialized.
❑ The binary data of a module are divided into two parts: the initialization part and the core part.
The former contains everything that can be discarded after loading has terminated (e.g., the ini-
tialization functions). The latter contains all dataneeded during the current operation. The start
address of the initialization part is held inmodule_initand comprisesinit_sizebytes, whereas
the core area is described bymodule_coreandcore_size.
❑ archis a processor-specific hook that, depending on the particular system, can be filled with
various additional data needed to run modules. Most architectures do not require any addi-
tional information and therefore definestruct mod_arch_specificas an empty structure that is
removed by the compiler during optimization.
❑ taintsis set if a module taints the kernel.Taintingmeans that the kernel suspects the module
of doing something harmful that could prevent correct kernel operation. Should a kernel panic^9

(^9) A kernel panic is triggered when a fatal internal error occurs that does not allow resumption of regular operations.

Free download pdf