1
0
mirror of https://github.com/bashrc/LKMPG.git synced 2018-06-11 03:06:54 +02:00

Change wording

This commit is contained in:
Bob Mottram
2016-03-09 16:39:04 +00:00
parent 2fdba972c9
commit 711052fe50
2 changed files with 26 additions and 63 deletions

View File

@@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2016-03-09 Wed 16:27 -->
<!-- 2016-03-09 Wed 16:38 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>The Linux Kernel Module Programming Guide</title>
@@ -182,10 +182,10 @@ for the JavaScript code in this tag.
<ul>
<li><a href="#orgheadline11">Introduction</a>
<ul>
<li><a href="#orgheadline1">Obtaining the Debian kernel</a></li>
<li><a href="#orgheadline2">What Is A Kernel Module?</a></li>
<li><a href="#orgheadline3">Kernel module package</a></li>
<li><a href="#orgheadline4">What Modules are in my Kernel?</a></li>
<li><a href="#orgheadline1">What Is A Kernel Module?</a></li>
<li><a href="#orgheadline2">Kernel module package</a></li>
<li><a href="#orgheadline3">What Modules are in my Kernel?</a></li>
<li><a href="#orgheadline4">Do I need to download and compile the kernel?</a></li>
<li><a href="#orgheadline5">How Do I Install Modules Into The Kernel?</a>
<ul>
<li><a href="#orgheadline6">Header files</a></li>
@@ -404,36 +404,8 @@ The following people have contributed corrections or good suggestions: Ignacio M
<h2 id="orgheadline11">Introduction</h2>
<div class="outline-text-2" id="text-orgheadline11">
</div><div id="outline-container-orgheadline1" class="outline-3">
<h3 id="orgheadline1">Obtaining the Debian kernel</h3>
<h3 id="orgheadline1">What Is A Kernel Module?</h3>
<div class="outline-text-3" id="text-orgheadline1">
<div class="org-src-container">
<pre class="src src-sh">mkdir -p ~/develop/kernel
<span class="org-builtin">cd</span> ~/develop/kernel
sudo apt-get -y install fakeroot build-essential devscripts
sudo apt-get -y build-dep linux
apt-get -y source linux
<span class="org-builtin">cd</span> linux-*
make -f debian/rules clean
make menuconfig
</pre>
</div>
<p>
Select <b>save</b>, enter the name <b>.config</b> then exit. The to build the kernel.
</p>
<div class="org-src-container">
<pre class="src src-sh">fakeroot make
</pre>
</div>
</div>
</div>
<div id="outline-container-orgheadline2" class="outline-3">
<h3 id="orgheadline2">What Is A Kernel Module?</h3>
<div class="outline-text-3" id="text-orgheadline2">
<p>
So, you want to write a kernel module. You know C, you've written a few normal programs to run as processes, and now you want to get to where the real action is, to where a single wild pointer can wipe out your file system and a core dump means a reboot.
</p>
@@ -444,9 +416,9 @@ What exactly is a kernel module? Modules are pieces of code that can be loaded a
</div>
</div>
<div id="outline-container-orgheadline3" class="outline-3">
<h3 id="orgheadline3">Kernel module package</h3>
<div class="outline-text-3" id="text-orgheadline3">
<div id="outline-container-orgheadline2" class="outline-3">
<h3 id="orgheadline2">Kernel module package</h3>
<div class="outline-text-3" id="text-orgheadline2">
<p>
Linux distros provide the commands <i>modprobe</i>, <i>insmod</i> and <i>depmod</i> within a package.
</p>
@@ -457,15 +429,15 @@ On Debian:
<div class="org-src-container">
<pre class="src src-sh">sudo apt-get install kmod
<pre class="src src-sh">sudo apt-get install build-essential kmod
</pre>
</div>
</div>
</div>
<div id="outline-container-orgheadline4" class="outline-3">
<h3 id="orgheadline4">What Modules are in my Kernel?</h3>
<div class="outline-text-3" id="text-orgheadline4">
<div id="outline-container-orgheadline3" class="outline-3">
<h3 id="orgheadline3">What Modules are in my Kernel?</h3>
<div class="outline-text-3" id="text-orgheadline3">
<p>
To discover what modules are already loaded within your current kernel use the command <b>lsmod</b>.
</p>
@@ -498,6 +470,14 @@ This can be a long list, and you might prefer to search for something particular
</div>
</div>
<div id="outline-container-orgheadline4" class="outline-3">
<h3 id="orgheadline4">Do I need to download and compile the kernel?</h3>
<div class="outline-text-3" id="text-orgheadline4">
<p>
For the purposes of following this guide you don't necessarily need to do that. However, it would be wise to run the examples within a test distro running on a virtual machine in order to avoid any possibility of messing up your system.
</p>
</div>
</div>
<div id="outline-container-orgheadline5" class="outline-3">
<h3 id="orgheadline5">How Do I Install Modules Into The Kernel?</h3>
<div class="outline-text-3" id="text-orgheadline5">
@@ -827,7 +807,7 @@ Here's another exercise for the reader. See that comment above the return statem
<h3 id="orgheadline16">Hello World (part 2): Hello and Goodbye</h3>
<div class="outline-text-3" id="text-orgheadline16">
<p>
As of Linux 2.4, you can rename the init and cleanup functions of your modules; they no longer have to be called init_module() and cleanup_module() respectively. This is done with the <b>module_init()</b> and <b>module_exit()</b> macros. These macros are defined in <b>linux/init.h</b>. The only caveat is that your init and cleanup functions must be defined before calling the macros, otherwise you'll get compilation errors. Here's an example of this technique:
In early kernel versions you had to use the <b>init_module</b> and <b>cleanup_module</b> functions, as in the first hello world example, but these days you can name those anything you want by using the <b>module_init</b> and <b>module_exit</b> macros. These macros are defined in <b>linux/init.h</b>. The only requirement is that your init and cleanup functions must be defined before calling the those macros, otherwise you'll get compilation errors. Here's an example of this technique:
</p>
</div>

