Determining 32bit or 64bit OS from a running kernel module
Hi, I want to write a kernel module which depends on the kernel type (32 or 64 bit). There are some lines of code which I want to be included in the module if and only if the kernel is 32 bit and some lines of code which should be included if kernel is 64 bit. Is there anything like #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) for this case ? I know we have CONFIG_X86_64 and CONFIG_X86_32 for x86 architecture but how do I exactly check it in my module code? Regards, Saket Sinha
Hi Saket, At code level you can check the size of a long. If you are in 32 bit it will be 4 bytes, if you are in 64 bit it will be 8 bytes. Probably there will be better ways and functions already with this test. If you want to check it you just have to include the file that has those defines and put your code under a #if . Best regards, Nuno Martins On Wed, Oct 23, 2013 at 6:46 AM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Hi,
I want to write a kernel module which depends on the kernel type (32 or 64 bit). There are some lines of code which I want to be included in the module if and only if the kernel is 32 bit and some lines of code which should be included if kernel is 64 bit.
Is there anything like #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) for this case ?
I know we have CONFIG_X86_64 and CONFIG_X86_32 for x86 architecture but how do I exactly check it in my module code?
Regards,
Saket Sinha
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Nuno Martins
On Wed, Oct 23, 2013 at 2:42 PM, Nuno Martins <nuno.m.g.martins@gmail.com>wrote:
Hi Saket,
At code level you can check the size of a long. If you are in 32 bit it will be 4 bytes, if you are in 64 bit it will be 8 bytes.
Probably there will be better ways and functions already with this test.
If you want to check it you just have to include the file that has those defines and put your code under a #if .
Best regards, Nuno Martins
On Wed, Oct 23, 2013 at 6:46 AM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Hi,
I want to write a kernel module which depends on the kernel type (32 or 64 bit). There are some lines of code which I want to be included in the module if and only if the kernel is 32 bit and some lines of code which should be included if kernel is 64 bit.
Is there anything like #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) for this case ?
I know we have CONFIG_X86_64 and CONFIG_X86_32 for x86 architecture but how do I exactly check it in my module code?
Regards,
Saket Sinha
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Nuno Martins
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi, You could see for proc fs or sys fs providing any facility that you can make use of. I am sure there has to be some. - Rohan
Hi, On Wed, Oct 23, 2013 at 1:46 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Hi,
I want to write a kernel module which depends on the kernel type (32 or 64 bit). There are some lines of code which I want to be included in the module if and only if the kernel is 32 bit and some lines of code which should be included if kernel is 64 bit.
Is there anything like #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) for this case ?
I know we have CONFIG_X86_64 and CONFIG_X86_32 for x86 architecture but how do I exactly check it in my module code?
Regards,
Saket Sinha
User space program may test the arch on the fly by `uname -m`. However, I don't know the counter part in the kernel space.
-- Cheers, Grissiom
On Wed, 23 Oct 2013 11:16:23 +0530, Saket Sinha said:
I want to write a kernel module which depends on the kernel type (32 or 64 bit)
In general, that's probably very bad software design. If you're a module, you probably shouldn't be mucking with stuff that's 32/64 bit dependent, and you should be trying to write code that doesn't care (witness the botch that most people make of ioctl parameters that aren't the same layout for 32 or 64 bit). However, it's possible you have an actual sane use case for caring inside a module.
I know we have CONFIG_X86_64 and CONFIG_X86_32 for x86 architecture but how do I exactly check it in my module code?
I'm totally failing to understand why '#ifdef CONFIG_X86_64' isn't sufficient?
I know we have CONFIG_X86_64 and CONFIG_X86_32 for x86 architecture but how do I exactly check it in my module code?
I'm totally failing to understand why '#ifdef CONFIG_X86_64' isn't sufficient?
'#ifdef CONFIG_X86_64 is working for me but I couldn't find it being used by drivers in the kernel source tree so I guessed people were doing it by some better, smarter method. Regards, Saket Sinha
On Wed, 23 Oct 2013 18:24:24 +0530, Saket Sinha said:
'#ifdef CONFIG_X86_64 is working for me but I couldn't find it being used by drivers in the kernel source tree so I guessed people were doing it by some better, smarter method.
The "better smarter method" is almost always "write code that's 32/64 bit clean". What exactly were you doing that 32 or 64 bit actually mattered?
participants (5)
-
Grissiom -
Nuno Martins -
Rohan Puri -
Saket Sinha -
Valdis.Kletnieks@vt.edu