Find the answer to your Linux question:
Results 1 to 4 of 4
Hi everybody, This is my first thread in this forum . So i'm trying to write this (stupid?) kernel module under my Fedora Core 2 (Linux 2.6.5-1.35 : [root@host module]# ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2006
    Posts
    4

    kernel module error


    Hi everybody,

    This is my first thread in this forum .
    So i'm trying to write this (stupid?) kernel module under my Fedora Core 2 (Linux 2.6.5-1.35:

    [root@host module]# cat syscall.c

    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/fcntl.h>
    #include <asm/uaccess.h>

    MODULE_LICENSE("GPL");

    int init_module(void)
    {
    extern long sys_open(const char *filename,int flags,int mode);
    extern int sys_close(unsigned int fd);
    printk(KERN_INFO "Hello world 1.\n");
    printk(KERN_INFO"sysclose address: %x\n", (unsigned long *)sys_close);

    /*
    * A non 0 return means init_module failed; module can't be loaded.
    */
    return 0;
    }

    void cleanup_module(void)
    {
    printk(KERN_INFO "Goodbye world 1.\n");
    }

    When I compile it with the following Makefile:
    [root@host module]# cat Makefile
    obj-m += syscall.o

    all :
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

    clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(pwd) clean

    I have the following error:

    [root@host module]# make
    make -C /lib/modules/2.6.5-1.358/build M=/root/module modules
    make[1]: Entering directory `/lib/modules/2.6.5-1.358/build'
    CC [M] /root/module/syscall.o
    /root/module/syscall.c: Dans la fonction << init_module >>:
    /root/module/syscall.c:19: attention : format unsigned int, arg pointeur (arg 2)
    Building modules, stage 2.
    MODPOST
    *** Warning: "sys_close" [/root/module/syscall.ko] undefined!
    LD [M] /root/module/syscall.ko
    make[1]: Leaving directory `/lib/modules/2.6.5-1.358/build'

    How can I solve this "sys_close" problem (which is apprently not exported by the kernel)?

    Thanks a lot

    Bibo

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Try this:

    extern unsigned long sys_close;

    Since you are looking for an address (the address of sys_close system call) and the address is represented as an (unsigned) 32 bit number in 32 bit processors.

    Once you get it, it is like a function pointer but remember you can not use it: system calls are ready to be called from user space. Inside the kernel you could do it with syscall1,syscall2... macros but you shouldn't.

    Best regards

  3. #3
    Just Joined!
    Join Date
    Apr 2006
    Posts
    4

    Unhappy

    Hi Fernape,

    I have made the change you recommend me:

    int init_module(void)
    {
    extern long sys_open(const char *filename,int flags,int mode);
    extern unsigned long sys_close(unsigned int fd);
    printk(KERN_INFO "Hello world 1.\n");
    /*unsigned long *addr =sys_close; */
    printk(KERN_INFO"sysclose address: %x\n", (unsigned long *) sys_close);

    /*
    * A non 0 return means init_module failed; module can't be loaded.
    */
    return 0;
    }

    But I still have the same error:

    [root@host module]# make
    make -C /lib/modules/2.6.5-1.358/build M=/root/module modules
    make[1]: Entering directory `/lib/modules/2.6.5-1.358/build'
    CC [M] /root/module/syscall.o
    /root/module/syscall.c: Dans la fonction << init_module >>:
    /root/module/syscall.c:19: attention : format unsigned int, arg pointeur (arg 2)
    Building modules, stage 2.
    MODPOST
    *** Warning: "sys_close" [/root/module/syscall.ko] undefined!
    LD [M] /root/module/syscall.ko
    make[1]: Leaving directory `/lib/modules/2.6.5-1.358/build'

    Bibo

  4. #4
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Maybe I explained bad...

    extern unsigned long sys_close;

    int init_module(void)
    {
    /*extern long sys_open(const char *filename,int flags,int mode);
    extern unsigned long sys_close(unsigned int fd);*/
    printk(KERN_INFO "Hello world 1.\n");

    printk(KERN_INFO"sysclose address: %x\n", &sys_close);
    return 0;
    }

    You should not prototype the symbol. It is only a symbol...
    The address you get, should be identical to the value given by your System.map file.

    Best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •