Loadable Kernel Modules
Results 1 to 7 of 7

Thread: Loadable Kernel Modules

  1. #1
    Senior Member linuxcomando's Avatar
    Join Date
    Sep 2001
    Posts
    430

    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)
    {

  2. #2
    Senior Member linuxcomando's Avatar
    Join Date
    Sep 2001
    Posts
    430
    connection got dropped....heres the rest.

    printk (KERN_DEBUG "Hello,kernel!\n);

  3. #3
    Senior Member linuxcomando's Avatar
    Join Date
    Sep 2001
    Posts
    430
    connection got dropped....heres the rest.

    printk (KERN_DEBUG "Hello,kernel!\n);

    return 0;
    }
    void cleanup_module(void)
    {

  4. #4
    Senior Member linuxcomando's Avatar
    Join Date
    Sep 2001
    Posts
    430
    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
    I toor\'d YOU!

  5. #5
    AntiOnline Senior Member souleman's Avatar
    Join Date
    Oct 2001
    Location
    Flint, MI
    Posts
    2,884
    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

  6. #6
    Senior Member linuxcomando's Avatar
    Join Date
    Sep 2001
    Posts
    430
    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 !
    I toor\'d YOU!

  7. #7
    er, it seems there were a few typos in the code, so I fixed them?



    #include &lt;linux/module.h&gt;

    #if defined(CONFIG_SMP)
    #define __SMP__
    #endif

    #if defined (CONFIG_MODVERSIONS)
    #define MODVERSIONS
    #include &lt;linux/modversions.h&gt;
    #endif

    #include &lt;linux/kernel.h&gt;

    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
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides