[NTOS:MM] Get rid of more calls to MmLocateMemoryAreaByAddress

This commit is contained in:
Timo Kreuzer 2024-04-07 10:56:10 +03:00
parent 1f27911997
commit 0e58b59794
5 changed files with 13 additions and 15 deletions

View file

@ -2264,10 +2264,10 @@ MiInsertBasedSection(
NTSTATUS NTSTATUS
NTAPI NTAPI
MiRosUnmapViewOfSection( MiRosUnmapViewOfSection(
IN PEPROCESS Process, _In_ PEPROCESS Process,
IN PVOID BaseAddress, _In_ PMEMORY_AREA MemoryArea,
IN BOOLEAN SkipDebuggerNotify _In_ PVOID BaseAddress,
); _In_ BOOLEAN SkipDebuggerNotify);
VOID VOID
NTAPI NTAPI

View file

@ -833,7 +833,7 @@ MiUnmapViewOfSection(IN PEPROCESS Process,
{ {
/* Call Mm API */ /* Call Mm API */
ASSERT(MI_IS_ROSMM_VAD(Vad)); ASSERT(MI_IS_ROSMM_VAD(Vad));
NTSTATUS Status = MiRosUnmapViewOfSection(Process, BaseAddress, Process->ProcessExiting); Status = MiRosUnmapViewOfSection(Process, (PMEMORY_AREA)Vad, BaseAddress, Process->ProcessExiting);
if (!Flags) MmUnlockAddressSpace(&Process->Vm); if (!Flags) MmUnlockAddressSpace(&Process->Vm);
return Status; return Status;
} }

View file

@ -4460,7 +4460,6 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
IN ULONG Protect) IN ULONG Protect)
{ {
PEPROCESS Process; PEPROCESS Process;
PMEMORY_AREA MemoryArea;
PMMVAD Vad = NULL, FoundVad; PMMVAD Vad = NULL, FoundVad;
NTSTATUS Status; NTSTATUS Status;
PMMSUPPORT AddressSpace; PMMSUPPORT AddressSpace;
@ -4876,8 +4875,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
// //
// Make sure this is an ARM3 section // Make sure this is an ARM3 section
// //
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)PAGE_ROUND_DOWN(PBaseAddress)); if (MI_IS_ROSMM_VAD(FoundVad))
if (MemoryArea && MemoryArea->Type != MEMORY_AREA_OWNED_BY_ARM3)
{ {
DPRINT1("Illegal commit of non-ARM3 section!\n"); DPRINT1("Illegal commit of non-ARM3 section!\n");
Status = STATUS_ALREADY_COMMITTED; Status = STATUS_ALREADY_COMMITTED;

View file

@ -511,7 +511,7 @@ MiRosCleanupMemoryArea(
if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)
{ {
Status = MiRosUnmapViewOfSection(Process, BaseAddress, Process->ProcessExiting); Status = MiRosUnmapViewOfSection(Process, MemoryArea, BaseAddress, Process->ProcessExiting);
} }
#ifdef NEWCC #ifdef NEWCC
else if (MemoryArea->Type == MEMORY_AREA_CACHE) else if (MemoryArea->Type == MEMORY_AREA_CACHE)

View file

@ -3599,12 +3599,13 @@ MmUnmapViewOfSegment(PMMSUPPORT AddressSpace,
/* This functions must be called with a locked address space */ /* This functions must be called with a locked address space */
NTSTATUS NTSTATUS
NTAPI NTAPI
MiRosUnmapViewOfSection(IN PEPROCESS Process, MiRosUnmapViewOfSection(
IN PVOID BaseAddress, _In_ PEPROCESS Process,
IN BOOLEAN SkipDebuggerNotify) _In_ PMEMORY_AREA MemoryArea,
_In_ PVOID BaseAddress,
_In_ BOOLEAN SkipDebuggerNotify)
{ {
NTSTATUS Status; NTSTATUS Status;
PMEMORY_AREA MemoryArea;
PMMSUPPORT AddressSpace; PMMSUPPORT AddressSpace;
PVOID ImageBaseAddress = 0; PVOID ImageBaseAddress = 0;
@ -3612,11 +3613,10 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
Process, BaseAddress); Process, BaseAddress);
ASSERT(Process); ASSERT(Process);
ASSERT(MemoryArea);
AddressSpace = &Process->Vm; AddressSpace = &Process->Vm;
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
BaseAddress);
if (MemoryArea == NULL || if (MemoryArea == NULL ||
#ifdef NEWCC #ifdef NEWCC
((MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) && (MemoryArea->Type != MEMORY_AREA_CACHE)) || ((MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) && (MemoryArea->Type != MEMORY_AREA_CACHE)) ||