[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
NTAPI
MiRosUnmapViewOfSection(
IN PEPROCESS Process,
IN PVOID BaseAddress,
IN BOOLEAN SkipDebuggerNotify
);
_In_ PEPROCESS Process,
_In_ PMEMORY_AREA MemoryArea,
_In_ PVOID BaseAddress,
_In_ BOOLEAN SkipDebuggerNotify);
VOID
NTAPI

View file

@ -833,7 +833,7 @@ MiUnmapViewOfSection(IN PEPROCESS Process,
{
/* Call Mm API */
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);
return Status;
}

View file

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

View file

@ -511,7 +511,7 @@ MiRosCleanupMemoryArea(
if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)
{
Status = MiRosUnmapViewOfSection(Process, BaseAddress, Process->ProcessExiting);
Status = MiRosUnmapViewOfSection(Process, MemoryArea, BaseAddress, Process->ProcessExiting);
}
#ifdef NEWCC
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 */
NTSTATUS
NTAPI
MiRosUnmapViewOfSection(IN PEPROCESS Process,
IN PVOID BaseAddress,
IN BOOLEAN SkipDebuggerNotify)
MiRosUnmapViewOfSection(
_In_ PEPROCESS Process,
_In_ PMEMORY_AREA MemoryArea,
_In_ PVOID BaseAddress,
_In_ BOOLEAN SkipDebuggerNotify)
{
NTSTATUS Status;
PMEMORY_AREA MemoryArea;
PMMSUPPORT AddressSpace;
PVOID ImageBaseAddress = 0;
@ -3612,11 +3613,10 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
Process, BaseAddress);
ASSERT(Process);
ASSERT(MemoryArea);
AddressSpace = &Process->Vm;
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
BaseAddress);
if (MemoryArea == NULL ||
#ifdef NEWCC
((MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) && (MemoryArea->Type != MEMORY_AREA_CACHE)) ||