global variables in modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I'm porting a kernel module (originally x86) to an OpenWRT environment (MIPS) running a 2.4 kernel. The module has multiple files.

In foo.h, there is:

--
extern kmem_cache_t *my_cache;
--


then in foo.c (includes foo.h), there is:


--
kmem_cache_t *my_cache;
--


When I loaded the module for the first time I got a segfault, which I traced to one of the first few lines of the init function:


--
my_cache = kmem_cache_create(...);
--


I spent a lot of time tearing my hair out trying to figure out why kmem_cache_create was segfaulting before realizing that I got the same behavior just setting my_cache to any value. I then discovered that if I declare my_cache as static, the problem goes away (this doesn't work for the module as a whole, since many files in the module want to access my_cache).

I'm guessing I need some special linkage macro in front of the declaration, but I can't seem to find out what on google (or could it be that I'm compiling it wrong?). The weird thing is that I'm pretty sure this code was working on x86. Can someone shed some light on how I should proceed?

Thanks,
-Bobby Holley

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux