2.10. Quick Reference
This section summarizes the kernel functions, variables, macros, and
/proc files that we've touched
on in this chapter. It is meant to act as a reference. Each item is
listed after the relevant header file, if any. A similar section
appears at the end of almost every chapter from here on, summarizing
the new symbols introduced in the chapter. Entries in this section
generally appear in the same order in which they were introduced in
User-space utilities that load modules into the running kernels and
- #include <linux/init.h>
that designate a module's initialization and cleanup
- _ _init
- _ _initdata
- _ _exit
- _ _exitdata
Markers for functions (_ _init and _
_exit) and data (_ _initdata and
_ _exitdata) that are only used at module
initialization or cleanup time. Items marked for initialization may
be discarded once initialization completes; the exit items may be
discarded if module unloading has not been configured into the
kernel. These markers work by causing the relevant objects to be
placed in a special ELF section in the executable file.
- #include <linux/sched.h>
the most important header files. This file contains definitions of
much of the kernel API used by the driver, including functions for
sleeping and numerous variable declarations.
- struct task_struct *current;
The process ID and command name for the current process.
A makefile symbol used by the kernel build system to determine which
modules should be built in the current directory.
is a sysfs directory hierarchy containing information on
currently-loaded modules. /proc/modules is the
older, single-file version of that information. Entries contain the
module name, the amount of memory each module occupies, and the usage
count. Extra strings are appended to each line to specify flags that
are currently active for the module.
An object file from the kernel source directory that describes the
environment a module was built for.
- #include <linux/module.h>
Required header. It must be included by a
- #include <linux/version.h>
header file containing information on the version of the kernel being
Integer macro, useful to
#ifdef version dependencies.
- EXPORT_SYMBOL (symbol);
- EXPORT_SYMBOL_GPL (symbol);
Macro used to export a symbol to the
kernel. The second form exports without using versioning information,
and the third limits the export to GPL-licensed modules.
Place documentation on the module in the
Macros that declare a module's initialization and
- #include <linux/moduleparam.h>
- module_param(variable, type, perm);
that creates a module parameter that can be adjusted by the user when
the module is loaded (or at boot time for built-in code). The type
can be one of bool, charp,
ulong, or intarray.
- #include <linux/kernel.h>
- int printk(const char * fmt, ...);
The analogue of printf for kernel code.