LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-01-2015, 07:58 PM   #1
ferite
Member
 
Registered: Jul 2014
Posts: 30

Rep: Reputation: Disabled
Load a 32bit kernel module on 64bit OS?


Hi.

Here is the scenario:

I have a third party software (SDK) that uses a kernel module to drive an infrared camera. The software are 32bit libraries of which I have not source code. The driver (kernel module) in the other hand is provided as source code. Now I have tested without problem this system on 32 bit machine. For some reasons now I must make this work on 64 bit machine.

So I installed the 32 bit support libraries for Linux (Ubuntu). With this, the software runs. But I have issues trying the software to work with the driver.

>If I build the driver against the 64 bit kernel, modprobe loads the module, but the software throws a "segmentation fault (core dumped)". Obviously there is a mismatch between 32bit software and 64 bit driver.

>If I build the driver against the 32 bit kernel, modprobe fails with "ERROR: could not insert 'moduleName': Exec format error". A 32 bit module does not simply loads on 64 bit OS.

My question is what can i do to get this work. I supposed that if 32 bit software can run on 64 bit OS, a kernel module can too, but obviously is not so simple. Is there a way to achieve this?.

Thanks.

Last edited by ferite; 06-01-2015 at 08:00 PM.
 
Old 06-01-2015, 09:16 PM   #2
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware, MX 18
Posts: 9,484
Blog Entries: 15

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Hi:

I've heard that re-compiling the kernel will get things that didn't work to work.
https://help.ubuntu.com/community/Kernel/Compile

Your program is only allowed to touch memory that belongs to it. Any access outside of those areas will cause a segmentation fault. Maybe debugging will help?

Here's a few links that may help or at least get you pointed in the right direction.
Sorry I don't know more.

http://www.cprogramming.com/debugging/segfaults.html
https://www.netbsd.org/docs/guide/en/chap-kernel.html
https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel

Debugging:-
https://wiki.ubuntu.com/DebuggingProcedures
https://wiki.ubuntu.com/Kernel/Debugging

HTH
 
Old 06-01-2015, 10:30 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,153

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Generally it should work - but ... have a read of this. Opensuse, but generally applicable.
The 32-bit API should cover most cases as it says - else the vendor needs to supply compatible binaries.
 
1 members found this post helpful.
Old 06-01-2015, 10:35 PM   #4
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware, MX 18
Posts: 9,484
Blog Entries: 15

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Thanks for the link syg00-
 
Old 06-02-2015, 05:29 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by ferite View Post
If I build the driver against the 64 bit kernel, modprobe loads the module, but the software throws a "segmentation fault (core dumped)". Obviously there is a mismatch between 32bit software and 64 bit driver.
That "obvious" conclusion would not even be my first guess. More likely, the driver contains some portability error and simply doesn't work when compiled for 64-bit. Since you have the source code, it should be possible to find and correct that portability error.

