https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0187c1e11394095ca644d…
commit 0187c1e11394095ca644d5cf622737cb3bca6f14
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Tue Mar 30 16:20:25 2021 +0200
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Tue Mar 30 16:26:43 2021 +0200
[NTOS:MM] Fix PFN tracing
---
ntoskrnl/cc/view.c | 19 -------------------
ntoskrnl/include/internal/mm.h | 42 +++++++++++++++++++++++++++++++++++++++++-
ntoskrnl/mm/ARM3/mminit.c | 4 ++--
ntoskrnl/mm/ARM3/pagfault.c | 9 +++++++++
ntoskrnl/mm/ARM3/pfnlist.c | 13 ++++++-------
ntoskrnl/mm/ARM3/sysldr.c | 9 +--------
ntoskrnl/mm/freelist.c | 15 +++++++++++++++
ntoskrnl/mm/section.c | 6 ------
8 files changed, 74 insertions(+), 43 deletions(-)
diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c
index 6481c340fe0..cb99d809a5d 100644
--- a/ntoskrnl/cc/view.c
+++ b/ntoskrnl/cc/view.c
@@ -806,25 +806,6 @@ Retry:
InsertTailList(&VacbLruListHead, ¤t->VacbLruListEntry);
KeReleaseQueuedSpinLock(LockQueueMasterLock, oldIrql);
- MI_SET_USAGE(MI_USAGE_CACHE);
-#if MI_TRACE_PFNS
- if ((SharedCacheMap->FileObject) &&
(SharedCacheMap->FileObject->FileName.Buffer))
- {
- PWCHAR pos;
- ULONG len = 0;
- pos = wcsrchr(SharedCacheMap->FileObject->FileName.Buffer, '\\');
- if (pos)
- {
- len = wcslen(pos) * sizeof(WCHAR);
- snprintf(MI_PFN_CURRENT_PROCESS_NAME, min(16, len), "%S", pos);
- }
- else
- {
- snprintf(MI_PFN_CURRENT_PROCESS_NAME, min(16, len), "%wZ",
&SharedCacheMap->FileObject->FileName);
- }
- }
-#endif
-
/* Reference it to allow release */
CcRosVacbIncRefCount(current);
diff --git a/ntoskrnl/include/internal/mm.h b/ntoskrnl/include/internal/mm.h
index a661aa469f3..074dbd4e454 100644
--- a/ntoskrnl/include/internal/mm.h
+++ b/ntoskrnl/include/internal/mm.h
@@ -245,9 +245,45 @@ MM_RMAP_ENTRY, *PMM_RMAP_ENTRY;
extern ULONG MI_PFN_CURRENT_USAGE;
extern CHAR MI_PFN_CURRENT_PROCESS_NAME[16];
#define MI_SET_USAGE(x) MI_PFN_CURRENT_USAGE = x
-#define MI_SET_PROCESS2(x) memcpy(MI_PFN_CURRENT_PROCESS_NAME, x, 16)
+#define MI_SET_PROCESS2(x) memcpy(MI_PFN_CURRENT_PROCESS_NAME, x, min(sizeof(x),
sizeof(MI_PFN_CURRENT_PROCESS_NAME)))
+FORCEINLINE
+void
+MI_SET_PROCESS(PEPROCESS Process)
+{
+ if (!Process)
+ MI_SET_PROCESS2("Kernel");
+ else if (Process == (PEPROCESS)1)
+ MI_SET_PROCESS2("Hydra");
+ else
+ MI_SET_PROCESS2(Process->ImageFileName);
+}
+
+FORCEINLINE
+void
+MI_SET_PROCESS_USTR(PUNICODE_STRING ustr)
+{
+ PWSTR pos, strEnd;
+ int i;
+
+ if (!ustr->Buffer || ustr->Length == 0)
+ {
+ MI_PFN_CURRENT_PROCESS_NAME[0] = 0;
+ return;
+ }
+
+ pos = strEnd = &ustr->Buffer[ustr->Length / sizeof(WCHAR)];
+ while ((*pos != L'\\') && (pos > ustr->Buffer))
+ pos--;
+
+ if (*pos == L'\\')
+ pos++;
+
+ for (i = 0; i < sizeof(MI_PFN_CURRENT_PROCESS_NAME) && pos <= strEnd;
i++, pos++)
+ MI_PFN_CURRENT_PROCESS_NAME[i] = (CHAR)*pos;
+}
#else
#define MI_SET_USAGE(x)
+#define MI_SET_PROCESS(x)
#define MI_SET_PROCESS2(x)
#endif
@@ -275,6 +311,9 @@ typedef enum _MI_PFN_USAGES
MI_USAGE_PFN_DATABASE,
MI_USAGE_BOOT_DRIVER,
MI_USAGE_INIT_MEMORY,
+ MI_USAGE_PAGE_FILE,
+ MI_USAGE_COW,
+ MI_USAGE_WSLE,
MI_USAGE_FREE_PAGE
} MI_PFN_USAGES;
@@ -355,6 +394,7 @@ typedef struct _MMPFN
#if MI_TRACE_PFNS
MI_PFN_USAGES PfnUsage;
CHAR ProcessName[16];
+#define MI_SET_PFN_PROCESS_NAME(pfn, x) memcpy(pfn->ProcessName, x, min(sizeof(x),
sizeof(pfn->ProcessName)))
#endif
// HACK until WS lists are supported
diff --git a/ntoskrnl/mm/ARM3/mminit.c b/ntoskrnl/mm/ARM3/mminit.c
index 64e2193a558..9b18537f3ac 100644
--- a/ntoskrnl/mm/ARM3/mminit.c
+++ b/ntoskrnl/mm/ARM3/mminit.c
@@ -801,7 +801,7 @@ MiBuildPfnDatabaseFromPages(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Pfn1->u3.e1.CacheAttribute = MiNonCached;
#if MI_TRACE_PFNS
Pfn1->PfnUsage = MI_USAGE_INIT_MEMORY;
- memcpy(Pfn1->ProcessName, "Initial PDE", 16);
+ MI_SET_PFN_PROCESS_NAME(Pfn1, "Initial PDE");
#endif
}
else
@@ -848,7 +848,7 @@ MiBuildPfnDatabaseFromPages(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Pfn2->u3.e1.CacheAttribute = MiNonCached;
#if MI_TRACE_PFNS
Pfn2->PfnUsage = MI_USAGE_INIT_MEMORY;
- memcpy(Pfn1->ProcessName, "Initial PTE",
16);
+ MI_SET_PFN_PROCESS_NAME(Pfn2, "Initial PTE");
#endif
}
}
diff --git a/ntoskrnl/mm/ARM3/pagfault.c b/ntoskrnl/mm/ARM3/pagfault.c
index 6d60645debd..87c789c1742 100644
--- a/ntoskrnl/mm/ARM3/pagfault.c
+++ b/ntoskrnl/mm/ARM3/pagfault.c
@@ -899,6 +899,9 @@ MiResolvePageFileFault(_In_ BOOLEAN StoreInstruction,
ASSERT(CurrentProcess > HYDRA_PROCESS);
ASSERT(*OldIrql != MM_NOIRQL);
+ MI_SET_USAGE(MI_USAGE_PAGE_FILE);
+ MI_SET_PROCESS(CurrentProcess);
+
/* We must hold the PFN lock */
MI_ASSERT_PFN_LOCK_HELD();
@@ -1210,6 +1213,9 @@ MiResolveProtoPteFault(IN BOOLEAN StoreInstruction,
ASSERT(TempPte.u.Hard.Valid == 1);
ProtoPageFrameIndex = PFN_FROM_PTE(&TempPte);
+ MI_SET_USAGE(MI_USAGE_COW);
+ MI_SET_PROCESS(Process);
+
/* Get a new page for the private copy */
if (Process > HYDRA_PROCESS)
Color = MI_GET_NEXT_PROCESS_COLOR(Process);
@@ -2210,6 +2216,9 @@ UserFault:
ASSERT(MmAvailablePages > 0);
+ MI_SET_USAGE(MI_USAGE_COW);
+ MI_SET_PROCESS(CurrentProcess);
+
/* Allocate a new page and copy it */
PageFrameIndex =
MiRemoveAnyPage(MI_GET_NEXT_PROCESS_COLOR(CurrentProcess));
OldPageFrameIndex = PFN_FROM_PTE(&TempPte);
diff --git a/ntoskrnl/mm/ARM3/pfnlist.c b/ntoskrnl/mm/ARM3/pfnlist.c
index f175541a500..a75f2194396 100644
--- a/ntoskrnl/mm/ARM3/pfnlist.c
+++ b/ntoskrnl/mm/ARM3/pfnlist.c
@@ -254,8 +254,8 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
ASSERT(MI_PFN_CURRENT_USAGE != MI_USAGE_NOT_SET);
Entry->PfnUsage = MI_PFN_CURRENT_USAGE;
memcpy(Entry->ProcessName, MI_PFN_CURRENT_PROCESS_NAME, 16);
-// MI_PFN_CURRENT_USAGE = MI_USAGE_NOT_SET;
-// memcpy(MI_PFN_CURRENT_PROCESS_NAME, "Not Set", 16);
+ MI_PFN_CURRENT_USAGE = MI_USAGE_NOT_SET;
+ MI_SET_PROCESS2("Not Set");
#endif
}
@@ -459,11 +459,11 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
MiDecrementAvailablePages();
#if MI_TRACE_PFNS
- //ASSERT(MI_PFN_CURRENT_USAGE != MI_USAGE_NOT_SET);
+ ASSERT(MI_PFN_CURRENT_USAGE != MI_USAGE_NOT_SET);
Pfn1->PfnUsage = MI_PFN_CURRENT_USAGE;
memcpy(Pfn1->ProcessName, MI_PFN_CURRENT_PROCESS_NAME, 16);
- //MI_PFN_CURRENT_USAGE = MI_USAGE_NOT_SET;
- //memcpy(MI_PFN_CURRENT_PROCESS_NAME, "Not Set", 16);
+ MI_PFN_CURRENT_USAGE = MI_USAGE_NOT_SET;
+ MI_SET_PROCESS2("Not Set");
#endif
/* Return the page */
@@ -937,9 +937,8 @@ MiInsertPageInList(IN PMMPFNLIST ListHead,
ColorHead->Count++;
#if MI_TRACE_PFNS
- //ASSERT(MI_PFN_CURRENT_USAGE == MI_USAGE_NOT_SET);
+ ASSERT(MI_PFN_CURRENT_USAGE == MI_USAGE_NOT_SET);
Pfn1->PfnUsage = MI_USAGE_FREE_PAGE;
- MI_PFN_CURRENT_USAGE = MI_USAGE_NOT_SET;
RtlZeroMemory(Pfn1->ProcessName, 16);
#endif
}
diff --git a/ntoskrnl/mm/ARM3/sysldr.c b/ntoskrnl/mm/ARM3/sysldr.c
index 0ebcae75e29..745543403f4 100644
--- a/ntoskrnl/mm/ARM3/sysldr.c
+++ b/ntoskrnl/mm/ARM3/sysldr.c
@@ -188,14 +188,7 @@ MiLoadImageSection(_Inout_ PSECTION *SectionPtr,
/* Some debug stuff */
MI_SET_USAGE(MI_USAGE_DRIVER_PAGE);
#if MI_TRACE_PFNS
- if (FileName->Buffer)
- {
- PWCHAR pos = NULL;
- ULONG len = 0;
- pos = wcsrchr(FileName->Buffer, '\\');
- len = wcslen(pos) * sizeof(WCHAR);
- if (pos) snprintf(MI_PFN_CURRENT_PROCESS_NAME, min(16, len), "%S",
pos);
- }
+ MI_SET_PROCESS_USTR(FileName);
#endif
/* Grab a page */
diff --git a/ntoskrnl/mm/freelist.c b/ntoskrnl/mm/freelist.c
index 4aa15a12582..b00cf1fbc04 100644
--- a/ntoskrnl/mm/freelist.c
+++ b/ntoskrnl/mm/freelist.c
@@ -610,6 +610,21 @@ MmAllocPage(ULONG Type)
OldIrql = MiAcquirePfnLock();
+#if MI_TRACE_PFNS
+ switch(Type)
+ {
+ case MC_CACHE:
+ case MC_SYSTEM:
+ MI_SET_USAGE(MI_USAGE_CACHE);
+ break;
+ case MC_USER:
+ MI_SET_USAGE(MI_USAGE_SECTION);
+ break;
+ default:
+ ASSERT(FALSE);
+ }
+#endif
+
PfnOffset = MiRemoveZeroPage(MI_GET_NEXT_COLOR());
if (!PfnOffset)
{
diff --git a/ntoskrnl/mm/section.c b/ntoskrnl/mm/section.c
index b3e300a58cc..3ff8098937d 100644
--- a/ntoskrnl/mm/section.c
+++ b/ntoskrnl/mm/section.c
@@ -1803,9 +1803,6 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
MmUnlockSectionSegment(Segment);
MmUnlockAddressSpace(AddressSpace);
- MI_SET_USAGE(MI_USAGE_SECTION);
- if (Process) MI_SET_PROCESS2(Process->ImageFileName);
- if (!Process) MI_SET_PROCESS2("Kernel Section");
Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &Page);
if (!NT_SUCCESS(Status))
{
@@ -1975,9 +1972,6 @@ MmAccessFaultSectionView(PMMSUPPORT AddressSpace,
/*
* Allocate a page
*/
- MI_SET_USAGE(MI_USAGE_SECTION);
- if (Process) MI_SET_PROCESS2(Process->ImageFileName);
- if (!Process) MI_SET_PROCESS2("Kernel Section");
Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &NewPage);
if (!NT_SUCCESS(Status))
{