Hello,
All.I have created a named section object with ZwCreateSection function in my driver. The code to accomplish this process is shown in figure 1.
BOOLEAN g_CreateFlag = FALSE;
NTSTATUS AutoStartCreate(IN PDEVICE_OBJECT fdo, IN PIRP Irp)
{
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
if (!g_CreateFlag)
{
LARGE_INTEGER size;
UNICODE_STRING usSectionName;
OBJECT_ATTRIBUTES objAttributes;
NTSTATUS status;
RtlInitUnicodeString(&usSectionName, L"\BaseNamedObjects\UserKernelSharedSection");
InitializeObjectAttributes(&objAttributes, &usSectionName, OBJ_CASE_INSENSITIVE, NULL, NULL);
size.HighPart = 0;
size.LowPart = 11074560;
status = ZwCreateSection(&g_hSection,SECTION_ALL_ACCESS, &objAttributes,&size,PAGE_READWRITE,0x8000000,NULL);
if(NT_SUCCESS(status))
{
g_CreateFlag = TRUE;
}
return CompleteIrp(Irp,STATUS_SUCCESS,0);
}
figure 1
In xp system, I can open successfully the object in my user_mode application. In vista,when I open the object ,the system tell me it can’t find the file. The code to open the object is shown in figure 2.
HANDLE hSection;
hSection = ::OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE, FALSE, “UserKernelSharedSection”);
if (hSection == NULL)
{
LPVOID msg;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&msg, 0, NULL);
AfxMessageBox((LPTSTR)msg);
::LocalFree(msg);
}
else
AfxMessageBox(_T(“OpenFileMapping OK”));
figure 2
Why? Could you help me? Thanks in advance!