32-bit applications work with 64-bit drivers in Linux (and other OS's). A correctly designed driver interfaces with the kernel in a way that should make the issue of the application bit size invisible to the driver. The kernel takes care of dealing with the 32-bit application.

So your guess that the 32-bit application is not compatible with 64-bit driver is not easy to completely rule out, but it is also not easy for me to believe.

Quote:
I supposed that if 32 bit software can run on 64 bit OS, a kernel module can too, but obviously is not so simple. Is there a way to achieve this?.
VM so you have a 32-bit kernel in which to use the 32-bit driver. Otherwise, I'm pretty sure your assumption that a 32-bit kernel module can run in a 64-bit kernel is wrong.

Quote:
Originally Posted by syg00 View Post
Generally it should work
Which "it" is that? In context you seem to be saying a 32-bit kernel module can work in a 64-bit kernel. But then you posted a link explicitly saying it can't.

A 64-bit driver and 64-bit kernel and 32-bit application should all play well together. So hopefully that is what you meant by "it".
 
1 members found this post helpful.
Old 06-02-2015, 05:34 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,153

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Indeed - the OP basically proved the 64-bit kernel requirement.

Didn't realise I was being ambidextrous.
 
Old 06-02-2015, 06:28 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
It may also depend on any ioctls that may be implemented by the kernel module... These get translated by the 32bit ABI, but custom ioctls would not. This in turn would cause a segmentation fault in the 32bit libraries as the data being passed would be for 64 bit rather than 32 bit. The only way to find out is to trace the segmentation fault.

And 32 bit kernel modules DON'T WORK in a 64 bit kernel. The kernel internal APIs are 64 bit only.
 
Old 06-02-2015, 03:31 PM   #8
ferite
Member
 
Registered: Jul 2014
Posts: 30

Original Poster
Rep: Reputation: Disabled
Thanks all for your answers.

Quote:
Originally Posted by jpollard View Post
It may also depend on any ioctls that may be implemented by the kernel module... These get translated by the 32bit ABI, but custom ioctls would not. This in turn would cause a segmentation fault in the 32bit libraries as the data being passed would be for 64 bit rather than 32 bit. The only way to find out is to trace the segmentation fault.

And 32 bit kernel modules DON'T WORK in a 64 bit kernel. The kernel internal APIs are 64 bit only.
Unfortunately my knowledge regarding C++, and driver development is limited for making a complete diagnostics. The definitions that could be found in the header file are:

Code:
#define USB_FJVEINCAM_IOCTL_CTRLMSG 	_IOWR(0xB4,0x01,struct fjveincam_cmsg)
#define USB_FJVEINCAM_IOCTL_CHECK		_IO(0xB4,0x02)
#define USB_FJVEINCAM_IOCTL_INFO		_IOR(0xB4,0x03,struct fjveincam_info)
#define USB_FJVEINCAM_IOCTL_CONFIRM 	_IO(0xB4,0x04)

/* for USB_FJVEINCAM_IOCTL_CTRLMSG */

struct fjveincam_cmsg {
	struct {
		unsigned char bRequestType;
		unsigned char bRequest;
		unsigned short wValue;
		unsigned short wIndex;
		unsigned short wLength;
	} req;						/* USB device control request data */
	void *data; 				/* response data area pointer */
};

/* for USB_FJVEINCAM_IOCTL_CHECK */

	/* no structure */

/* for USB_FJVEINCAM_IOCTL_INFO */

/* Magic number for Fujitsu Palmsecure sensor driver. */
#define FJPV_MAGIC	0x464A5056

struct fjveincam_info {
	int magic;					/* Magic number for indicating Fujitsu Palmsecure sensor driver. */
	int minor;					/* minor number */
	int o_timeout;				/* counter of open time out */
	int r_error;				/* counter of read error */
	int r_lasterr;				/* read last error */
	int w_error;				/* counter of write error */
	int w_lasterr;				/* write last error */
	unsigned char version[8];	/* device driver version string */
};
Just for the record, I am using this with a modified kernel. Installation instructions specify CONFIG_USB_DYNAMIC_MINORS should be disabled.
 
Old 06-02-2015, 05:12 PM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
The void *data would be wrong.

In a 32 bit binary that is a 32 bit address. The driver would be assuming it got a 64 bit address - which would be invalid, and possibly be the cause of your segmentation error. It would be if the fault is traced to the ioctl.
 
Old 06-16-2015, 07:43 AM   #10
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
By far the simplest solution would be to ask the vendor for appropriate drivers. I'm not quite sure why "an infrared camera" has kernel requirements, anyway. How is this camera connected?
 
Old 06-16-2015, 08:41 AM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by sundialsvcs View Post
By far the simplest solution would be to ask the vendor for appropriate drivers. I'm not quite sure why "an infrared camera" has kernel requirements, anyway. How is this camera connected?
Even if the camera were connected via USB, there could be problems in that the application isn't using libusb to communicate with it...

I THINK (but not sure) the 32 bit version of libusb would work on a 64 bit system.
 
Old 06-16-2015, 07:22 PM   #12
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware, MX 18
Posts: 9,484
Blog Entries: 15

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
It can't hurt to re-compile the kernel and see if that works. It might just work but you won't know till you give it a go.

See here for libusb-
http://www.libusb.org/

The Infrared-HOWTO provides an introduction to Linux and infrared devices-
(not sure if this will help but none the less I looked it up.
http://www.tldp.org/HOWTO/html_single/Infrared-HOWTO/

What make and model is your camera ferite?
 
Old 11-03-2015, 05:22 PM   #13
mrtcn
LQ Newbie
 
Registered: Jan 2007
Location: London
Distribution: CentOS
Posts: 20

Rep: Reputation: 0
I've compiled the same driver for different architectures, do you still need any help?
 
Old 11-03-2015, 07:08 PM   #14
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,020

Rep: Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630
Run a virtual machine in 32 bit??
 
  


Reply

Tags
32 bits, kernel module



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sendmsg from 32bit uer to 64bit kernel jimmyting Programming 1 08-16-2012 09:24 AM
[SOLVED] build 32bit-kernel on 64bit kernel system jimmyting Linux - Software 2 06-04-2012 07:58 AM
possible to compile a 32bit kernel on a 64bit os? Shadowmeph Linux - General 5 10-02-2008 06:07 AM
Running 32bit Installation with 64bit kernel? Colombian Linux - Newbie 3 09-26-2006 06:56 AM
Cannot load DSO (32bit) in 64bit CentOS jasperphang Linux - Newbie 4 07-27-2006 04:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 07:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration