diff --git a/LKMPG-3.16.html b/LKMPG-3.16.html index ef3d425..4e601a0 100644 --- a/LKMPG-3.16.html +++ b/LKMPG-3.16.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- +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 --
-Select save, enter the name .config then exit. The to build the kernel. -
- -fakeroot make --
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.
@@ -444,9 +416,9 @@ What exactly is a kernel module? Modules are pieces of code that can be loaded aLinux distros provide the commands modprobe, insmod and depmod within a package.
@@ -457,15 +429,15 @@ On Debian:sudo apt-get install kmod +sudo apt-get install build-essential kmod
To discover what modules are already loaded within your current kernel use the command lsmod.
@@ -498,6 +470,14 @@ This can be a long list, and you might prefer to search for something particular+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. +
+-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: