Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


a userspace daemon. This daemon then seeks the apt module and inserts it into the kernel. Section 7.4
describes how this is implemented.

7.3 Inserting and Deleting Modules


Two system calls form the interface between the userspace tools and the module implementation of the
kernel:

❑ init_module— Inserts a new module into the kernel. All the userspace tool needs do is provide
the binary data. All further steps (particularly relocation and symbol resolution) are performed
in the kernel itself.
❑ delete_module— Removes a module from the kernel. A prerequisite is, of course, that the
code is no longer in use and that no other modules are employing functions exported from the
module.

There is also a function namedrequest_module(nota system call) that is used to load modules from the
kernel side. It is required not only to load modules but also to implement hotplug capabilities.

7.3.1 Module Representation


Before looking more closely at the implementation of the module-related functions, it is necessary to
explain how modules (and their properties) are represented in the kernel. As usual, a set of data struc-
tures is defined to do this.

Not surprisingly, the name of the most important structure ismodule; an instance of this structure is
allocated for each module resident in the kernel. It is defined as follows:

<module.h>

Module Representation


{
enum module_state state;

/* Member of list of modules */
struct list_head list;

/* Unique handle for this module */
char name[MODULE_NAME_LEN];
...
/* Exported symbols */
const struct kernel_symbol *syms;
unsigned int num_syms;
const unsigned long *crcs;

/* GPL-only exported symbols. */
const struct kernel_symbol *gpl_syms;
unsigned int num_gpl_syms;
const unsigned long *gpl_crcs;
...
Free download pdf