Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > accessing global variables in loadable kernel modules

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 07-19-2008   #1 (permalink)
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..
swapna13 is offline  



Reply With Quote
Old 11-24-2008   #2 (permalink)
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
npchanda is offline   Reply With Quote
Old 11-25-2008   #3 (permalink)
Linux Enthusiast
 
gerard4143's Avatar
 
Join Date: Dec 2007
Location: Canada, Prince Edward Island
Posts: 630
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
gerard4143 is offline   Reply With Quote
Old 11-25-2008   #4 (permalink)
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
npchanda is offline   Reply With Quote
Old 11-25-2008   #5 (permalink)
Linux Enthusiast
 
gerard4143's Avatar
 
Join Date: Dec 2007
Location: Canada, Prince Edward Island
Posts: 630
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
gerard4143 is offline   Reply With Quote
Old 12-03-2008   #6 (permalink)
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
digvijay.gahlot is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it.
subscribe
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 06:43 AM.






© 2000 - - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.1