Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


various kernel configurations that have a drastic impact on the entire code and therefore need a sepa-
rate set of modules. The following code is linked into each module during the second phase of module
compilation:

module.mod.c
MODULE_INFO(vermagic, VERMAGIC_STRING);

VERMAGIC_STRINGis a string that indicates the key features of the kernel configuration:

<vermagic.h>
#define VERMAGIC_STRING \
UTS_RELEASE " " \
MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
MODULE_VERMAGIC_MODULE_UNLOAD MODULE_ARCH_VERMAGIC

AcopyofVERMAGIC_STRINGis stored in the kernel itself and in each module; a module may only be
loaded if both variants match. This means that the following must be identical in the module and in the
kernel:

❑ The SMP configuration (enabled or not)
❑ The preemption configuration (enabled or not)
❑ The compiler version used
❑ An architecture-specific constant

On IA-32 systems, the processor type is used as the architecture-specific constant because some very
different features are available. For example, a module compiled with special optimization for Pentium 4
processors cannot be inserted into an Athlon kernel.

The kernel version is stored but is ignored when the comparison is made. Modules with different kernel
versions whose remaining version string matches can be loaded with no problem; for example, modules
of 2.6.0 can be loaded into a kernel with version 2.6.10.

7.3.4 Inserting Modules


Theinit_modulesystem call is the interface between userspace and kernel and is used to load new
modules.

kernel/module.c
asmlinkage long
sys_init_module(void __user *umod, unsigned long len, const char __user *uargs)

The call requires three parameters — a pointer to the area in user address space in which the binary
code of the module is located (umod), its length (len), and a pointer to a string that specifies the module
parameters. From the userspace viewpoint, inserting a module is very simple because all that need be
done is to read in the module binary code and to issue a system call.

SystemCall Implementation


Figure 7-4 shows the code flow diagram forsys_init_module.
Free download pdf