views:

1015

answers:

3

New to Linux programming in general.

I am trying to communicate with a kernel module via shared memory, but cannot call the functions used in user apps such as shmget(); I have installed kernel-headers and kernel-devel, and included , to the kernel module source, but the headers do not contain any functions.

Is there a standard way of using shared memory in the kernel?

Also, any tips on how to use sockets in the same situation will be of great help.

Using Distro: CentOS 5.2 kernel: 2.6.18-92.1.22.e15

Thanks in advance.

//Added// To clarify, I am trying to make a demo that has common features of a typical embedded linux project. The final goal being porting it to LynxOS to see what kind of troubles may occur when doing so on larger projects.

Currently the main features of the demo is multi-process, pipes, message ques, shared-memory, sockets, multi-threads.

It has an user app and a loadable kernel module communicating with each other. pipes and messages between two processes within the user app, and shared-memory and sockets between the user app and kernel module.

If I am doing something plain off-course, please tell me.

+2  A: 

Your purpose does not look very clear to me. Shared memory is not a way to communicate between user space and kernel space. If you want to have access to some kernel allocated memory, one way to go is to implement the mmap system call.

If you really need to write some kernel code, a recommended reading is : linux device driver third edition, and chapter 15 is the one you are looking for.

Once you have shared memory, you probably will need a way to do some synchronisation, ie working on one part within the kernel, while using another part in user space. An example of userspace / kernel sharing of memory is the V4L2 API. An more friendly explanation can be found in the LWN series about it.

However, if you were more specific in what you want to do, you would receive more specific help on the way to do it, if you really need a kernel module, which kernel code you could have a look at and so on.

For the socket thing, I don't know enough, but you should google for linux + kernel + netlink. It is used to communicate with the kernel from user space via "standard" socket call, but I have really no idea on how to use it in a module.

shodanex
thanks for the advice!I wanted to make a demo program that used typical features one would use on a embedded linux project.Will clarify by editing the question
Saifis
+1  A: 

The kernel can access userspace memory automatically, there are plenty of examples of this in the kernel already (Hint: open() needs to access userspace to read the filename to open)

It's not clear what your use case is, please be more specific.

The normal way of communicating between userspace and the kernel is via sys calls; you can add your own (not necessarily recommended) or extend some existing ones (ioctl on a character device is typical).

A lot of kernel modules implement a device-special-file, this is what (most) device drivers do (except network interfaces, which aren't device special files under Linux)

MarkR
Thankyou, will look into kernel.
Saifis
A: 

following are ways by which u can talk to kernel mmap device files ( write you simple device driver , or you use fifo files as well , Netlink sockets (networking stack ), sockets ( networking) , or write you system call ... if you tell me in detail what exactly you want to acheive i can help you more.

Md.Ayyaz A Mulla