Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


sys_init_module

Insert module into kernel list

load_module

mod->init

Free initialization area
Figure 7-4: Code flow diagram for
sys_init_module.
The binary data are transferred into the kernel address space usingload_module. All required relocations
are performed, and all references are resolved. The arguments are converted into a form that is easy to
analyze (a table ofkernel_paraminstances), and an instance of themoduledata structure is created with
all the necessary information on the module.

Once themoduleinstance created in theload_modulefunction has been added to the globalmoduleslist,
all the kernel need do is to call the module initialization function and free the memory occupied by the
initialization data.

LoadingModules
The real difficulties are encountered when implementingload_module— the kernel comment ‘‘do all the
hard work’’ for the function is quite right. This is a very comprehensive function (with more than 350
lines) that assumes the following tasks:

❑ Copying module data (and arguments) from userspace into atemporarymemory location in ker-
nel address space; the relative addresses of the ELF sections are replaced with absolute addresses

Structure of the VFS


❑ Finding the positions of the (optional) sections
❑ Ensuring that the version control string and the definition ofstruct modulematch in the kernel
and module
❑ Distributing the existing sections to their final positions in memory
❑ Relocating symbols and resolving references. Any version control information linked with the
module symbols is noted.
❑ Processing the arguments of the module

load_moduleis the cornerstone of the module loader, which is why I deal in greater detail with the most
important code sections.

The information below makes frequent reference to special features of the ELF
format. The data structures made available for this format by the kernel are also
often used. Appendix E discusses both in detail.

kernel/module.c
static struct module *load_module(void __user *umod,
unsigned long len,
const char __user *uargs)
Free download pdf