You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lkmpg.tex
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,7 @@
62
62
63
63
\section{Introduction}
64
64
\label{sec:introduction}
65
-
The Linux Kernel Module Programming Guide is a free book; you may reproduce and/or modify it under the terms of the \href{https://opensource.org/licenses/OSL-3.0}{Open Software License}, version 3.0.
65
+
The Linux Kernel Module Programming Guide is a free book; you may reproduce or modify it under the terms of the \href{https://opensource.org/licenses/OSL-3.0}{Open Software License}, version 3.0.
66
66
67
67
This book is distributed in the hope that it would be useful, but without any warranty, without even the implied warranty of merchantability or fitness for a particular purpose.
68
68
@@ -74,7 +74,7 @@ \section{Introduction}
74
74
Please make revisions and updates available directly to the document maintainer, Jim Huang <jserv@ccns.ncku.edu.tw>.
75
75
This will allow for the merging of updates and provide consistent revisions to the Linux community.
76
76
77
-
If you publish or distribute this book commercially, donations, royalties, and/or printed copies are greatly appreciated by the author and the \href{https://tldp.org/}{Linux Documentation Project} (LDP).
77
+
If you publish or distribute this book commercially, donations, royalties, or printed copies are greatly appreciated by the author and the \href{https://tldp.org/}{Linux Documentation Project} (LDP).
78
78
Contributing in this way shows your support for free software and the LDP. If you have questions or comments, please contact the address above.
79
79
80
80
\subsection{Authorship}
@@ -170,7 +170,7 @@ \subsection{Before We Begin}
170
170
However, most stock Linux distribution kernels come with modversioning enabled.
171
171
If difficulties arise when loading the modules due to versioning errors, consider compiling a kernel with modversioning turned off.
172
172
173
-
\item Using X Window System.
173
+
\item Using the X Window System.
174
174
It is highly recommended to extract, compile, and load all the examples discussed in this guide from a console.
175
175
Working on these tasks within the X Window System is discouraged.
176
176
@@ -186,9 +186,9 @@ \subsection{Before We Begin}
186
186
Certain Linux distributions even ship with the default Linux kernel configured to support SecureBoot.
187
187
In these cases, the kernel module necessitates a signed security key.
188
188
189
-
Failing this, an attempt to insert your first ``hello world'' module would result in the message: ``\emph{ERROR: could not insert module}''.
190
-
If this message \emph{Lockdown: insmod: unsigned module loading is restricted;
191
-
see man kernel lockdown.7} appears in the \sh|dmesg| output,
189
+
Failing that, an attempt to insert your first ``hello world'' module would result in the message: ``\emph{ERROR: could not insert module}''.
190
+
If this message ``\emph{Lockdown: insmod: unsigned module loading is restricted;
191
+
see man kernel lockdown.7}'' appears in the \sh|dmesg| output,
192
192
the simplest approach involves disabling UEFI SecureBoot from the boot menu of your PC or laptop,
193
193
allowing the successful insertion of ``hello world'' module.
194
194
Naturally, an alternative involves undergoing intricate procedures such as generating keys, system key installation,
@@ -208,7 +208,7 @@ \section{Headers}
208
208
\end{codebash}
209
209
210
210
The following command provides information on the available kernel header files.
In \verb|Makefile|, \verb|$(CURDIR)| can set to the absolute pathname of the current working directory(after all \verb|-C| options are processed, if any).
267
+
In \verb|Makefile|, \verb|$(CURDIR)| can be set to the absolute pathname of the current working directory(after all \verb|-C| options are processed, if any).
268
268
See more about \verb|CURDIR| in \href{https://www.gnu.org/software/make/manual/make.html}{GNU make manual}.
Then, we can use \verb|-p| flag to print out the environment variable values from the Makefile.
295
+
Then, we can use the \verb|-p| flag to print out the environment variable values from the Makefile.
296
296
297
297
\begin{verbatim}
298
298
$ make -p | grep PWD
@@ -806,13 +806,13 @@ \subsection{Name Space}
806
806
\subsection{Code space}
807
807
\label{sec:codespace}
808
808
Memory management is a very complicated subject and the majority of O'Reilly's \href{https://www.oreilly.com/library/view/understanding-the-linux/0596005652/}{Understanding The Linux Kernel} exclusively covers memory management!
809
-
We are not setting out to be experts on memory managements, but we do need to know a couple of facts to even begin worrying about writing real modules.
809
+
We are not setting out to be experts on memory management, but we do need to know a couple of facts to even begin worrying about writing real modules.
810
810
811
811
If you have not thought about what a segfault really means, you may be surprised to hear that pointers do not actually point to memory locations.
812
812
Not real ones, anyway.
813
813
When a process is created, the kernel sets aside a portion of real physical memory and hands it to the process to use for its executing code, variables, stack, heap and other things which a computer scientist would know about.
814
814
This memory begins with 0x00000000 and extends up to whatever it needs to be.
815
-
Since the memory space for any two processes do not overlap, every process that can access a memory address, say 0xbffff978, would be accessing a different location in real physical memory! The processes would be accessing an index named 0xbffff978 which points to some kind of offset into the region of memory set aside for that particular process.
815
+
Since the memory space for any two processes does not overlap, every process that can access a memory address, say 0xbffff978, would be accessing a different location in real physical memory! The processes would be accessing an index named 0xbffff978 which points to some kind of offset into the region of memory set aside for that particular process.
816
816
For the most part, a process like our Hello, World program can't access the space of another process, although there are ways which we will talk about later.
817
817
818
818
The kernel has its own space of memory as well. Since a module is code which can be dynamically inserted and removed in the kernel (as opposed to a semi-autonomous object), it shares the kernel's codespace rather than having its own.
Because we don't get called when the file is opened or closed, there's nowhere for us to put \cpp|try_module_get| and \cpp|module_put| in this module, and if the file is opened and then the module is removed, there's no way to avoid the consequences.
1150
1150
1151
-
Here a simple example showing how to use a \verb|/proc| file.
1151
+
Here is a simple example showing how to use a \verb|/proc| file.
1152
1152
This is the HelloWorld for the \verb|/proc| filesystem.
1153
1153
There are three parts: create the file \verb|/proc/helloworld| in the function \cpp|init_module|, return a value (and a buffer) when the file \verb|/proc/helloworld| is read in the callback function \cpp|procfile_read|, and delete the file \verb|/proc/helloworld| in the function \cpp|cleanup_module|.
1154
1154
@@ -1294,7 +1294,7 @@ \section{sysfs: Interacting with your module}
1294
1294
Attributes can be exported for kobjects in the form of regular files in the filesystem.
1295
1295
Sysfs forwards file I/O operations to methods defined for the attributes, providing a means to read and write kernel attributes.
1296
1296
1297
-
An attribute definition in simply:
1297
+
A simple attribute definition:
1298
1298
1299
1299
\begin{code}
1300
1300
struct attribute {
@@ -1322,7 +1322,7 @@ \section{sysfs: Interacting with your module}
To read or write attributes, \cpp|show()| or \cpp|store()| method must be specified when declaring the attribute.
1325
+
To read or write attributes, the \cpp|show()| or \cpp|store()| method must be specified when declaring the attribute.
1326
1326
For the common cases \src{include/linux/sysfs.h} provides convenience macros (\cpp|__ATTR|, \cpp|__ATTR_RO|, \cpp|__ATTR_WO|, etc.) to make defining attributes easier as well as making code more concise and readable.
1327
1327
1328
1328
An example of a hello world module which includes the creation of a variable accessible via sysfs is given below.
0 commit comments