View File

@@ -32,25 +32,6 @@ The source code and discussions should apply to most architectures, but I can't
The following people have contributed corrections or good suggestions: Ignacio Martin, David Porter, Daniele Paolo Scarpazza, Dimo Velev, Francois Audeon, Horst Schirmeier and Bob Mottram.
* Introduction
** Obtaining the Debian kernel
#+BEGIN_SRC sh
mkdir -p ~/develop/kernel
cd ~/develop/kernel
sudo apt-get -y install fakeroot build-essential devscripts
sudo apt-get -y build-dep linux
apt-get -y source linux
cd linux-*
make -f debian/rules clean
make menuconfig
#+END_SRC
Select *save*, enter the name *.config* then exit. The to build the kernel.
#+BEGIN_SRC sh
fakeroot make
#+END_SRC
** What Is A Kernel Module?
So, you want to write a kernel module. You know C, you've written a few normal programs to run as processes, and now you want to get to where the real action is, to where a single wild pointer can wipe out your file system and a core dump means a reboot.
@@ -64,7 +45,7 @@ Linux distros provide the commands /modprobe/, /insmod/ and /depmod/ within a pa
On Debian:
#+BEGIN_SRC sh
sudo apt-get install kmod
sudo apt-get install build-essential kmod
#+END_SRC
** What Modules are in my Kernel?
@@ -87,6 +68,8 @@ This can be a long list, and you might prefer to search for something particular
sudo lsmod | grep fat
#+END_SRC
** Do I need to download and compile the kernel?
For the purposes of following this guide you don't necessarily need to do that. However, it would be wise to run the examples within a test distro running on a virtual machine in order to avoid any possibility of messing up your system.
** How Do I Install Modules Into The Kernel?
When the kernel needs a feature that is not currently resident in the kernel, the kernel module daemon kmod[1] runs the *modprobe* command to load it. modprobe is passed a string in one of two forms:
@@ -284,7 +267,7 @@ Here's another exercise for the reader. See that comment above the return statem
** Hello World (part 2): Hello and Goodbye
As of Linux 2.4, you can rename the init and cleanup functions of your modules; they no longer have to be called init_module() and cleanup_module() respectively. This is done with the *module_init()* and *module_exit()* macros. These macros are defined in *linux/init.h*. The only caveat is that your init and cleanup functions must be defined before calling the macros, otherwise you'll get compilation errors. Here's an example of this technique:
In early kernel versions you had to use the *init_module* and *cleanup_module* functions, as in the first hello world example, but these days you can name those anything you want by using the *module_init* and *module_exit* macros. These macros are defined in *linux/init.h*. The only requirement is that your init and cleanup functions must be defined before calling the those macros, otherwise you'll get compilation errors. Here's an example of this technique:
*** Example: hello-2.c
#+BEGIN_SRC c