Find the answer to your Linux question:
Results 1 to 6 of 6
i have a character array defined in /init/main.c as char filepath[100]; i am accessing in /fs/open.c as extern char filepath[100]; now i want to access this variable in my loadable ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    1

    accessing global variables in loadable kernel modules


    i have a character array defined in /init/main.c as
    char filepath[100];

    i am accessing in /fs/open.c as
    extern char filepath[100];

    now i want to access this variable in my loadable kernel module.
    i have declared it as
    extern char filepath[100];

    but when i give a make command i get the following error

    ERROR: "filepath" [drivers/misc/chardevopen.ko] undefined!

    plz help me..

  2. #2
    Just Joined!
    Join Date
    Sep 2008
    Posts
    21

    Question sharing variable between two kernel module

    hi
    I am also in srch of this...how to share variable between two kernel module.

    thanks

  3. #3
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Are you trying to access a global variable in a user process from a kernel module??

    If you are...an easy way to do this is to print the pid(process id) and address of the global variable and past them directly to the kernel module when you load it...Hope this helps Gerard4143...


    Note you need the pid of the user process for this to work.....and you have to make sure the kernel is responding the user process for this to work...i.e. if you could hijack a system call that would do nicely

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Sep 2008
    Posts
    21

    Question use of extern variable in two kernel modules

    No i dont want to access global variable in user space from kernel module. I want to access variable defined in one of the kernel module into another kernel module. How to use extern concept so that i will get same value which is assigned in one of the kernel module in another module.

    Thanks

  6. #5
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by npchanda View Post
    No i dont want to access global variable in user space from kernel module.
    Thanks
    If you have a question npchanda you really should post it separately...you shouldn't hijack another persons posting...

    But since you did ask you can solve your question the same as above, that is by printing the variable address when you install the kernel module A and then passing the address to the other kernel module B when you install it. If you want this variable to be permanently available (and visible) in the kernel well thats a process thats probably changed since I did it...Hope this Helps Geard4143

  7. #6
    Linux Newbie
    Join Date
    Mar 2008
    Location
    Hyderabad
    Posts
    109

    Hi

    You have to export the symbol you wish to use in another module in the kernel. May be this can help.

    Linux-Kernel Archive: exporting variables across modules

Posting Permissions

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