Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

static const struct modversion_info ____versions[]
__attribute_used__
__attribute__((section("__versions"))) =
0x8533a6dd, "struct_module" ,
0x21ab58c2, "fat_detach" ,
0xd8ec2862, "__mark_inode_dirty" ,
...
0x3c15a491, "fat_dir_empty" ,
0x9a290a43, "d_instantiate" ,
};

static const char __module_depends[]
__attribute_used__
__attribute__((section(".modinfo"))) =
"depends=fat";
In the file, two variables located in different sections of the binary file are defined:

a. All symbols referenced by the module — together with the checksum that they
need and that was copied from the symbol definition in the kernel or in another
module — are stored in themodversions_infoarray in the__modversionssection.
When a module is inserted, this information is used to check whether the running
kernel has the correct versions of the required symbols.
b. A list of all modules on which the processed module depends is located in the
module_dependsarray in the.modinfosection. In our example, the VFAT module
depends on the FAT module.
It is a simple matter formodprobeto create the depends list. If module A references a
symbol that is not defined in the kernel itself but in another module B, the name of B is
noted in the depends list of A.


  1. In the last step, the kernel compiles the resulting.mod.ofile into an object file and links it
    with the existing.oobject file of the module usingld; the resulting file is namedmodule.ko
    and is the finished kernel module that can be loaded withinsmod.


7.5.2 Version Control Functions


Above I noted that the kernel uses the auxiliary functioncheck_versionto determine whether the sym-
bol versions required by a module match the versions made available by the kernel.

This function requires several parameters: a pointer to the section header of the (sechdrs)module,the
index of the__versionsection, the name of the processed symbol (symname), a pointer to the module
data structure (mod), and a pointer to the checksum (crc) that the kernel provides for the symbol and that
is supplied by__find_symbolwhen the symbol is resolved.
Free download pdf