I am writing some kernel side code for Windows7 to access shared memory created in user mode, as suggested here.
The shared memory is created in user space with name:
"MySharedMem"
Opening the shared memory in user space works.
Opening the same shared memory in kernel mode calling ZwOpenSection
fails returning:
#define STATUS_OBJECT_NAME_NOT_FOUND ((NTSTATUS)0xC0000034L)
The kernel code is:
NTSTATUS CModule1::OpenShared()
{
SIZE_T vs = 256;
WCHAR stringBuffer[] = L"\\BaseNamedObjects\\MySharedMem";
UNICODE_STRING sectionName;
RtlInitUnicodeString(§ionName,stringBuffer);
OBJECT_ATTRIBUTES myAttributes;
InitializeObjectAttributes(&myAttributes,§ionName,0,NULL,NULL);
NTSTATUS status0 = ZwOpenSection(§ionHandle_,SECTION_MAP_READ|SECTION_MAP_WRITE,&myAttributes);
NTSTATUS status = ZwMapViewOfSection(§ionHandle_, ZwCurrentProcess(), (PVOID *)&pSharedData_, 0, 0, NULL, &vs, ViewShare, 0, PAGE_READWRITE);
return status;
}
I tried several names (L"\\MySharedMem"
or L"MySharedMem"
) but I got other errors as STATUS_OBJECT_PATH_INVALID
or STATUS_OBJECT_PATH_NOT_FOUND
.
Also creating the shared memory as "Global\\MySharedMem"
does not work.
What am I doing wrong?
I tried to create the shared memory in kernel mode, I get success on ZwCreateSection
and ZwMapViewOfSection
but i get access violation when I access the pSharedData_ pointer to test the buffer:
NTSTATUS CModule1::MapUserSection()
{
typedef struct SHARED_SECTION {DWORD i; };
NTSTATUS status = STATUS_SUCCESS;
ULONG Attributes=OBJ_KERNEL_HANDLE | OBJ_FORCE_ACCESS_CHECK;
OBJECT_ATTRIBUTES objectAttributes;
LARGE_INTEGER MaxSize;
SIZE_T ViewSize=sizeof(SHARED_SECTION);
MaxSize.QuadPart=sizeof(SHARED_SECTION);
WCHAR stringBuffer[] = L"\\MySm2";
UNICODE_STRING sectionName;
RtlInitUnicodeString(§ionName,stringBuffer);
InitializeObjectAttributes(&objectAttributes,§ionName,Attributes,NULL,NULL);
status= ZwCreateSection(§ionHandle_,SECTION_ALL_ACCESS,&objectAttributes,&MaxSize,PAGE_READWRITE,SEC_COMMIT,NULL);
status = ZwMapViewOfSection(sectionHandle_, ZwCurrentProcess(), (PVOID *)&pSharedData_, 0, 0, NULL, &ViewSize, ViewShare, 0, PAGE_READWRITE);
//To test the buffer
RtlFillMemory(pSharedData_, '1',ViewSize);
return status;
}
Everything fails...
"Local\\"
or"Global\\"
, you may need to append"Local\\"
to the front of your names. – OrmeGlobal\MySharedMem
when creating the file mapping. Once you've done that, usewinobj
(available from the MS web site) to look through the kernel namespace and find it. – LossGlobal\\MySharedMemame
but in this case I get the errorSTATUS_OBJECT_PATH_SYNTAX_BAD 0xC000003BL
– Filamentwinobj
find? – Loss