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
+26-12Lines changed: 26 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -65,18 +65,23 @@ \section{Introduction}
65
65
\label{sec:introduction}
66
66
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.
67
67
68
-
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
+
This book is distributed in the hope that it would be useful, but without any warranty,
69
+
without even the implied warranty of merchantability or fitness for a particular purpose.
69
70
70
-
The author encourages wide distribution of this book for personal or commercial use, provided the above copyright notice remains intact and the method adheres to the provisions of the \href{https://opensource.org/licenses/OSL-3.0}{Open Software License}.
71
-
In summary, you may copy and distribute this book free of charge or for a profit. No explicit permission is required from the author for reproduction of this book in any medium, physical or electronic.
71
+
The author encourages wide distribution of this book for personal or commercial use,
72
+
provided the above copyright notice remains intact and the method adheres to the provisions of the \href{https://opensource.org/licenses/OSL-3.0}{Open Software License}.
73
+
In summary, you may copy and distribute this book free of charge or for a profit.
74
+
No explicit permission is required from the author for reproduction of this book in any medium, physical or electronic.
72
75
73
76
Derivative works and translations of this document must be placed under the Open Software License, and the original copyright notice must remain intact.
74
77
If you have contributed new material to this book, you must make the material and source code available for your revisions.
75
78
Please make revisions and updates available directly to the document maintainer, Jim Huang <jserv@ccns.ncku.edu.tw>.
76
79
This will allow for the merging of updates and provide consistent revisions to the Linux community.
77
80
78
-
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).
79
-
Contributing in this way shows your support for free software and the LDP. If you have questions or comments, please contact the address above.
81
+
If you publish or distribute this book commercially, donations, royalties,
82
+
or printed copies are greatly appreciated by the author and the \href{https://tldp.org/}{Linux Documentation Project} (LDP).
83
+
Contributing in this way shows your support for free software and the LDP.
84
+
If you have questions or comments, please contact the address above.
80
85
81
86
\subsection{Authorship}
82
87
\label{sec:authorship}
@@ -536,7 +541,8 @@ \subsection{Passing Command Line Arguments to a Module}
536
541
The example code should clear up my admittedly lousy explanation.
537
542
538
543
The \cpp|module_param()| macro takes 3 arguments: the name of the variable, its type and permissions for the corresponding file in sysfs.
539
-
Integer types can be signed as usual or unsigned. If you would like to use arrays of integers or strings, see \cpp|module_param_array()| and \cpp|module_param_string()|.
544
+
Integer types can be signed as usual or unsigned. If you would like to use arrays of integers or strings,
545
+
see \cpp|module_param_array()| and \cpp|module_param_string()|.
540
546
541
547
\begin{code}
542
548
int myint = 3;
@@ -545,7 +551,8 @@ \subsection{Passing Command Line Arguments to a Module}
545
551
546
552
Arrays are supported too, but things are a bit different now than they were in the olden days.
547
553
To keep track of the number of parameters, you need to pass a pointer to a count variable as the third parameter.
548
-
At your option, you could also ignore the count and pass \cpp|NULL| instead. We show both possibilities here:
554
+
At your option, you could also ignore the count and pass \cpp|NULL| instead.
555
+
We show both possibilities here:
549
556
550
557
\begin{code}
551
558
int myintarray[2];
@@ -557,7 +564,8 @@ \subsection{Passing Command Line Arguments to a Module}
557
564
\end{code}
558
565
559
566
A good use for this is to have the module variable's default values set, like a port or IO address.
560
-
If the variables contain the default values, then perform autodetection (explained elsewhere). Otherwise, keep the current value.
567
+
If the variables contain the default values, then perform autodetection (explained elsewhere).
568
+
Otherwise, keep the current value.
561
569
This will be made clear later on.
562
570
563
571
Lastly, there is a macro function, \cpp|MODULE_PARM_DESC()|, that is used to document arguments that the module can take.
\subsection{Building modules for a precompiled kernel}
637
645
\label{sec:precompiled}
638
-
Obviously, we strongly suggest you to recompile your kernel, so that you can enable a number of useful debugging features, such as forced module unloading (\cpp|MODULE_FORCE_UNLOAD|): when this option is enabled, you can force the kernel to unload a module even when it believes it is unsafe, via a \sh|sudo rmmod -f module| command.
646
+
% TODO: Recent Linux kernel images shipped with distributions should already have sufficient debugging features enabled for LKMPG.
647
+
Obviously, we strongly suggest you to recompile your kernel, so that you can enable a number of useful debugging features,
648
+
such as forced module unloading (\cpp|MODULE_FORCE_UNLOAD|): when this option is enabled,
649
+
you can force the kernel to unload a module even when it believes it is unsafe, via a \sh|sudo rmmod -f module| command.
639
650
This option can save you a lot of time and a number of reboots during the development of a module.
640
651
If you do not want to recompile your kernel then you should consider running the examples within a test distribution on a virtual machine.
641
652
If you mess anything up then you can easily reboot or restore the virtual machine (VM).
642
653
643
-
There are a number of cases in which you may want to load your module into a precompiled running kernel, such as the ones shipped with common Linux distributions, or a kernel you have compiled in the past.
644
-
In certain circumstances you could require to compile and insert a module into a running kernel which you are not allowed to recompile, or on a machine that you prefer not to reboot.
654
+
There are a number of cases in which you may want to load your module into a precompiled running kernel,
655
+
such as the ones shipped with common Linux distributions, or a kernel you have compiled in the past.
656
+
In certain circumstances you could require to compile and insert a module into a running kernel which you are not allowed to recompile,
657
+
or on a machine that you prefer not to reboot.
645
658
If you can't think of a case that will force you to use modules for a precompiled kernel you might want to skip this and treat the rest of this chapter as a big footnote.
646
659
647
-
Now, if you just install a kernel source tree, use it to compile your kernel module and you try to insert your module into the kernel, in most cases you would obtain an error as follows:
660
+
Now, if you just install a kernel source tree, use it to compile your kernel module and you try to insert your module into the kernel,
661
+
in most cases you would obtain an error as follows:
648
662
649
663
\begin{verbatim}
650
664
insmod: ERROR: could not insert module poet.ko: Invalid module format
0 commit comments