Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call a kernel module function from program at user space

Tags:

I developed a kernel module and some functions on it. Now i need to develop a program in the user space and call some functions which are in the kernel module.

I also need to access some global variable that are in the kernel module on my program at the user space.

like image 364
Ricardo Avatar asked May 30 '12 12:05

Ricardo


People also ask

How do I access kernel module from user space?

The canonical way to invoke kernel functions from a user application is to use syscalls(2). You could make some kernel module -providing some device- which, thru the interface of the device (i.e. read , write , ioctl on that device) is calling your kernel functions.

Which process is used for making calls to user space applications from within the kernel?

The mmap() system call is responsible for mapping the content of the file to the virtual memory space of the process. System call table is defined in Linux kernel source code.


1 Answers

There is complete overview of linux-kernel module and user-space program interacting http://wiki.tldp.org/kernel_user_space_howto "Kernel Space, User Space Interfaces" by Ariane Keller (it is from 2008-09-28, but about 2.6 kernels; only major new way is relayfs)

No ordinary function call from user space to kernel space is listed, only syscall (adding new syscall is not easy) and upcall (call in inverse direction).

One of easiest interface is ioctl; but you can't start to use ioctl before creating procfs, sysfs or similiar file.

Other is sysctl; but sysctl is more eligible to reading/writing to global variable. (It is hard to pass several parameters via sysctl interface).

like image 123
osgx Avatar answered Nov 12 '22 22:11

osgx