LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-10-2008, 05:07 AM   #1
ian b davidson
LQ Newbie
 
Registered: Nov 2008
Posts: 2

Rep: Reputation: 0
Sharing memory between driver and user space


Hi,

The sys V functions, shmget(), shmatt(), and shmdet() allow
memory to be shared between one or more applications in userspace. The memory may be efficiently accessed in each
user application by dereferencing pointers.

Will this work between driver code and userspace?

If not, is there another method whereby memory can be shared between a device driver, and user code using pointers?

I am writing a display driver, and want to share the pixel image between user code and the display driver.
The user code will simply update the pixel image by dereferencing a pointer, and the driver will be responsible for keeping the display up to date.

Thanks for any information,

Ian Davidson
 
Old 11-10-2008, 09:06 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
I would obligate the user to allocate a shared-memory segment and then provide you with a handle to it. With each request you then verify that the segment exists, that it really does belong to this user, and that it is of sufficient size, and that the coordinates are plausible. Then, the kernel-mode routine can gain access to the memory (caution: it's virtual!) and use it.

Needless to say, the interface to your kernel module will reside in a library that the user will employ to actually get at whatever functionality you provide. So, all the shared-memory strangeness can be wrapped-up in that "cleverly designed, easy-to-use" library. Although this does not relieve your kernel-routine of the obligation to validate its parameters on the assumption that some "133t h4x0R" has hijacked it, it does allow you to design some fairly crufty kernel-interfaces and get away with it.

Last edited by sundialsvcs; 11-10-2008 at 09:09 AM.
 
Old 11-10-2008, 10:20 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Have you considered creating a character or /proc device and mmaping it from user-space? With a memory map the module will receive the updates; therefore, it will only need to refresh, etc. when the image is updated in the map. Leaving the data in user-space will probably require the module to be on a refresh cycle because the module won't know exactly when that memory has been updated, unless of course you require a "refresh" call from user-space (which might be more appropriate, maybe via ioctl.) Using a special file will also allow the module to arbitrarily limit write access.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sharing Memory between driver space and user space ian b davidson Programming 1 11-10-2008 06:35 AM
mapping contiguous kernel memory to user space nili Linux - Kernel 4 01-29-2008 01:43 PM
Sharing semaphore between kernel and user space balinju Programming 5 01-25-2008 12:21 PM
Isolating driver memory space rajeshwar27singh Linux - Kernel 4 10-29-2007 05:39 PM
User wants to allocate more than 3Gb memory space in RHel5 batkinso Red Hat 3 07-24-2007 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 10:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration