@@ -6,18 +6,8 @@ The following document describes how to use Symbol Namespaces to structure the
6
6
export surface of in-kernel symbols exported through the family of
7
7
EXPORT_SYMBOL() macros.
8
8
9
- .. Table of Contents
10
-
11
- === 1 Introduction
12
- === 2 How to define Symbol Namespaces
13
- --- 2.1 Using the EXPORT_SYMBOL macros
14
- --- 2.2 Using the DEFAULT_SYMBOL_NAMESPACE define
15
- === 3 How to use Symbols exported in Namespaces
16
- === 4 Loading Modules that use namespaced Symbols
17
- === 5 Automatically creating MODULE_IMPORT_NS statements
18
-
19
- 1. Introduction
20
- ===============
9
+ Introduction
10
+ ============
21
11
22
12
Symbol Namespaces have been introduced as a means to structure the export
23
13
surface of the in-kernel API. It allows subsystem maintainers to partition
@@ -31,15 +21,15 @@ its configuration, reject loading the module or warn about a missing import.
31
21
Additionally, it is possible to put symbols into a module namespace, strictly
32
22
limiting which modules are allowed to use these symbols.
33
23
34
- 2. How to define Symbol Namespaces
35
- ==================================
24
+ How to define Symbol Namespaces
25
+ ===============================
36
26
37
27
Symbols can be exported into namespace using different methods. All of them are
38
28
changing the way EXPORT_SYMBOL and friends are instrumented to create ksymtab
39
29
entries.
40
30
41
- 2.1 Using the EXPORT_SYMBOL macros
42
- ==================================
31
+ Using the EXPORT_SYMBOL macros
32
+ ------------------------------
43
33
44
34
In addition to the macros EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(), that allow
45
35
exporting of kernel symbols to the kernel symbol table, variants of these are
@@ -57,8 +47,8 @@ refer to ``NULL``. There is no default namespace if none is defined. ``modpost``
57
47
and kernel/module/main.c make use the namespace at build time or module load
58
48
time, respectively.
59
49
60
- 2.2 Using the DEFAULT_SYMBOL_NAMESPACE define
61
- =============================================
50
+ Using the DEFAULT_SYMBOL_NAMESPACE define
51
+ -----------------------------------------
62
52
63
53
Defining namespaces for all symbols of a subsystem can be very verbose and may
64
54
become hard to maintain. Therefore a default define (DEFAULT_SYMBOL_NAMESPACE)
@@ -86,8 +76,8 @@ unit as preprocessor statement. The above example would then read::
86
76
within the corresponding compilation unit before the #include for
87
77
<linux/export.h>. Typically it's placed before the first #include statement.
88
78
89
- 2.3 Using the EXPORT_SYMBOL_GPL_FOR_MODULES() macro
90
- ===================================================
79
+ Using the EXPORT_SYMBOL_GPL_FOR_MODULES() macro
80
+ -----------------------------------------------
91
81
92
82
Symbols exported using this macro are put into a module namespace. This
93
83
namespace cannot be imported.
@@ -102,8 +92,8 @@ For example:
102
92
will limit usage of this symbol to modules whoes name matches the given
103
93
patterns.
104
94
105
- 3. How to use Symbols exported in Namespaces
106
- ============================================
95
+ How to use Symbols exported in Namespaces
96
+ =========================================
107
97
108
98
In order to use symbols that are exported into namespaces, kernel modules need
109
99
to explicitly import these namespaces. Otherwise the kernel might reject to
@@ -125,11 +115,10 @@ inspected with modinfo::
125
115
126
116
127
117
It is advisable to add the MODULE_IMPORT_NS() statement close to other module
128
- metadata definitions like MODULE_AUTHOR() or MODULE_LICENSE(). Refer to section
129
- 5. for a way to create missing import statements automatically.
118
+ metadata definitions like MODULE_AUTHOR() or MODULE_LICENSE().
130
119
131
- 4. Loading Modules that use namespaced Symbols
132
- ==============================================
120
+ Loading Modules that use namespaced Symbols
121
+ ===========================================
133
122
134
123
At module loading time (e.g. ``insmod ``), the kernel will check each symbol
135
124
referenced from the module for its availability and whether the namespace it
@@ -140,8 +129,8 @@ allow loading of modules that don't satisfy this precondition, a configuration
140
129
option is available: Setting MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=y will
141
130
enable loading regardless, but will emit a warning.
142
131
143
- 5. Automatically creating MODULE_IMPORT_NS statements
144
- =====================================================
132
+ Automatically creating MODULE_IMPORT_NS statements
133
+ ==================================================
145
134
146
135
Missing namespaces imports can easily be detected at build time. In fact,
147
136
modpost will emit a warning if a module uses a symbol from a namespace
0 commit comments