[NTOSKRNL]: Partly implement NtAreMappedFilesTheSame...

[NTDLL]: Fix (although I'm not sure quite why) LdrpCheckForLoadedDll which was crashing now that I've fixed PAGE_EXECUTE sections with only FILE_EXECUTE handles. Ironically, this meant that LdrpCheckForLoadedDll never worked until my previous fix some revisions ago, it always returned FALSE.
This should fix KVM/QEMU crashes...

svn path=/trunk/; revision=55448
This commit is contained in:
Alex Ionescu 2012-02-06 06:53:28 +00:00
parent a78b493a6b
commit 16b9a65060
2 changed files with 83 additions and 8 deletions

View file

@ -2204,12 +2204,7 @@ lookinhash:
{ {
/* Headers match too! Finally ask the kernel to compare mapped files */ /* Headers match too! Finally ask the kernel to compare mapped files */
Status = ZwAreMappedFilesTheSame(CurEntry->DllBase, ViewBase); Status = ZwAreMappedFilesTheSame(CurEntry->DllBase, ViewBase);
if (!NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{
/* Almost identical, but not quite, keep trying */
_SEH2_YIELD(continue;)
}
else
{ {
/* This is our entry!, unmap and return success */ /* This is our entry!, unmap and return success */
*LdrEntry = CurEntry; *LdrEntry = CurEntry;

View file

@ -1383,8 +1383,88 @@ NTAPI
NtAreMappedFilesTheSame(IN PVOID File1MappedAsAnImage, NtAreMappedFilesTheSame(IN PVOID File1MappedAsAnImage,
IN PVOID File2MappedAsFile) IN PVOID File2MappedAsFile)
{ {
UNIMPLEMENTED; PVOID AddressSpace;
return STATUS_NOT_IMPLEMENTED; PMEMORY_AREA MemoryArea1, MemoryArea2;
PROS_SECTION_OBJECT Section1, Section2;
DPRINT1("Is image: %p the same as file: %p?\n", File1MappedAsAnImage, File2MappedAsFile);
/* Lock address space */
AddressSpace = MmGetCurrentAddressSpace();
MmLockAddressSpace(AddressSpace);
/* Locate the memory area for the process by address */
MemoryArea1 = MmLocateMemoryAreaByAddress(AddressSpace, File1MappedAsAnImage);
if (!MemoryArea1)
{
/* Fail, the address does not exist */
DPRINT1("Invalid address\n");
MmUnlockAddressSpace(AddressSpace);
return STATUS_INVALID_ADDRESS;
}
/* Check if it's a section view (RosMm section) or ARM3 section */
if (MemoryArea1->Type != MEMORY_AREA_SECTION_VIEW)
{
/* Fail, the address is not a section */
DPRINT1("Invalid address (not a section)\n");
MmUnlockAddressSpace(AddressSpace);
return STATUS_CONFLICTING_ADDRESSES;
}
/* Get the section pointer to the SECTION_OBJECT */
Section1 = MemoryArea1->Data.SectionData.Section;
if (Section1->FileObject == NULL)
{
DPRINT1("No file object\n");
MmUnlockAddressSpace(AddressSpace);
return STATUS_CONFLICTING_ADDRESSES;
}
/* Locate the memory area for the process by address */
MemoryArea2 = MmLocateMemoryAreaByAddress(AddressSpace, File2MappedAsFile);
if (!MemoryArea2)
{
/* Fail, the address does not exist */
DPRINT1("Invalid address\n");
MmUnlockAddressSpace(AddressSpace);
return STATUS_INVALID_ADDRESS;
}
/* Check if it's a section view (RosMm section) or ARM3 section */
if (MemoryArea2->Type != MEMORY_AREA_SECTION_VIEW)
{
/* Fail, the address is not a section */
DPRINT1("Invalid address (not a section)\n");
MmUnlockAddressSpace(AddressSpace);
return STATUS_CONFLICTING_ADDRESSES;
}
/* Get the section pointer to the SECTION_OBJECT */
Section2 = MemoryArea2->Data.SectionData.Section;
if (Section2->FileObject == NULL)
{
DPRINT1("No file object\n");
MmUnlockAddressSpace(AddressSpace);
return STATUS_CONFLICTING_ADDRESSES;
}
/* These dbgprints should allow me to see what should w ecompare in ROS's section implementation once the winetests are run... for now lie and say they're not equal. */
DPRINT1("FO1/2: %p %p\n", Section1->FileObject, Section2->FileObject);
DPRINT1("SOP: %p %p\n",
Section1->FileObject->SectionObjectPointer,
Section2->FileObject->SectionObjectPointer);
DPRINT1("SCM: %p %p\n",
Section1->FileObject->SectionObjectPointer->SharedCacheMap,
Section2->FileObject->SectionObjectPointer->SharedCacheMap);
DPRINT1("ISO: %p %p\n",
Section1->FileObject->SectionObjectPointer->ImageSectionObject,
Section2->FileObject->SectionObjectPointer->ImageSectionObject);
DPRINT1("SISO: %p %p\n", Section1->ImageSection, Section2->ImageSection);
/* Unlock address space */
MmUnlockAddressSpace(AddressSpace);
return STATUS_NOT_SAME_DEVICE;
} }
/* /*