LinuxQuestions.org
Visit Jeremy's Blog.
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 02-22-2007, 04:16 AM   #1
raga4223688
LQ Newbie
 
Registered: Feb 2007
Posts: 11

Rep: Reputation: 0
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?????
 
Old 02-22-2007, 05:22 AM   #2
yogeshgaur
LQ Newbie
 
Registered: Feb 2007
Posts: 3

Rep: Reputation: 0
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.
 
Old 02-24-2007, 10:54 AM   #3
deardron
Member
 
Registered: Dec 2003
Location: Russia/Iceland
Distribution: Ubuntu 6, NetBSD 3.1, Cygwin
Posts: 39

Rep: Reputation: 15
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:

http://www.lxhp.in-berlin.de/lhpsyscal.html

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).

Last edited by deardron; 02-24-2007 at 11:00 AM.
 
Old 02-25-2007, 12:02 AM   #4
raga4223688
LQ Newbie
 
Registered: Feb 2007
Posts: 11

Original Poster
Rep: Reputation: 0
can't a module be accessed from /proc filesystem??
 
Old 02-25-2007, 12:11 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
If you provide the interface. Nothing happens magically.
 
Old 02-25-2007, 10:43 AM   #6
hal_2001
LQ Newbie
 
Registered: Oct 2003
Location: UK
Distribution: Mandriva, Red Hat, Fedora Core, MontaVista
Posts: 23

Rep: Reputation: 16
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.
 
Old 08-03-2011, 01:32 PM   #7
gorg0th
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
a handy resource

This is a pretty good explanation of how to do what you're talking about, and what some of the relevant issues are.

http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN885

I had to access a kernel module I had written from a userland process and this is the route I ended using.

~g
 
  


Reply



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
Can a kernel module call the function of another kernel module sceadu Programming 3 05-02-2011 02:22 AM
how to find the priority of an inserted module in the kernel sharad Linux - Software 1 07-06-2006 06:40 AM
LXer: Linux: Tainting the Kernel From Userland LXer Syndicated Linux News 0 05-29-2006 11:54 PM
Trigger action when module is inserted (wake on lan) benjalien Debian 12 04-25-2006 01:16 AM
root file system on NFS... kernel vs. userland GUIPenguin Linux - General 0 03-22-2006 01:52 PM

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

All times are GMT -5. The time now is 05:18 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