Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


*owner = mod;
ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
if (ks) {
*crc = symversion(mod->crcs, (ks - mod->syms));
return ks->value;
}

if (gplok) {
ks = lookup_symbol(name, mod->gpl_syms,
mod->gpl_syms + mod->num_gpl_syms);
if (ks) {
*crc = symversion(mod->gpl_crcs,
(ks - mod->gpl_syms));
return ks->value;
}
}

...
/* Try unused symbols etc. */
...

}
return 0;
}

Each module stores its exported symbols in themod->symsarray, which has the same structure as the
symbol array of the kernel.

If the module is GPL-compatible, all GPL-exported symbols of the modules are scanned; this is done in
exactly the same way as the above search, butmod->gpl_symsis used as the database. If this remains
unsuccessful, the kernel tries the remaining symbol sections.

The kernel sets theownerparameter of__find_symbolto the module data structure
of the second module that is presently being processed. This serves to create a
dependency between modules when a symbol is resolved with the help of another
module.

0 is returned if the kernel cannot resolve the symbol.

Let’s return toresolve_symbol.If__find_symbolis successful, the kernel first usescheck_versionto
determine whether the checksums match (this function is discussed in Section 7.5). If the symbol used
originates from another module, a dependency between the two modules is established by means of the
familiaruse_modulefunction; this prevents the referencedmodule from being removed as long as the
symbol just loaded is still in memory.

7.3.5 Removing Modules


Removing modules from the kernel is much simpler than inserting them, as shown by the code flow
diagram ofsys_delete_modulein Figure 7-6.
Free download pdf