Author: tkreuzer
Date: Sat Nov 14 05:08:54 2009
New Revision: 44147
URL:
http://svn.reactos.org/svn/reactos?rev=44147&view=rev
Log:
The freelist code is an increadible hack. It #defines structure members to other structure
members and misuses them. Try to improve the hack by declaring PHYSICAL_PAGE as a unioun
of MMPFN and the stuff that is used in the freelist code. Exchange the positions of
RmapListHead with MapCount as the former must be pointer sized. More work is required
here.
Modified:
branches/ros-amd64-bringup/reactos/ntoskrnl/mm/freelist.c
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/mm/freelist.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] Sat Nov 14
05:08:54 2009
@@ -32,23 +32,45 @@
//
// ReactOS to NT Physical Page Descriptor Entry Legacy Mapping Definitions
//
-// REACTOS NT
-//
-#define Consumer PageLocation
-#define Type CacheAttribute
-#define Zero PrototypePte
-#define LockCount u3.e1.PageColor
-#define RmapListHead AweReferenceCount
-#define SavedSwapEntry u4.EntireFrame
-#define Flags u3.e1
-#define ReferenceCount u3.ReferenceCount
-#define RemoveEntryList(x) RemoveEntryList((PLIST_ENTRY)x)
-#define InsertTailList(x, y) InsertTailList(x, (PLIST_ENTRY)y)
-#define ListEntry u1
-#define PHYSICAL_PAGE MMPFN
-#define PPHYSICAL_PAGE PMMPFN
-
-PPHYSICAL_PAGE MmPfnDatabase;
+
+typedef union
+{
+ MMPFN Pfn;
+
+ struct
+ {
+ LIST_ENTRY ListEntry; // 0x000
+ ULONG_PTR RmapListHead; // 0x008
+ USHORT ReferenceCount; // 0x00C
+ struct // 0x00$
+ {
+ USHORT _unused1:1;
+ USHORT StartOfAllocation:1;
+ USHORT EndOfAllocation:1;
+ USHORT Zero:1;
+ USHORT LockCount:4;
+ USHORT Consumer:3;
+ USHORT _unused2:1;
+ USHORT Type:2;
+ USHORT _unused3:1;
+ USHORT _unused4:1;
+ } Flags;
+ LONG MapCount; // 0x10
+ ULONG_PTR SavedSwapEntry; // 0x018
+ };
+} PHYSICAL_PAGE, *PPHYSICAL_PAGE;
+
+C_ASSERT(sizeof(PHYSICAL_PAGE) == sizeof(MMPFN));
+
+#define MiGetPfnEntry(Pfn) ((PPHYSICAL_PAGE)MiGetPfnEntry(Pfn))
+#define MiGetPfnEntryIndex(x) MiGetPfnEntryIndex((struct _MMPFN*)x)
+#define LockCount Flags.LockCount
+
+PMMPFN MmPfnDatabase;
+#define MmPfnDatabase ((PPHYSICAL_PAGE)MmPfnDatabase)
+
+#define MMPFN PHYSICAL_PAGE
+#define PMMPFN PPHYSICAL_PAGE
ULONG MmAvailablePages;
ULONG MmResidentAvailablePages;
@@ -99,7 +121,7 @@
return 0;
}
PageDescriptor = CONTAINING_RECORD(NextListEntry, PHYSICAL_PAGE, ListEntry);
- ASSERT_PFN(PageDescriptor);
+ ASSERT_PFN(&PageDescriptor->Pfn);
KeReleaseQueuedSpinLock(LockQueuePfnLock, oldIrql);
return PageDescriptor - MmPfnDatabase;
}
@@ -731,12 +753,10 @@
NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
NextEntry = NextEntry->Flink)
{
-#undef ListEntry
/* Get the descriptor */
Md = CONTAINING_RECORD(NextEntry,
MEMORY_ALLOCATION_DESCRIPTOR,
ListEntry);
-#define ListEntry u1
/* Skip bad memory */
if ((Md->MemoryType == LoaderFirmwarePermanent) ||
@@ -800,7 +820,7 @@
KIRQL oldIrql;
oldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
- MiGetPfnEntry(Pfn)->RmapListHead = (LONG)ListHead;
+ MiGetPfnEntry(Pfn)->RmapListHead = (LONG_PTR)ListHead;
KeReleaseQueuedSpinLock(LockQueuePfnLock, oldIrql);
}
@@ -929,7 +949,7 @@
{
MmAvailablePages++;
if (Page->Flags.Consumer == MC_USER) RemoveEntryList(&Page->ListEntry);
- if (Page->RmapListHead != (LONG)NULL)
+ if (Page->RmapListHead != (LONG_PTR)NULL)
{
DPRINT1("Freeing page with rmap entries.\n");
KeBugCheck(MEMORY_MANAGEMENT);