-
April 29th, 2002, 05:24 PM
#1
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)
{
-
April 29th, 2002, 05:28 PM
#2
connection got dropped....heres the rest.
printk (KERN_DEBUG "Hello,kernel!\n);
-
April 29th, 2002, 05:28 PM
#3
connection got dropped....heres the rest.
printk (KERN_DEBUG "Hello,kernel!\n);
return 0;
}
void cleanup_module(void)
{
-
April 29th, 2002, 05:35 PM
#4
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
-
April 29th, 2002, 06:41 PM
#5
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....
\"Ignorance is bliss....
but only for your enemy\"
-- souleman
-
April 29th, 2002, 07:26 PM
#6
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 !
-
June 5th, 2004, 08:45 AM
#7
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");
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|