Author: tfaber Date: Tue Aug 11 08:47:14 2015 New Revision: 68678
URL: http://svn.reactos.org/svn/reactos?rev=68678&view=rev Log: [NTOS:MM] - Ignore IMAGE_SCN_TYPE_NOLOAD when loading image sections, as shown by ntdll_apitest:NtMapViewOfSection. This avoids errors when trying to relocate .rossym sections (since they were not loaded but Ldr tried to change their protection) CORE-8384
Modified: trunk/reactos/ntoskrnl/mm/section.c
Modified: trunk/reactos/ntoskrnl/mm/section.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/section.c?rev=6... ============================================================================== --- trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] Tue Aug 11 08:47:14 2015 @@ -4216,13 +4216,10 @@ * and calculate the image base address */ for (i = 0; i < NrSegments; i++) { - if (!(SectionSegments[i].Image.Characteristics & IMAGE_SCN_TYPE_NOLOAD)) + if (Segment == &SectionSegments[i]) { - if (Segment == &SectionSegments[i]) - { - ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress; - break; - } + ImageBaseAddress = (char*)BaseAddress - (ULONG_PTR)SectionSegments[i].Image.VirtualAddress; + break; } } if (i >= NrSegments) @@ -4232,18 +4229,15 @@
for (i = 0; i < NrSegments; i++) { - if (!(SectionSegments[i].Image.Characteristics & IMAGE_SCN_TYPE_NOLOAD)) + PVOID SBaseAddress = (PVOID) + ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress); + + Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress); + if (!NT_SUCCESS(Status)) { - PVOID SBaseAddress = (PVOID) - ((char*)ImageBaseAddress + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress); - - Status = MmUnmapViewOfSegment(AddressSpace, SBaseAddress); - if (!NT_SUCCESS(Status)) - { - DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n", - SBaseAddress, Process, Status); - NT_ASSERT(NT_SUCCESS(Status)); - } + DPRINT1("MmUnmapViewOfSegment failed for %p (Process %p) with %lx\n", + SBaseAddress, Process, Status); + NT_ASSERT(NT_SUCCESS(Status)); } } } @@ -4520,13 +4514,10 @@ ImageSize = 0; for (i = 0; i < NrSegments; i++) { - if (!(SectionSegments[i].Image.Characteristics & IMAGE_SCN_TYPE_NOLOAD)) - { - ULONG_PTR MaxExtent; - MaxExtent = (ULONG_PTR)(SectionSegments[i].Image.VirtualAddress + - SectionSegments[i].Length.QuadPart); - ImageSize = max(ImageSize, MaxExtent); - } + ULONG_PTR MaxExtent; + MaxExtent = (ULONG_PTR)(SectionSegments[i].Image.VirtualAddress + + SectionSegments[i].Length.QuadPart); + ImageSize = max(ImageSize, MaxExtent); }
ImageSectionObject->ImageInformation.ImageFileSize = (ULONG)ImageSize; @@ -4570,25 +4561,22 @@
for (i = 0; i < NrSegments; i++) { - if (!(SectionSegments[i].Image.Characteristics & IMAGE_SCN_TYPE_NOLOAD)) + PVOID SBaseAddress = (PVOID) + ((char*)ImageBase + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress); + MmLockSectionSegment(&SectionSegments[i]); + Status = MmMapViewOfSegment(AddressSpace, + Section, + &SectionSegments[i], + &SBaseAddress, + SectionSegments[i].Length.LowPart, + SectionSegments[i].Protection, + 0, + 0); + MmUnlockSectionSegment(&SectionSegments[i]); + if (!NT_SUCCESS(Status)) { - PVOID SBaseAddress = (PVOID) - ((char*)ImageBase + (ULONG_PTR)SectionSegments[i].Image.VirtualAddress); - MmLockSectionSegment(&SectionSegments[i]); - Status = MmMapViewOfSegment(AddressSpace, - Section, - &SectionSegments[i], - &SBaseAddress, - SectionSegments[i].Length.LowPart, - SectionSegments[i].Protection, - 0, - 0); - MmUnlockSectionSegment(&SectionSegments[i]); - if (!NT_SUCCESS(Status)) - { - MmUnlockAddressSpace(AddressSpace); - return(Status); - } + MmUnlockAddressSpace(AddressSpace); + return(Status); } }