Skip to content

Commit 71e8fc8

Browse files
author
Sir Richard
committed
[NTOS]: Fix straggling bugs in color table algorithms.
[NTOS]: Enable color tables! Right now pages are merely entering and exiting the tables, the tables themselves are never used for allocations. This will change with further commits. svn path=/trunk/; revision=48926
1 parent f41dde7 commit 71e8fc8

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

reactos/ntoskrnl/mm/ARM3/miarm.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,25 @@ extern const ULONG MmProtectToPteMask[32];
194194
#define MM_SYSLDR_BOOT_LOADED (PVOID)0xFFFFFFFF
195195
#define MM_SYSLDR_SINGLE_ENTRY 0x1
196196

197+
#if defined(_M_IX86) || defined(_M_ARM)
197198
//
198199
// PFN List Sentinel
199200
//
200201
#define LIST_HEAD 0xFFFFFFFF
201202

203+
//
204+
// Because GCC cannot automatically downcast 0xFFFFFFFF to lesser-width bits,
205+
// we need a manual definition suited to the number of bits in the PteFrame.
206+
// This is used as a LIST_HEAD for the colored list
207+
//
208+
#define COLORED_LIST_HEAD ((1 << 25) - 1) // 0x1FFFFFF
209+
#elif defined(_M_AMD64)
210+
#define LIST_HEAD 0xFFFFFFFFFFFFFFFFLL
211+
#define COLORED_LIST_HEAD ((1 << 57) - 1) // 0x1FFFFFFFFFFFFFFLL
212+
#else
213+
#error Define these please!
214+
#endif
215+
202216
//
203217
// Special IRQL value (found in assertions)
204218
//

reactos/ntoskrnl/mm/ARM3/pfnlist.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ do { \
3030
#define ASSERT_LIST_INVARIANT(x)
3131
#endif
3232

33+
#define ARM3_COLORS 1
34+
3335
/* GLOBALS ********************************************************************/
3436

3537
BOOLEAN MmDynamicPfn;
@@ -133,11 +135,9 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
133135
/* Get the page color */
134136
OldBlink = MiGetPfnEntryIndex(Entry);
135137
Color = OldBlink & MmSecondaryColorMask;
136-
DPRINT1("Color: %lx\n", Color);
137138

138139
/* Get the first page on the color list */
139140
ColorTable = &MmFreePagesByColor[ListName][Color];
140-
DPRINT1("Color table: %p %lx\n", ColorTable, ColorTable->Flink);
141141

142142
/* Check if this was was actually the head */
143143
OldFlink = ColorTable->Flink;
@@ -148,7 +148,7 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
148148
if (ColorTable->Flink != LIST_HEAD)
149149
{
150150
/* And make the previous link point to the head now */
151-
MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = -1;
151+
MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = COLORED_LIST_HEAD;
152152
}
153153
else
154154
{
@@ -159,7 +159,7 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
159159
else
160160
{
161161
/* This page shouldn't be pointing back to the head */
162-
ASSERT(Entry->u4.PteFrame != -1);
162+
ASSERT(Entry->u4.PteFrame != COLORED_LIST_HEAD);
163163

164164
/* Make the back link point to whoever the next page is */
165165
Pfn1 = MiGetPfnEntry(Entry->u4.PteFrame);
@@ -170,7 +170,7 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
170170
{
171171
/* Make the back link point to the head */
172172
Pfn1 = MiGetPfnEntry(Entry->OriginalPte.u.Long);
173-
Pfn1->u4.PteFrame = -1;
173+
Pfn1->u4.PteFrame = Entry->u4.PteFrame;
174174
}
175175
else
176176
{
@@ -182,6 +182,9 @@ MiUnlinkFreeOrZeroedPage(IN PMMPFN Entry)
182182
/* One less colored page */
183183
ASSERT(ColorTable->Count >= 1);
184184
ColorTable->Count--;
185+
186+
/* ReactOS Hack */
187+
Entry->OriginalPte.u.Long = 0;
185188
#endif
186189
/* We are not on a list anymore */
187190
Entry->u1.Flink = Entry->u2.Blink = 0;
@@ -284,8 +287,6 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
284287
ASSERT(ColorTable->Count >= 1);
285288

286289
/* Set the forward link to whoever we were pointing to */
287-
DPRINT1("Has RMAP: %lx (link: %lx)\n", Pfn1->u3.e1.ParityError, Pfn1->OriginalPte.u.Long);
288-
DPRINT1("Color table: %p %lx\n", ColorTable, ColorTable->Flink);
289290
ColorTable->Flink = Pfn1->OriginalPte.u.Long;
290291

291292
/* Get the first page on the color list */
@@ -297,11 +298,14 @@ MiRemovePageByColor(IN PFN_NUMBER PageIndex,
297298
else
298299
{
299300
/* The list is empty, so we are the first page */
300-
MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = -1;
301+
MiGetPfnEntry(ColorTable->Flink)->u4.PteFrame = COLORED_LIST_HEAD;
301302
}
302303

303304
/* One less page */
304305
ColorTable->Count--;
306+
307+
/* ReactOS Hack */
308+
Pfn1->OriginalPte.u.Long = 0;
305309
#endif
306310
/* See if we hit any thresholds */
307311
if (MmAvailablePages == MmHighMemoryThreshold)
@@ -536,16 +540,13 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
536540
#ifdef ARM3_COLORS
537541
/* Get the page color */
538542
Color = PageFrameIndex & MmSecondaryColorMask;
539-
DPRINT1("Color: %lx\n", Color);
540543

541544
/* Get the first page on the color list */
542545
ColorTable = &MmFreePagesByColor[FreePageList][Color];
543-
DPRINT1("Color table: %p %lx\n", ColorTable, ColorTable->Flink);
544-
DPRINT1("Has RMAP: %lx (link: %lx)\n", Pfn1->u3.e1.ParityError, Pfn1->OriginalPte.u.Long);
545546
if (ColorTable->Flink == LIST_HEAD)
546547
{
547548
/* The list is empty, so we are the first page */
548-
Pfn1->u4.PteFrame = -1;
549+
Pfn1->u4.PteFrame = COLORED_LIST_HEAD;
549550
ColorTable->Flink = PageFrameIndex;
550551
}
551552
else
@@ -557,7 +558,6 @@ MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
557558
Pfn1->u4.PteFrame = MiGetPfnEntryIndex(Blink);
558559

559560
/* If there is an original pte, it should be an old link, NOT a ReactOS RMAP */
560-
DPRINT1("Has RMAP: %lx (link: %lx)\n", Blink->u3.e1.ParityError, Blink->OriginalPte.u.Long);
561561
ASSERT(Blink->u3.e1.ParityError == FALSE);
562562
Blink->OriginalPte.u.Long = PageFrameIndex;
563563
}
@@ -663,7 +663,6 @@ MiInsertPageInList(IN PMMPFNLIST ListHead,
663663

664664
/* Get the page color */
665665
Color = PageFrameIndex & MmSecondaryColorMask;
666-
DPRINT1("Color: %lx\n", Color);
667666

668667
/* Get the list for this color */
669668
ColorHead = &MmFreePagesByColor[ZeroedPageList][Color];
@@ -676,7 +675,7 @@ MiInsertPageInList(IN PMMPFNLIST ListHead,
676675

677676
/* Make this page point back to the list, and point forwards to the old head */
678677
Pfn1->OriginalPte.u.Long = Flink;
679-
Pfn1->u4.PteFrame = -1;
678+
Pfn1->u4.PteFrame = COLORED_LIST_HEAD;
680679

681680
/* Set the new head */
682681
ColorHead->Flink = PageFrameIndex;
@@ -849,7 +848,7 @@ MiDecrementShareCount(IN PMMPFN Pfn1,
849848
* ways we shouldn't be seeing RMAP entries at this point
850849
*/
851850
ASSERT(Pfn1->OriginalPte.u.Soft.Prototype == 0);
852-
ASSERT(Pfn1->OriginalPte.u.Long == 0);
851+
ASSERT(Pfn1->u3.e1.ParityError == FALSE);
853852

854853
/* Mark the page temporarily as valid, we're going to make it free soon */
855854
Pfn1->u3.e1.PageLocation = ActiveAndValid;

0 commit comments

Comments
 (0)