Hi,
Am a new bee to linux internals.
I am trying to make a simple program witch will call a function from a
module. I made a module compiled it and INSMOD-it into kernel, that works
fine. I would like to call from my user program a function defined in my
kernel module.
Please suggest any method thro' which this could be accomplished.
The only way i did it was by running my new module as insmod mymodule.o and
get my job done.
Thanks,
Sudharsan.
On Tue, 2003-02-18 at 12:50, Sudharsan Vijayaraghavan wrote:
> Hi,
>
> Am a new bee to linux internals.
> I am trying to make a simple program witch will call a function from a
> module. I made a module compiled it and INSMOD-it into kernel, that works
> fine. I would like to call from my user program a function defined in my
> kernel module.
You never call functions directly from user-mode. You generally use a
syscall to interface between user-mode and kernel-mode. Most drivers
implement operations that map via these syscalls (i.e.
open/close/read/write etc).
What exactly are you trying to achieve?
--
Alex, homepage: http://www.bennee.com/~alex/
How much does it cost to entice a dope-smoking UNIX system guru to Dayton?
-- Brian Boyle, UNIX/WORLD's First Annual Salary Survey
On Tue, 18 Feb 2003, Sudharsan Vijayaraghavan wrote:
> Hi,
>
> Am a new bee to linux internals.
> I am trying to make a simple program witch will call a function from a
> module. I made a module compiled it and INSMOD-it into kernel, that works
> fine. I would like to call from my user program a function defined in my
> kernel module.
>
> Please suggest any method thro' which this could be accomplished.
> The only way i did it was by running my new module as insmod mymodule.o and
> get my job done.
>
> Thanks,
> Sudharsan.
Unix/Linux uses open() close() read() write() and ioctl() (plus a few
others) to interface with modules or any kind of driver. To 'call' some
module function from user-mode, you impliment open() and close(). That
will provide a file-descriptor for subsequent operations. Then you
impliment either read() write() or ioctl() or all, whichever is
most appropriate for the function your module is going to provide.
You never 'call' a kernel function directly from user-mode. One of
the kernel's primary functions is to make this impossible. Kernel
code is protected from direct user-mode access.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.
#include <stdio.h>
#include <errno.h>
#include <asm/unistd.h>
#define __NR_my_func 250
_syscall0(void, my_func);
main()
{
my_func();
}
On Tue, 2003-02-18 at 13:43, Srinivas Chinta wrote:
> Hi,
> One way of doing this is , by hooking up your function
> inside the module as a system call.
> Here i'm sending two files, module.c and user_space.c.
> first do "insmod module.o" and then run
> "./user_space".
> As i'm also a newbee, i'm not aware of the
> disadvantages of this approach.
The main disadvantage is your driver/module becomes a specialized device
that can only be accessed by special syscall incantaion by one
application. The Un*x way is about keeping every thing as standard as
possible so there is easy interaction between user-mode programs
accessing the device even if they don't know the details of the
internals.
Most devices can be treated as char devices or block devices and are
coded as such. This way you can dump the contents of your hard-drive by
doing "cat /dev/hda1 > dump" without cat having intimate knowledge of
what a hard drive is and how to access one.
Of course there will always be times when new system calls need to be
added but generally this should be done sparinginly.
--
Alex, homepage: http://www.bennee.com/~alex/
He missed an invaluable opportunity to hold his tongue.
-- Andrew Lang