mirror of https://github.com/tLDP/LDP
updated
This commit is contained in:
parent
aa593058de
commit
1acf0d8ad7
|
@ -2956,7 +2956,7 @@ This HOWTO has been removed for review. </Para>
|
|||
Module-HOWTO</ULink>,
|
||||
<CiteTitle>Linux Loadable Kernel Module HOWTO</CiteTitle>
|
||||
</Para><Para>
|
||||
<CiteTitle>Updated: Jan 2005</CiteTitle>.
|
||||
<CiteTitle>Updated: Jul 2005</CiteTitle>.
|
||||
Explains what Linux loadable kernel modules (LKMs) are,
|
||||
and how to use and create them. </Para>
|
||||
</ListItem>
|
||||
|
|
|
@ -527,7 +527,7 @@ Crash Dump) package. </Para>
|
|||
Module-HOWTO</ULink>,
|
||||
<CiteTitle>Linux Loadable Kernel Module HOWTO</CiteTitle>
|
||||
</Para><Para>
|
||||
<CiteTitle>Updated: Jan 2005</CiteTitle>.
|
||||
<CiteTitle>Updated: Jul 2005</CiteTitle>.
|
||||
Explains what Linux loadable kernel modules (LKMs) are,
|
||||
and how to use and create them. </Para>
|
||||
</ListItem>
|
||||
|
|
|
@ -335,7 +335,7 @@ point for more information. </Para>
|
|||
Module-HOWTO</ULink>,
|
||||
<CiteTitle>Linux Loadable Kernel Module HOWTO</CiteTitle>
|
||||
</Para><Para>
|
||||
<CiteTitle>Updated: Jan 2005</CiteTitle>.
|
||||
<CiteTitle>Updated: Jul 2005</CiteTitle>.
|
||||
Explains what Linux loadable kernel modules (LKMs) are,
|
||||
and how to use and create them. </Para>
|
||||
</ListItem>
|
||||
|
|
|
@ -17,9 +17,19 @@
|
|||
|
||||
</author>
|
||||
|
||||
<pubdate>January 12, 2005</pubdate>
|
||||
<pubdate>2005-07-20</pubdate>
|
||||
|
||||
<revhistory>
|
||||
<revision>
|
||||
<revnumber>v1.07</revnumber>
|
||||
<date>2005-07-20</date>
|
||||
<authorinitials>bjh</authorinitials>
|
||||
<revremark>
|
||||
Add some 2.6 info and disclaimers.
|
||||
Update references to Linux Device Drivers
|
||||
book, Linux Kernel Module Programming Guide.
|
||||
</revremark>
|
||||
</revision>
|
||||
<revision>
|
||||
<revnumber>v1.06</revnumber>
|
||||
<date>2005-01-12</date>
|
||||
|
@ -550,6 +560,15 @@ If it does work, though, the way to prove to yourself that you know what
|
|||
you're doing is to look at <filename>/proc/modules</filename> as
|
||||
described in <xref linkend="procmodules">.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Note that the examples in this section are from Linux 2.4. In Linux 2.6,
|
||||
the technical aspects of loading LKMs are considerably different, and
|
||||
the most visible manifestation of this is that the LKM file has a suffix
|
||||
of ".ko" instead of ".o". From the user point of
|
||||
view, it looks quite similar, though.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Now lets look at a more difficult insertion. If you try
|
||||
<screen>
|
||||
|
@ -574,6 +593,12 @@ to list every symbol that is exported by the kernel (i.e. available
|
|||
for binding to LKMs). You will see that 'fat_date_unix2dos' is
|
||||
nowhere in the list.
|
||||
</para>
|
||||
|
||||
<para>(In Linux 2.6, there is no <filename>/proc/ksyms</filename>. Use
|
||||
<filename>/proc/kallsyms</filename> instead; the format is like the
|
||||
output of <command>nm</command>: look for symbols labelled "t").
|
||||
</para>
|
||||
|
||||
<para>
|
||||
How do you get it into the list? By loading another LKM, one which
|
||||
defines those symbols and exports them. In this case, it is the LKM
|
||||
|
@ -888,9 +913,9 @@ Kernel Module Loader
|
|||
</title>
|
||||
<para>
|
||||
There is some documentation of the kernel module loader in the file
|
||||
<filename>Documentation/kmod.txt</filename> in the Linux source tree.
|
||||
As of this writing, this section is more complete and accurate than
|
||||
that file. You can also look at its source code in
|
||||
<filename>Documentation/kmod.txt</filename> in the Linux 2.4 source
|
||||
tree. This section is more complete and accurate than that file. You
|
||||
can also look at its source code in
|
||||
<filename>kernel/kmod.c</filename>.
|
||||
</para>
|
||||
<para>
|
||||
|
@ -1665,7 +1690,21 @@ base kernel's <function>register_chrdev</function> subroutine. This
|
|||
is not a system call, but an ordinary subroutine bound into the base
|
||||
kernel. Calling it means branching to its address. So how does our
|
||||
LKM, which was not compiled anywhere near the base kernel, know that
|
||||
address? The answer to this is <command>insmod</command> relocation.
|
||||
address? The answer to this is the relocation that happens at
|
||||
<command>insmod</command> time.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
How that relocation happens is fundamentally different between Linux
|
||||
2.4 and Linux 2.6. In 2.6, <command>insmod</command> pretty much just
|
||||
passes the verbatim contents of the LKM file (.ko file) to the kernel
|
||||
and the kernel does the relocation. In 2.4, <command>insmod</command> does
|
||||
the relocation and passes a fully linked module image, ready to stuff
|
||||
into kernel memory, to the kernel. <emphasis>The description below
|
||||
covers the 2.4 case.</emphasis>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<command>insmod</command> functions as a relocating linker/loader.
|
||||
The LKM object file contains an external reference to the symbol
|
||||
<varname>register_chrdev</varname>. <command>insmod</command> does a
|
||||
|
@ -1804,9 +1843,10 @@ kernel, in hexadecimal.
|
|||
<para>
|
||||
<command>ksymoops</command> looks at the hexadecimal addresses, looks
|
||||
them up in the kernel symbol table (which you see in
|
||||
<filename>/proc/ksyms</filename>, and translates the addresses in the
|
||||
oops message to symbolic addresses, which you might be able to look
|
||||
up in an assembler listing.
|
||||
<filename>/proc/ksyms</filename> (Linux 2.4) or
|
||||
<filename>/proc/kallsyms</filename> (Linux 2.6), and translates the
|
||||
addresses in the oops message to symbolic addresses, which you might
|
||||
be able to look up in an assembler listing.
|
||||
</para>
|
||||
<para>
|
||||
So lets say you have an LKM crash on you. The oops message contains
|
||||
|
@ -1822,9 +1862,9 @@ get the loadpoints and lengths of the various sections of the LKM from
|
|||
the kernel symbol table.
|
||||
</para>
|
||||
<para>
|
||||
Well, <command>insmod</command> knows those addresses, so it just
|
||||
creates symbols for them and includes them in the symbols it loads
|
||||
with the LKM.
|
||||
Well, in Linux 2.4, <command>insmod</command> knows those addresses,
|
||||
so it just creates symbols for them and includes them in the symbols
|
||||
it loads with the LKM.
|
||||
</para>
|
||||
<para>
|
||||
In particular, those symbols are named (and you can see this for
|
||||
|
@ -1880,6 +1920,9 @@ in Linux's <filename>linux/version.h</filename> file. For example,
|
|||
The value of this symbol is meaningless.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
In Linux 2.6, it works differently. (I haven't figured out how yet).
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
|
@ -2063,13 +2106,19 @@ Writing Your Own Loadable Kernel Module
|
|||
</title>
|
||||
<para>
|
||||
<ulink url="http://tldp.org/LDP/lkmpg"><citetitle>The Linux Kernel
|
||||
Module Programming Guide</citetitle></ulink> by Ori Pomerantz (Lkmpg) is a
|
||||
complete explanation of writing your own LKM. This book is also
|
||||
available in print.
|
||||
Module Programming Guide</citetitle></ulink> by Peter J Salzman,
|
||||
Michael Burian, and Ori Pomerantz is a complete explanation of writing
|
||||
your own LKM. This book is also available in print. There are two
|
||||
versions of it: one for Linux 2.4, and another for 2.6.
|
||||
</para>
|
||||
<para>
|
||||
We will not duplicate information in that document, but here are
|
||||
Here are a few things about writing an LKM that aren't in there.
|
||||
At one time, the Linux 2.4 version of this document was rather out of
|
||||
date and contained an error or two.
|
||||
</para>
|
||||
<para>
|
||||
Here are a few things about writing an LKM that, at least at one time,
|
||||
weren't in there. Let the author of the LKM HOWTO know if it's still
|
||||
true. If not, he can remove this section from the LKM HOWTO.
|
||||
</para>
|
||||
|
||||
<sect2>
|
||||
|
@ -2220,12 +2269,12 @@ changes.
|
|||
|
||||
<sect2>
|
||||
<title>
|
||||
Rubini & Corbet: Linux Device Drivers
|
||||
Rubini: Linux Device Drivers
|
||||
</title>
|
||||
<para>
|
||||
The most popular book on writing device drivers is O'Reilly's
|
||||
<citetitle>Linux Device Drivers</citetitle> by Alessandro
|
||||
Rubini and Jonathan Corbet.
|
||||
Rubini, Jonathan Corbet, and Greg Kroah-Hartman.
|
||||
</para>
|
||||
<para>
|
||||
Even if you're writing an LKM that isn't a device driver, you can learn
|
||||
|
@ -2234,12 +2283,27 @@ a lot from this book that will help you.
|
|||
<para>
|
||||
The first edition of this book covers Linux 2.0, with notes about
|
||||
differences in 2.2. The second edition (June 2001) covers Linux 2.4.
|
||||
The third edition (April 2005) covers Linux 2.6. Of course, if you know
|
||||
anything about Linux, you know that a book like this doesn't perfectly
|
||||
cover any release, because Linux changes frequently. Linux 2.6 as was
|
||||
current a month after the Third Edition was released had significant
|
||||
differences from the Linux 2.6 about which the book was written.
|
||||
</para>
|
||||
<para>
|
||||
This book is available under the FDL. You can read it at
|
||||
The second edition of this book is available under the FDL. You can
|
||||
read it at
|
||||
<ulink URL="http://www.xml.com/ldd/chapter/book/">
|
||||
http://www.xml.com/ldd/chapter/book/</ulink>.
|
||||
The third edition is available under the terms of the Creative Commons
|
||||
Attribution-ShareAlike license, and you'll find it at
|
||||
<ulink URL="http://lwn.net/Kernel/LDD3/">
|
||||
http://lwn.net/Kernel/LDD3/</ulink>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
This book is also available in print in any decent technical book store.
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
|
||||
|
@ -6987,5 +7051,3 @@ Copyright <trademark class="copyright">2001</trademark>.
|
|||
</sect1>
|
||||
</Article>
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue