-
Loadable Kernel Modules
Well after a while of reading,reading and some more reading i thought id share how-to creat a Loadable Kernel Module.
Lets begin with creating a simple C program.
%vi hello.c
#include <linux/module.h>
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined (CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/kernel.h>
int int_module (void)
{
-
connection got dropped....heres the rest.
printk (KERN_DEBUG "Hello,kernel!\n);
-
connection got dropped....heres the rest.
printk (KERN_DEBUG "Hello,kernel!\n);
return 0;
}
void cleanup_module(void)
{
-
Guys sometimes i hate friggin computers.....
Lets begin with creating a simple C program.
%vi hello.c
#include <linux/module.h>
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined (CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/kernel.h>
int int_module (void)
{
printk(KERN_DEBUG "Hello, World! \n);
return 0;
}
void cleanup_module (void)
{
printk(KERN_DEBUG "Good-bye, World! \n";
}
Now do a gcc -D__KERNEL__ -I/lib/modules/$(uname -r)/build/include -DMODULE -Wall -c hello.c -o hello.o
Next do a insmod hello.o
dmesg | tail -n1 will show you your message
lsmod will show you all of the loaded modules
rmmod will take out any module you want
-
You know, you can always delete your old posts ;) And there is always a cut and paste by writing it in vi first.
Anyway, never wrote my own kernal mod, but I have installed them a few times. This was a really good, basic tut....
-
But i think having 2 half completed posts adds character to my posts ;)
Funny enough my last one i did exactly that wrote it in vi and pasted it .
But im glad you liked my tut. It really is an intro into in to LKM.
Im getting a little better at writing them but they can be punks !
-
er, it seems there were a few typos in the code, so I fixed them?
#include <linux/module.h>
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined (CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/kernel.h>
int int_module (void)
{
printk(KERN_DEBUG "Hello, World! \n");
return 0;
}
void cleanup_module (void)
{
printk(KERN_DEBUG "Good-bye, World! \n");
}