[NTOSKRNL] Store the MM_IMAGE_SECTION_OBJECT pointer in SECTION::Segment

This commit is contained in:
Jérôme Gardou 2020-10-23 17:27:47 +02:00
parent c6a87f28bf
commit e980efebd4
4 changed files with 27 additions and 24 deletions

View file

@ -200,8 +200,6 @@ typedef struct _ROS_SECTION_OBJECT
{ {
SECTION; SECTION;
PFILE_OBJECT FileObject; PFILE_OBJECT FileObject;
PMM_IMAGE_SECTION_OBJECT ImageSection;
} ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT; } ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT;
#define MA_GetStartingAddress(_MemoryArea) ((_MemoryArea)->VadNode.StartingVpn << PAGE_SHIFT) #define MA_GetStartingAddress(_MemoryArea) ((_MemoryArea)->VadNode.StartingVpn << PAGE_SHIFT)

View file

@ -1789,8 +1789,14 @@ MmGetImageInformation (OUT PSECTION_IMAGE_INFORMATION ImageInformation)
ASSERT(SectionObject != NULL); ASSERT(SectionObject != NULL);
ASSERT(MiIsRosSectionObject(SectionObject) == TRUE); ASSERT(MiIsRosSectionObject(SectionObject) == TRUE);
if (SectionObject->u.Flags.Image == 0)
{
RtlZeroMemory(ImageInformation, sizeof(*ImageInformation));
return;
}
/* Return the image information */ /* Return the image information */
*ImageInformation = ((PROS_SECTION_OBJECT)SectionObject)->ImageSection->ImageInformation; *ImageInformation = ((PMM_IMAGE_SECTION_OBJECT)SectionObject->Segment)->ImageInformation;
} }
NTSTATUS NTSTATUS

View file

