Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 7: Modules


Chapter 7: Modules..........................................................


first and most widely used Open Source licenses.^3 A major problem is the fact that for a variety of
reasons — which may or may not be sensible and justified — many hardware manufacturers keep
the documentation needed to control their add-on devices under wraps or require developers to sign
‘‘nondisclosure agreements‘‘ in which they, in turn, promise to keep secret the source code they write
using information in the documentation and not to reveal it to the public. This means that the driver
cannot be included in official kernel sources whose source code is always open.

This problem can be solved — at least from a technical point of view — by using binary modules that
are passed on in compiled form only but not in source code. Control of proprietary hardware is possible
using this approach, but most kernel developers are not happy with this situation because using open
code has many advantages. The sweeping success of the Linux kernel is certainly a prime example.

Modules can be inserted almost seamlessly into the kernel, as illustrated in Figure 7-1. The module code
exports functions that can be used by other kernel modules (and also by code permanently compiled into
the kernel). The link between the module and the remaining parts of the kernel can, of course, be broken
when the code needs to be unloaded; I discuss the technical details in the sections below.

Code

Exported
Functions

Code

Exported
Functions

Code

Exported
Functions

Module Compiled in

Kernelspace

insmod rmmod Userspace
Figure 7-1: Modules in the kernel.

7.2 Using Modules


To add and remove modules, there are several system calls that are normally addressed using the tools
of themodutilspackage that is installed on practically every system.^4

7.2.1 Adding and Removing


From the user point of view, modules can be added into a running kernel by two different system
programs:modprobeandinsmod. The former takes into account the dependencies that arise between indi-
vidual modules when a module depends on the functions of one or more partner modules. In contrast,
insmodloads only a single module into the kernel, and this module may depend only on the code already

(^3) To counter the criticisms levied by license purists: GPL does not, of course, stand for Open Source but for free software. However,
because the details are of a legal rather than a technical nature, I do not consider them here.
(^4) Notice that during the development of kernel 2.5, the module implementation was revised from top to bottom. The userspace inter-
face differs completely from the old version, which also necessitated a full rewrite of themodutils.

Free download pdf