2001-02-12 15:22:01

by Ben Rush

[permalink] [raw]
Subject: Error Communicating With Module

Hello, first of all I must tell you that I do not belong to this
mailing list as of yet, so, please respond to me via [email protected].
Thank you very much in advance!

My problem is as follows:

I have added a variable named bens_variable to ksyms.c as follows:

extern int bens_variable=10;

I have then exported the variable in ksyms.c as follows:

EXPORT_SYMBOL(bens_variable);

I then recompiled the kernel as bzImage and everything went
perfectly fine. I then wrote a module for that particular kernel which
is simple and looks as follows:

#define MODULE
#define __KERNEL__
#include <linux/module.h>

int init_module(void){
printk(bens_variable);
return 0;
}

void cleanup_module(void){
printk("<1>Module Unloaded\n");
}

But, of course, whenever I try and compile the module to load it
using gcc it tells me that bens_variable is undefined - which makes sense,
however I don't see how I can compile this without typing in

extern int bens_variable;

again. How do I get my module to compile and print out the value
of bens_variable as defined within ksyms.c?

Again, please respond to me via [email protected]. Thanks again in
advance!!!

~Ben
[email protected]

******************************************************
Benjamin Rush ([email protected])
http://cse.unl.edu/~brush/
Undergradute Computer Scientist @ UNL
*******************************************************



2001-02-12 15:51:03

by Brian Gerst

[permalink] [raw]
Subject: Re: Error Communicating With Module

Ben Rush wrote:
>
> Hello, first of all I must tell you that I do not belong to this
> mailing list as of yet, so, please respond to me via [email protected].
> Thank you very much in advance!
>
> My problem is as follows:
>
> I have added a variable named bens_variable to ksyms.c as follows:
>
> extern int bens_variable=10;
>
> I have then exported the variable in ksyms.c as follows:
>
> EXPORT_SYMBOL(bens_variable);
>
> I then recompiled the kernel as bzImage and everything went
> perfectly fine. I then wrote a module for that particular kernel which
> is simple and looks as follows:
>
> #define MODULE
> #define __KERNEL__
> #include <linux/module.h>
>
> int init_module(void){
> printk(bens_variable);
> return 0;
> }
>
> void cleanup_module(void){
> printk("<1>Module Unloaded\n");
> }
>
> But, of course, whenever I try and compile the module to load it
> using gcc it tells me that bens_variable is undefined - which makes sense,
> however I don't see how I can compile this without typing in
>
> extern int bens_variable;
>
> again. How do I get my module to compile and print out the value
> of bens_variable as defined within ksyms.c?

Turn module versioning off.

--

Brian Gerst

2001-02-12 16:23:26

by Richard B. Johnson

[permalink] [raw]
Subject: Re: Error Communicating With Module

On Mon, 12 Feb 2001, Brian Gerst wrote:

> Ben Rush wrote:
> >
> > Hello, first of all I must tell you that I do not belong to this
> > mailing list as of yet, so, please respond to me via [email protected].
> > Thank you very much in advance!
> >
> > My problem is as follows:
> > I have added a variable named bens_variable to ksyms.c as follows:
> > extern int bens_variable=10;
^^^^^^

Yes. But where is this allocated?? This statement says that it's
someplace else.

Remove "extern".

[SNIPPED]
> >
> > #define MODULE
> > #define __KERNEL__
> > #include <linux/module.h>
> >

... add:

extern int bens_variable;

> > int init_module(void){
> > printk(bens_variable);
> > return 0;
> > }
> >
> > void cleanup_module(void){
> > printk("<1>Module Unloaded\n");
> > }
> >

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.