Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i call a function that written in kernel module, from the user program?

sample driver created and loaded successfully, in that a user defined function is written, it does some actions. i need to write a user program that calls the user defined function in the driver module.

need help in following cases.

  1. How can i get access to the driver code from a user program ?.
  2. How can i call a function that written in kernel module, from the user program ?.

thanks.

like image 319
tijin Avatar asked Jan 20 '26 13:01

tijin


2 Answers

You can make your driver to react on writes (or if necessary, ioctl) to a /dev/xxx file or a /proc/xxx file. Also, you can create a new syscall, but that's more of a toy as the module would only work on custom built kernels.

Edit: try http://www.faqs.org/docs/kernel/x571.html (on character device drivers.)

like image 169
Adrian Panasiuk Avatar answered Jan 23 '26 03:01

Adrian Panasiuk


It depends on what your function does, but in general:

  • If you want to store and show properties in the form of values (e.g. current brightness of a backlight), the standard way of doing would be using sysfs: http://kernel.org/doc/Documentation/filesystems/sysfs.txt

  • If you want to write/read values from a device (real or virtual), export memory or IO regions of a device to user space, or more generally control a device (e.g. setting resolution of a camera and capturing frames), you would use a character or block devices with the read/write/mmap and ioctl functions: http://luv.asn.au/overheads/chrdev-talk.html

  • Finally if your function just controls something from the kernel, then sysfs or procfs should be the way to go. I am not sure why people are still using procfs nowadays, except for misc devices maybe.

So in general, you need to export your kernel functions to user space through files, by defining hooks that will be called when the file is opened, read, written (to copy data from/to user space), mmap'ed (to share memory areas without copying) or when an ioctl is invoked (to perform more general control).

like image 22
Gnurou Avatar answered Jan 23 '26 04:01

Gnurou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!