LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-15-2006, 12:28 AM   #1
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Rep: Reputation: 15
help: using loaded modules


Hello!

I'm really new to all these things so please be patient with me. Here is the thing: I work on some embedded device with Linux on it. I loaded some module (LED driver) with insmod and I can see new symbols loaded into kernel symbol table with cat /proc/ksyms. I can also see new entry in /proc/devices and /proc/ioports. Now I can use this device if I make char device with mknod and use the device trough ioctl commands.

I don't want to use the driver this way because driver also exports some functions into kernel symbol table. Problem is, I don't know how to use the code this way. If I use this exported functions in my simple application, I get undefined references when the linker tries to make the executable. That is logical of course. So, how can I use functions loaded into kernel symbol table? Is there some kind of define, way to compile the application?

Regards,
 
Old 11-16-2006, 12:25 AM   #2
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Original Poster
Rep: Reputation: 15
Here is some additional info.

This is the header of the LED driver

Code:
#ifndef led_H
#define led_H

#ifdef __KERNEL__
/* Function Prototypes */
extern u32	led_off		(u32 indexLED);
extern u32	led_on		(u32 indexLED);
extern u8	led_eth_ctrl	(int eth_port, u8 ethleds);
#endif

/* IOCTLs */
#define LED_ON		_IOW('T', 1, unsigned int)
#define LED_OFF		_IOW('T', 2, unsigned int)
#define LED_ETH_PC	_IOW('T', 3, unsigned char)
#define LED_ETH_LAN	_IOW('T', 4, unsigned char)

#endif /* led_H */
I can successfully use it in my mini test app

Code:
#include "led.h"
#include <sys/ioctl.h>

int main(void){
  long f = 0;
  f = open("/dev/led", 0);
  ioctl(f, LED_ON, 0x1);
  close(f);
  return 0;
}
As you can see, module exports some functions to the linux kernel symbol table. I can see that in the implementation. How can I use this functions in my mini app? How can I call led_on or led_off without linkage problem? I can see those symbols with cat /proc/ksyms.

Regards,
 
Old 11-16-2006, 08:57 AM   #3
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 573

Rep: Reputation: 91
The short answer is, you can't.

The long answer is this: Linux is segmented. The kernel's execution and executable code runs in kernel space. Your mini-app runs in user space. There's no way to link the two so that they can just be called from one another.

That's the reason that IOCTL calls exist. They tell the kernel to execute a specific function. You're pretty much stuck with that method, for now.

You _could_ write a handy library which has the functions len_on, led_off, led_eth_ctrl, and calls the ioctls for you. That would be one way of having a userspace implementation of those library functions.
 
Old 11-16-2006, 10:03 AM   #4
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 3,685

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
I would first look carefully to see if there is not an existing library that does this. For example, it's logical to assume that XWindows/XOrg would already have this capability.

Otherwise...

Yes, there is an absolute dividing-line between kernel-space and user-space. Never the twain shall meet. A kernel module is a loadable part of the kernel, and you can never call kernel-code directly from userland. For very obvious reasons.
 
Old 11-16-2006, 01:23 PM   #5
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Original Poster
Rep: Reputation: 15
I suspected this will be the answer. I know that kernel space is totally separate from user space. But one thing keeps puzzling me. Why would somebody implement this handy functions in the driver and then export them to kernel space. Why not implement just ioctl interface? As I understand there is no other way of communicating with the driver code as trough direct writing and reading from character devices or trough ioctl calls?

I also have other drivers for DSP and Keyboard implemented similarly. There is ioctl interface and there are also those handy functions exported to the kernel. What is the purpose of those functions if they can't be used from the user space?

Regards,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
extra modules loaded dambla Linux - General 2 08-03-2006 12:57 PM
Too Many Modules Loaded XSIWILL Suse/Novell 2 02-24-2006 10:13 PM
What modules loaded in a apache2 gianh Linux - Software 0 05-27-2004 07:31 AM
Find out which modules are loaded? redneon Linux - General 8 05-25-2004 12:03 PM
Kernel 2.6.5 -> no modules loaded Spheerke Debian 4 04-07-2004 09:05 PM


All times are GMT -5. The time now is 05:01 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration