mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 22:02:58 +00:00
Add invariant checks and fix a bug: Copy+Paste error misusing OldFlink
svn path=/trunk/; revision=47510
This commit is contained in:
parent
5e80db9d5e
commit
5fafb51079
1 changed files with 44 additions and 3 deletions
|
@ -16,6 +16,16 @@
|
||||||
#define MODULE_INVOLVED_IN_ARM3
|
#define MODULE_INVOLVED_IN_ARM3
|
||||||
#include "../ARM3/miarm.h"
|
#include "../ARM3/miarm.h"
|
||||||
|
|
||||||
|
#define ASSERT_LIST_INVARIANT(x) \
|
||||||
|
do { \
|
||||||
|
ASSERT(((x)->Total == 0 && \
|
||||||
|
(x)->Flink == LIST_HEAD && \
|
||||||
|
(x)->Blink == LIST_HEAD) || \
|
||||||
|
((x)->Total != 0 && \
|
||||||
|
(x)->Flink != LIST_HEAD && \
|
||||||
|
(x)->Blink != LIST_HEAD)); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/* GLOBALS ********************************************************************/
|
/* GLOBALS ********************************************************************/
|
||||||
|
|
||||||
BOOLEAN MmDynamicPfn;
|
BOOLEAN MmDynamicPfn;
|
||||||
|
@ -49,6 +59,9 @@ MiInsertInListTail(IN PMMPFNLIST ListHead,
|
||||||
{
|
{
|
||||||
PFN_NUMBER OldBlink, EntryIndex = MiGetPfnEntryIndex(Entry);
|
PFN_NUMBER OldBlink, EntryIndex = MiGetPfnEntryIndex(Entry);
|
||||||
|
|
||||||
|
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
/* Get the back link */
|
/* Get the back link */
|
||||||
OldBlink = ListHead->Blink;
|
OldBlink = ListHead->Blink;
|
||||||
if (OldBlink != LIST_HEAD)
|
if (OldBlink != LIST_HEAD)
|
||||||
|
@ -69,6 +82,7 @@ MiInsertInListTail(IN PMMPFNLIST ListHead,
|
||||||
/* And now the head points back to us, since we are last */
|
/* And now the head points back to us, since we are last */
|
||||||
ListHead->Blink = EntryIndex;
|
ListHead->Blink = EntryIndex;
|
||||||
ListHead->Total++;
|
ListHead->Total++;
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
@ -97,6 +111,7 @@ MiInsertZeroListAtBack(IN PFN_NUMBER EntryIndex)
|
||||||
|
|
||||||
/* Use the zero list */
|
/* Use the zero list */
|
||||||
ListHead = &MmZeroedPageListHead;
|
ListHead = &MmZeroedPageListHead;
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
ListHead->Total++;
|
ListHead->Total++;
|
||||||
|
|
||||||
/* Get the back link */
|
/* Get the back link */
|
||||||
|
@ -136,6 +151,9 @@ MiInsertZeroListAtBack(IN PFN_NUMBER EntryIndex)
|
||||||
/* Otherwise check if we reached the high threshold and signal the event */
|
/* Otherwise check if we reached the high threshold and signal the event */
|
||||||
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Get the page color */
|
/* Get the page color */
|
||||||
Color = EntryIndex & MmSecondaryColorMask;
|
Color = EntryIndex & MmSecondaryColorMask;
|
||||||
|
@ -187,6 +205,7 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
|
||||||
ListName = ListHead->ListName;
|
ListName = ListHead->ListName;
|
||||||
ASSERT(ListHead != NULL);
|
ASSERT(ListHead != NULL);
|
||||||
ASSERT(ListName <= FreePageList);
|
ASSERT(ListName <= FreePageList);
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
/* Remove one count */
|
/* Remove one count */
|
||||||
ASSERT(ListHead->Total != 0);
|
ASSERT(ListHead->Total != 0);
|
||||||
|
@ -205,7 +224,7 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Set the list head's backlink instead */
|
/* Set the list head's backlink instead */
|
||||||
ListHead->Blink = OldFlink;
|
ListHead->Blink = OldBlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the back entry is the list head */
|
/* Check if the back entry is the list head */
|
||||||
|
@ -222,6 +241,7 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
|
||||||
|
|
||||||
/* We are not on a list anymore */
|
/* We are not on a list anymore */
|
||||||
Entry->u1.Flink = Entry->u2.Blink = 0;
|
Entry->u1.Flink = Entry->u2.Blink = 0;
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
/* FIXME: Deal with color list */
|
/* FIXME: Deal with color list */
|
||||||
|
|
||||||
|
@ -272,6 +292,7 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
|
||||||
|
|
||||||
/* Could be either on free or zero list */
|
/* Could be either on free or zero list */
|
||||||
ListHead = MmPageLocationList[Pfn1->u3.e1.PageLocation];
|
ListHead = MmPageLocationList[Pfn1->u3.e1.PageLocation];
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
ListName = ListHead->ListName;
|
ListName = ListHead->ListName;
|
||||||
ASSERT(ListName <= FreePageList);
|
ASSERT(ListName <= FreePageList);
|
||||||
|
|
||||||
|
@ -313,6 +334,9 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
|
||||||
Pfn1->u3.e2.ShortFlags = 0;
|
Pfn1->u3.e2.ShortFlags = 0;
|
||||||
Pfn1->u3.e1.PageColor = OldColor;
|
Pfn1->u3.e1.PageColor = OldColor;
|
||||||
Pfn1->u3.e1.CacheAttribute = OldCache;
|
Pfn1->u3.e1.CacheAttribute = OldCache;
|
||||||
|
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
#if 0 // When switching to ARM3
|
#if 0 // When switching to ARM3
|
||||||
/* Get the first page on the color list */
|
/* Get the first page on the color list */
|
||||||
ColorTable = &MmFreePagesByColor[ListName][Color];
|
ColorTable = &MmFreePagesByColor[ListName][Color];
|
||||||
|
@ -379,12 +403,13 @@ MiRemoveAnyPage(IN ULONG Color)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
/* Check the free list */
|
/* Check the free list */
|
||||||
|
ASSERT_LIST_INVARIANT(&MmFreePageListHead);
|
||||||
PageIndex = MmFreePageListHead.Flink;
|
PageIndex = MmFreePageListHead.Flink;
|
||||||
Color = PageIndex & MmSecondaryColorMask;
|
Color = PageIndex & MmSecondaryColorMask;
|
||||||
if (PageIndex == LIST_HEAD)
|
if (PageIndex == LIST_HEAD)
|
||||||
{
|
{
|
||||||
/* Check the zero list */
|
/* Check the zero list */
|
||||||
ASSERT(MmFreePageListHead.Total == 0);
|
ASSERT_LIST_INVARIANT(&MmZeroedPageListHead);
|
||||||
PageIndex = MmZeroedPageListHead.Flink;
|
PageIndex = MmZeroedPageListHead.Flink;
|
||||||
Color = PageIndex & MmSecondaryColorMask;
|
Color = PageIndex & MmSecondaryColorMask;
|
||||||
ASSERT(PageIndex != LIST_HEAD);
|
ASSERT(PageIndex != LIST_HEAD);
|
||||||
|
@ -410,6 +435,9 @@ MiRemoveAnyPage(IN ULONG Color)
|
||||||
ASSERT(Pfn1->u2.ShareCount == 0);
|
ASSERT(Pfn1->u2.ShareCount == 0);
|
||||||
|
|
||||||
/* Return the page */
|
/* Return the page */
|
||||||
|
ASSERT_LIST_INVARIANT(&MmFreePageListHead);
|
||||||
|
ASSERT_LIST_INVARIANT(&MmZeroedPageListHead);
|
||||||
|
|
||||||
return PageIndex;
|
return PageIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,6 +448,9 @@ MiRemoveHeadList(IN PMMPFNLIST ListHead)
|
||||||
PFN_NUMBER Entry, Flink;
|
PFN_NUMBER Entry, Flink;
|
||||||
PMMPFN Pfn1;
|
PMMPFN Pfn1;
|
||||||
|
|
||||||
|
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
/* Get the entry that's currently first on the list */
|
/* Get the entry that's currently first on the list */
|
||||||
Entry = ListHead->Flink;
|
Entry = ListHead->Flink;
|
||||||
Pfn1 = MiGetPfnEntry(Entry);
|
Pfn1 = MiGetPfnEntry(Entry);
|
||||||
|
@ -444,6 +475,8 @@ MiRemoveHeadList(IN PMMPFNLIST ListHead)
|
||||||
Pfn1->u1.Flink = Pfn1->u2.Blink = 0;
|
Pfn1->u1.Flink = Pfn1->u2.Blink = 0;
|
||||||
ListHead->Total--;
|
ListHead->Total--;
|
||||||
|
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
/* Return the head element */
|
/* Return the head element */
|
||||||
return Pfn1;
|
return Pfn1;
|
||||||
}
|
}
|
||||||
|
@ -461,6 +494,7 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
|
||||||
PMMCOLOR_TABLES ColorTable;
|
PMMCOLOR_TABLES ColorTable;
|
||||||
#endif
|
#endif
|
||||||
/* Make sure the page index is valid */
|
/* Make sure the page index is valid */
|
||||||
|
ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL);
|
||||||
ASSERT((PageFrameIndex != 0) &&
|
ASSERT((PageFrameIndex != 0) &&
|
||||||
(PageFrameIndex <= MmHighestPhysicalPage) &&
|
(PageFrameIndex <= MmHighestPhysicalPage) &&
|
||||||
(PageFrameIndex >= MmLowestPhysicalPage));
|
(PageFrameIndex >= MmLowestPhysicalPage));
|
||||||
|
@ -477,6 +511,7 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
|
||||||
|
|
||||||
/* Get the free page list and increment its count */
|
/* Get the free page list and increment its count */
|
||||||
ListHead = &MmFreePageListHead;
|
ListHead = &MmFreePageListHead;
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
ListHead->Total++;
|
ListHead->Total++;
|
||||||
|
|
||||||
/* Get the last page on the list */
|
/* Get the last page on the list */
|
||||||
|
@ -522,6 +557,8 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
|
||||||
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
KeSetEvent(MiHighMemoryEvent, 0, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT_LIST_INVARIANT(ListHead);
|
||||||
|
|
||||||
#if 0 // When using ARM3 PFN
|
#if 0 // When using ARM3 PFN
|
||||||
/* Get the page color */
|
/* Get the page color */
|
||||||
Color = PageFrameIndex & MmSecondaryColorMask;
|
Color = PageFrameIndex & MmSecondaryColorMask;
|
||||||
|
@ -641,6 +678,8 @@ MiAllocatePfn(IN PMMPTE PointerPte,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grab a page */
|
/* Grab a page */
|
||||||
|
ASSERT_LIST_INVARIANT(&MmFreePageListHead);
|
||||||
|
ASSERT_LIST_INVARIANT(&MmZeroedPageListHead);
|
||||||
PageFrameIndex = MiRemoveAnyPage(0);
|
PageFrameIndex = MiRemoveAnyPage(0);
|
||||||
|
|
||||||
/* Write the software PTE */
|
/* Write the software PTE */
|
||||||
|
@ -652,6 +691,8 @@ MiAllocatePfn(IN PMMPTE PointerPte,
|
||||||
MiInitializePfn(PageFrameIndex, PointerPte, TRUE);
|
MiInitializePfn(PageFrameIndex, PointerPte, TRUE);
|
||||||
|
|
||||||
/* Release the PFN lock and return the page */
|
/* Release the PFN lock and return the page */
|
||||||
|
ASSERT_LIST_INVARIANT(&MmFreePageListHead);
|
||||||
|
ASSERT_LIST_INVARIANT(&MmZeroedPageListHead);
|
||||||
KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
|
KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
|
||||||
return PageFrameIndex;
|
return PageFrameIndex;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue