&SectionHaHi,
I used shared memory object to share memory between multiple processes and a kernel mode driver. The application created the shared object using CreateFileMapping() and the driver maps it using ZwMapViewOfSection().
Application in this case is a 32bit application.
Driver function ZwMapViewOfSection() seems to work fine in Windows server 2003 x64 OS, but fails in Windows XP x64 with NTSTATUS 0xc00000f1 which is "INVALID_THIRD_PARAMETER". Actually only free build of the driver shows this problem, check build driver works fine. Driver also seems to work in 32bit Windows XP.
I used following code. Any idea why this issue occurs? Is there any Documentation/errata regarding this? Any help appreciated.
Application Code:
#define MYSHAREDMEMORYOBJECTNAME "MY_SHARED_OBJ"
#define MYBUFFERSIZE 100
HANDLE gMyCMDProfAPISharedMapFile = NULL;
bool InitializeProfAPISharedObj()
{
// check if the handle had been created before
gMyCMDProfAPISharedMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
MYSHAREDMEMORYOBJECTNAME); // name of mapping object
if (!gMyCMDProfAPISharedMapFile)
{
gMyCMDProfAPISharedMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL, // default security
PAGE_READWRITE, // read/write access
0, // max. object size
MYBUFFERSIZE, // buffer size
MYSHAREDMEMORYOBJECTNAME); // name of mapping object
}
printf("Create Shared Object\n");
if (gMyCMDProfAPISharedMapFile)
return true;
else
return false;
}
Driver Code:
#define MY_SHARED_OBJ L"\\BaseNamedObjects\\MY_SHARED_OBJ"
#define MY_SHARED_MEM_SIZE 100
CreateUserKernelSharedMap(
IN PCAPROF_DEV_EXTENSION pDevExt
)
{
NTSTATUS status;
OBJECT_ATTRIBUTES objAttrs;
PMDL pMdl; HANDLE SectionHandle;
HANDLE ProcessHandle;
ULONG MappedLength;
ULONG64* pulSharedObj;
UNICODE_STRING usSharedMemoryObjName;
LARGE_INTEGER Size;
ULONG ViewSize = 0;
PVOID uBaseAddress = NULL;
Size.QuadPart = MY_SHARED_MEM_SIZE;
RtlZeroMemory(&objAttrs, sizeof(objAttrs));
//Convert the constant string to the UNICODE_STRING
RtlInitUnicodeString(&usSharedMemoryObjName, MY_SHARED_OBJ); // initialize
the object attributes structure
InitializeObjectAttributes(
&objAttrs,
&usSharedMemoryObjName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
(HANDLE)NULL,
(PSECURITY_DESCRIPTOR)NULL
);
status = ZwOpenSection(
ndle,
SECTION_MAP_READ|SECTION_MAP_WRITE,
&objAttrs
);
if (!NT_SUCCESS(status))
{
KdPrint(("ZwOpenSection failed, rc = 0x%08X\n", status));
return status;
}
pDevExt->hSharedObjSectionHandle = SectionHandle;
status = ZwMapViewOfSection(
SectionHandle, //section handle
NtCurrentProcess(), // current process
&uBaseAddress, //virtual based address
0L, //Zerobits
MY_SHARED_MEM_SIZE,
0, // optional
(PSIZE_T)&ViewSize, // How much to map
ViewShare, // Inherit disposition
0, //ALlocation Type
PAGE_READWRITE //protection
);
if(!NT_SUCCESS(status))
{
KdPrint(("ZwMapViewOfSection failed, rc = 0x%08X\n", status));
DbgPrint("%x\n",status); //This prints c00000f1 in x64 XP
ZwClose(pDevExt->hSharedObjSectionHandle);
return status;
}
.................
}
Thanks,
RJ