Sharing Memory Between the Linux Kernel and User Space

This page provides an example driver that allows a block of memory to be shared between multiple user spaces, and drivers operating in kernel space. While the standard kernel makes it possible to share memory between user space processes, it's not (easily) possible to access that memory from the kernel at the same time.

Of course that's something you should never really do - there are a lot more controlled ways for such code to communicate, but just occasionally you need to share something simple, and all the overhead of ioctls or sockets is too much. And in embedded programming, it's the sort of thing that happens more often...

The Shared Memory Driver

The source code package creates a tree containing four source files:

You'll need to edit Makefile and tesmod/Makefile and update the KERNEL_SOURCE definition to point to where you are keeping your kernel source. Then the files can be built by running make build in the top level directory.

Run make load to load the drivers, and make unload should unload them.

Once the files are built and the drivers loaded, you should be able to run the tests by running ./client a and ./client b in two separate windows. If the two instances of the client are communicating with each other (and the test module) then the clients should print a long sequence of numbers.


This code was written and tested on version 3.0.6 of the kernel.

Email questions/comments to notes at

© Embrisk Ltd. 2012