@ -81,13 +81,13 @@ MiCacheImageSymbols(IN PVOID BaseAddress)
NTSTATUS NTSTATUS
NTAPI NTAPI
MiLoadImageSection(IN OUT PVOID *SectionPtr, MiLoadImageSection(_Inout_ PSECTION *SectionPtr,
OUT PVOID *ImageBase, _Out_ PVOID *ImageBase,
IN PUNICODE_STRING FileName, _In_ PUNICODE_STRING FileName,
IN BOOLEAN SessionLoad, _In_ BOOLEAN SessionLoad,
IN PLDR_DATA_TABLE_ENTRY LdrEntry) _In_ PLDR_DATA_TABLE_ENTRY LdrEntry)
{ {
PROS_SECTION_OBJECT Section = *SectionPtr; PSECTION Section = *SectionPtr;
NTSTATUS Status; NTSTATUS Status;
PEPROCESS Process; PEPROCESS Process;
PVOID Base = NULL; PVOID Base = NULL;
@ -158,7 +158,7 @@ MiLoadImageSection(IN OUT PVOID *SectionPtr,
} }
/* Reserve system PTEs needed */ /* Reserve system PTEs needed */
PteCount = ROUND_TO_PAGES(Section->ImageSection->ImageInformation.ImageFileSize) >> PAGE_SHIFT; PteCount = ROUND_TO_PAGES(((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->ImageInformation.ImageFileSize) >> PAGE_SHIFT;
PointerPte = MiReserveSystemPtes(PteCount, SystemPteSpace); PointerPte = MiReserveSystemPtes(PteCount, SystemPteSpace);
if (!PointerPte) if (!PointerPte)
{ {
@ -2837,7 +2837,7 @@ MmLoadSystemImage(IN PUNICODE_STRING FileName,
PWCHAR MissingDriverName; PWCHAR MissingDriverName;
HANDLE SectionHandle; HANDLE SectionHandle;
ACCESS_MASK DesiredAccess; ACCESS_MASK DesiredAccess;
PVOID Section = NULL; PSECTION Section = NULL;
BOOLEAN LockOwned = FALSE; BOOLEAN LockOwned = FALSE;
PLIST_ENTRY NextEntry; PLIST_ENTRY NextEntry;
IMAGE_INFO ImageInfo; IMAGE_INFO ImageInfo;
@ -3054,7 +3054,7 @@ LoaderScan:
SECTION_MAP_EXECUTE, SECTION_MAP_EXECUTE,
MmSectionObjectType, MmSectionObjectType,
KernelMode, KernelMode,
&Section, (PVOID*)&Section,
NULL); NULL);
ZwClose(SectionHandle); ZwClose(SectionHandle);
if (!NT_SUCCESS(Status)) goto Quickie; if (!NT_SUCCESS(Status)) goto Quickie;
@ -3085,7 +3085,7 @@ LoaderScan:
ASSERT(Status != STATUS_ALREADY_COMMITTED); ASSERT(Status != STATUS_ALREADY_COMMITTED);
/* Get the size of the driver */ /* Get the size of the driver */
DriverSize = ((PROS_SECTION_OBJECT)Section)->ImageSection->ImageInformation.ImageFileSize; DriverSize = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->ImageInformation.ImageFileSize;
/* Make sure we're not being loaded into session space */ /* Make sure we're not being loaded into session space */
if (!Flags) if (!Flags)

View file

@ -2633,7 +2633,7 @@ MmpFreePageFileSegment(PMM_SECTION_SEGMENT Segment)
VOID NTAPI VOID NTAPI
MmpDeleteSection(PVOID ObjectBody) MmpDeleteSection(PVOID ObjectBody)
{ {
PROS_SECTION_OBJECT Section = (PROS_SECTION_OBJECT)ObjectBody; PROS_SECTION_OBJECT Section = ObjectBody;
/* Check if it's an ARM3, or ReactOS section */ /* Check if it's an ARM3, or ReactOS section */
if (!MiIsRosSectionObject(Section)) if (!MiIsRosSectionObject(Section))
@ -2656,11 +2656,11 @@ MmpDeleteSection(PVOID ObjectBody)
* until the image section is properly initialized we shouldn't * until the image section is properly initialized we shouldn't
* process further here. * process further here.
*/ */
if (Section->ImageSection == NULL) if (Section->Segment == NULL)
return; return;
SectionSegments = Section->ImageSection->Segments; SectionSegments = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->Segments;
NrSegments = Section->ImageSection->NrSegments; NrSegments = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment)->NrSegments;
for (i = 0; i < NrSegments; i++) for (i = 0; i < NrSegments; i++)
{ {
@ -3763,7 +3763,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
return(Status); return(Status);
} }
Section->ImageSection = ImageSectionObject; Section->Segment = (PSEGMENT)ImageSectionObject;
ASSERT(ImageSectionObject->Segments); ASSERT(ImageSectionObject->Segments);
/* /*
@ -3788,7 +3788,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
ExFreePool(ImageSectionObject->Segments); ExFreePool(ImageSectionObject->Segments);
ExFreePool(ImageSectionObject); ExFreePool(ImageSectionObject);
ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject; ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
Section->ImageSection = ImageSectionObject; Section->Segment = (PSEGMENT)ImageSectionObject;
SectionSegments = ImageSectionObject->Segments; SectionSegments = ImageSectionObject->Segments;
for (i = 0; i < ImageSectionObject->NrSegments; i++) for (i = 0; i < ImageSectionObject->NrSegments; i++)
@ -3813,7 +3813,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
} }
ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject; ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
Section->ImageSection = ImageSectionObject; Section->Segment = (PSEGMENT)ImageSectionObject;
SectionSegments = ImageSectionObject->Segments; SectionSegments = ImageSectionObject->Segments;
/* /*
@ -4114,7 +4114,7 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
PMM_SECTION_SEGMENT Segment; PMM_SECTION_SEGMENT Segment;
Segment = MemoryArea->SectionData.Segment; Segment = MemoryArea->SectionData.Segment;
ImageSectionObject = Section->ImageSection; ImageSectionObject = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
SectionSegments = ImageSectionObject->Segments; SectionSegments = ImageSectionObject->Segments;
NrSegments = ImageSectionObject->NrSegments; NrSegments = ImageSectionObject->NrSegments;
@ -4314,8 +4314,7 @@ NtQuerySection(
{ {
if (RosSection->u.Flags.Image) if (RosSection->u.Flags.Image)
{ {
PMM_IMAGE_SECTION_OBJECT ImageSectionObject; PMM_IMAGE_SECTION_OBJECT ImageSectionObject = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
ImageSectionObject = RosSection->ImageSection;
*Sii = ImageSectionObject->ImageInformation; *Sii = ImageSectionObject->ImageInformation;
} }
@ -4504,7 +4503,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
PMM_IMAGE_SECTION_OBJECT ImageSectionObject; PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
PMM_SECTION_SEGMENT SectionSegments; PMM_SECTION_SEGMENT SectionSegments;
ImageSectionObject = Section->ImageSection; ImageSectionObject = ((PMM_IMAGE_SECTION_OBJECT)Section->Segment);
SectionSegments = ImageSectionObject->Segments; SectionSegments = ImageSectionObject->Segments;
NrSegments = ImageSectionObject->NrSegments; NrSegments = ImageSectionObject->NrSegments;