ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?
#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.
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.
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.
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.