LKM Newbie with some problems

LKM Newbie with some problems

Post by O. Mat » Tue, 30 Jul 2002 01:06:45



Hi,

I'm new to Linux Kernel programming, and I need some help on kernel
module programming.

I'm beginning with a simple and useless piece of code :

--- snip

#define __KERNEL__
#define MODULE

#include <linux/module.h>
#include <linux/config.h>

#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/smp.h>
#include <linux/major.h>

#include <asm/processor.h>
#include <asm/msr.h>
#include <asm/uaccess.h>
#include <asm/system.h>

#define MY_MAJOR 119

int init_module (void);
void cleanup_module(void);
static int test_read(struct inode *inode,
        struct file *file, char *buffer, int count);

static struct file_operations test_fops =
{
        NULL, test_read, NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  
        NULL,  NULL,  NULL,  NULL

Quote:};

int init_module (void)
{
        printk("Hello kernel\n");
        if (register_chrdev(MY_MAJOR,"test",&test_fops))
        {
                printk("test: unable to get major %d\n",MY_MAJOR);
                return -EIO;
        }
        return 0;

Quote:}

void cleanup_module(void)
{
        unregister_chrdev(MY_MAJOR,"test");
        printk("Bye Kernel\n");

Quote:}

static int test_read(struct inode *inode,
        struct file *file, char *buffer, int count)
{
        int temp;

//      if ((temp=verify_area(VERIFY_WRITE,buffer,1)) != 0)
//      return 0;

        copy_to_user(buffer,banner,1);
        return 1;

Quote:}

---- snip

As you can see, I try to write a character device driver.
So, here are the problems :

        when I compile it with gcc -c myhack.c, then I try to
        load it with insmod myhack.o

        First, insmod tells me that myhack.o is from a different
        kernel version. How do I specify manually that my kernel
        version is 2.4.18-686 and not 2.4.18 ?

        Then, insmod says that he can't load the module because
        he can't links to 'prefetch'

        What is prefetch ? I guess that this dependency problem is
        related of the different kernel versions. So how do I
        solve this dependency ?

        Finaly, do I need to need to use verify_area() ?
        I have to complain that VERIFY_WRITE is on my computer
        undefined...

Thanks for your help.

--
Olivier Matt, alias Init64
$a+=(~$a^$a)>>((log((~$a|$a)+1)/log(2)-1)); # Remplir & dcaler


 
 
 

1. problems with lkm, (modstat)

Hi all!

i just upgrade to 3.1-STABLE

Any ideas why im getting device not configured, when i run modstat?

Thank you.

Guadalajara:</root>% ll /dev/lkm
8629 crw-r--r--  1 root  wheel  -  32,   0 Mar  9 14:43 /dev/lkm
Guadalajara:</root>% modstat
modstat: /dev/lkm: Device not configured
Guadalajara:</root>%

2. prompt

3. LKM compile problem

4. ASPSeek 1.2.6 released

5. LKM system calls.

6. SU: NO SHELL - Help me

7. Looking for home based Linux LKM and socket based application project

8. Bison and Flex libs? Where are they?

9. Getting the CPU load value in a LKM...

10. LKM: Linux Emulator Q

11. Generating a simple sound (f.e. "beep") in a LKM - 2.2.12

12. chkrootkit report : LKM trojan?

13. LKM failure