O'Reilly logo

Understanding the Linux Kernel by Marco Cesati, Daniel P. Bovet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Module Implementation

Modules are stored in the filesystem as ELF object files. The kernel considers only modules that have been loaded into RAM by the /sbin/insmod program (see Section B.3) and for each of them it allocates a memory area containing the following data:

  • A module object

  • A null-terminated string that represents the name of the module (all modules should have unique names)

  • The code that implements the functions of the module

The module object describes a module; its fields are shown in Table B-1. A simply linked list collects all module objects, where the next field of each object points to the next element in the list. The first element of the list is addressed by the module_list variable. But actually, the first element of the list is always the same: it is named kernel_module and refers to a fictitious module representing the statically linked kernel code.

Table The module Object
Type Name Description
unsigned long size_of_struct Size of module object
struct module * next Next list element
const char * name Pointer to module name
unsigned long size Module size
atomic_t uc.usecount Module usage counter
unsigned long flags Module flags
unsigned int nsyms Number of exported symbols
unsigned int ndeps Number of referenced modules
struct module_symbol * syms Table of exported symbols
struct module_ref * deps List of referenced modules
struct module_ref * refs List of referencing modules
int (*)(void) init Initialization method
void (*)(void) cleanup Cleanup method

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required