JustKernel

Ray Of Hope

Shared Memory Between UserMode and Kernel (Windows)

Hi,

I was working on a project where display driver will capture the desktop and blit the content on to the file .. Now user application will read from the file and trasfer the blitted content to another embedded device via usb driver.

Now this operation was very slow and continuous reading and writing from the file was a performance hit.

So , I decided to use shared memory instead of using file. Now there are many techniques for using shared memory but I preferred using section object (may be that was the easiest one. 🙂 ) (Ioctl based approach was not suitable and mdl I couldn’t understand at that instant)

To create the shared memory , in my graphics driver (that will read the desktop and blit the content to shared memory), I created a section object .

ntstShrdMem = ZwCreateSection( &hSection, SECTION_ALL_ACCESS, &objAttrs, &lrgIntSecSize, PAGE_READWRITE,
SEC_COMMIT, NULL );

ZwMaplVIewOfSection ( hSection , NtCurrentProcess, &ptrBaseaddress,0L, PAGE_SIZE, NULL, szViewSize, ViewShare, 0, PAGE_READWRITE);

try {
ProbeForWrite( hSection,sizeof( HANDLE ), 4);
}

Now use this pointer, ptrBaseaddress, to write the content on to the shared buffer.

And From application did the following to read the buffer :

hOpenFile = OpenFileMapping(FILE_MAP_READ, (LPCSTR)”SharedMemoryArea);

void * pMem = (char *) MapViewOfFile( hOpenFIle, FILE_MAP_READ, 0, 0, 0);

Now use this pointer pMem, to read the content of shared memory.

Anshul Makkar, anshul_makkar@justkernel.com

Originally Posted On: 2010-04-06 01:23:24

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.