[wdmaudiodev] Named Shared memory between Kernel Mode driver and User mode

  • From: swapnil kamble <swap.kamble@xxxxxxxxx>
  • To: wdmaudiodev@xxxxxxxxxxxxx
  • Date: Tue, 14 Apr 2009 16:27:19 +0530

Hi All,
        I want to create a named shared memory between a driver and User
mode. I create named Shared memory from driver by using following code.

    SIZE_T ViewSize= 1024*10;

    RtlInitUnicodeString(&usSectionName,
L"\\BaseNamedObjects\\SharedMemory");
    InitializeObjectAttributes(&objAttributes, &usSectionName,
OBJ_CASE_INSENSITIVE , NULL, NULL);

    size.HighPart = 0;
    size.LowPart = 1024*10;

    status = ZwCreateSection(&hSection,*SECTION_ALL_ACCESS*,
&objAttributes,&size,*PAGE_READWRITE* ,*SEC_COMMIT*,NULL);
    DbgPrint("\nZwCreateSection returns status=%x",status);

    status = ZwMapViewOfSection(
hSection,ZwCurrentProcess(),&BaseAddress,0,ViewSize,NULL,&ViewSize,ViewShare,0,
*PAGE_READWRITE | PAGE_NOCACHE*);


From User mode I open that section in the following way

_tcscpy_s( m_szMemFileName , TEXT("Global\\SharedMemory") );

    BOOL bFileObjCreatedByThisInstance = FALSE;

    m_hMemMapFile = OpenFileMapping( *FILE_MAP_READ*,FALSE,m_szMemFileName);

    m_pSharedBuffer = (UCHAR*) MapViewOfFile(    m_hMemMapFile,  *
FILE_MAP_READ*,    0,  0,   10*1024);

ZwCreateSection sets ALL_ACCESS on this section. If I open it with *
FILE_MAP_READ* flag then it opens successfully, but if I specify
*FILE_MAP_WRITE
*then OpenFileMapping returns errror code 5 which is *access denied*. Does
any one has any idea about this problem ?


-- 
...Swapnil

|| Hare Krishna Hare Krishna Krishna Krishna Hare Hare ||
|| Hare Rama    Hare Rama   Rama   Rama    Hare Hare ||



-- 
...Swapnil

|| Hare Krishna Hare Krishna Krishna Krishna Hare Hare ||
|| Hare Rama    Hare Rama   Rama   Rama    Hare Hare ||

Other related posts:

  • » [wdmaudiodev] Named Shared memory between Kernel Mode driver and User mode - swapnil kamble