Module Implementation

Modules are stored in the filesystem as ELF object files and are linked to the kernel by executing the insmod program (see the later section, Section B.3). For each module, the kernel 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 B-1. 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 ...

Get Understanding the Linux Kernel, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.