How to call a kernel inserted module from a userland program??
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to call a kernel inserted module from a userland program??
I have inserted a module having some functions defined in it. Now i have a c program in userspace andi need to call the functions in the kernel module....how to access/call these functions in the module?????
I dont know much about this but i think that you have to do IOCTL mapping of your API in user and kernel space and whenever you call function from user space then it internally calls the IOCTL and which calls the corresponding kernel mode API. So you have to just do the mapping from user space to kernel space through IOCTL.
For more info you can have a look for linux device driver by Rubin.
AFAIK you can only call it as a system call, so there must be an interface providing this, either via a wrapping glibc function or through the assembly command "int 0x80". The list of system calls is well-documented on the net:
Otherwise you'll need to create a custom system call for your needs which will be interesting as a hack, but absolutely unpractical. The general rule is that kernelspace functions are closed for access from userland (except the mentioned system calls).
Distribution: Mandriva, Red Hat, Fedora Core, MontaVista
Posts: 23
Rep:
For a user-space program to access a Kernel module a /dev entry can be used.
In user-space, the /dev entry is opened and can be accessed using IOCTL or indeed read, write methods etc. These methods are defined in the Kernel module.
In kernel-space, the Linux module needs to register itself as a driver, may be char or block device etc. This registration requires a MAJOR and MINOR device number. Using mknod your device node in /dev can be created. You need to pick a name for your device in /dev.
That is the basics, you then need to consider how to transfer data, eg. copy_to_user, copy_from_user. You'll need to concern yourself with understanding virtual address spaces.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.