call a kernel module function from program at user space

前端 未结 4 1187
别跟我提以往
别跟我提以往 2020-12-08 01:32

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 als

相关标签:
4条回答
  • 2020-12-08 01:52

    You seem to be missing the point of kernel and userland separation. If your user program could modify data inside the kernel directly, that would quickly lead to disaster.

    There's only one conventional way for a user program to explicitly request services from the kernel - make a system call.

    There are also traps and some Linux-specific userland-kernel communication mechanisms, but those are not relevant here.

    0 讨论(0)
  • 2020-12-08 01:58

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

    0 讨论(0)
  • 2020-12-08 02:01

    As other posters have mentioned, there is a clear distinction between kernel and user space. So no you can't call a kernel function directly from user space. I think the easiest way to send messages between userspace and kernel space is via netlink sockets. A netlink socket allows you to easily pass arbitrary data structures between user level and kernel level.

    Yes ioctl, system calls are viable alternatives, they are not as flexible as the netlink socket for passing arbitrary information.

    0 讨论(0)
  • 2020-12-08 02:08

    You'll need to install a new kernel to make use of the new call unless you already have some mechanism to update the kernel ... http://www.cyberciti.biz/tips/how-to-patch-running-linux-kernel.html

    0 讨论(0)
提交回复
热议问题