Skip to content

Commit a38d98d

Browse files
author
Sir Richard
committed
[NTOS]: At times, pages may be removed from the zero or free page list, but without being initialized as part of the PFN database, such that their PageLocation has not changed. However, we can detect these pages because their link pointers will be NULL, meaning they're not _really_ free or zeroed. Use this enhanced check when verifying if a page is in use or not, and additionally triple-check by making sure the reference count is zero. This now matches the Windows checks. We also consider Standby pages (not yet implemented) as usable, since we can always steal them.
svn path=/trunk/; revision=47148
1 parent b6b0074 commit a38d98d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

reactos/ntoskrnl/mm/freelist.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,23 @@ MmRemoveLRUUserPage(PFN_TYPE Page)
128128
RtlClearBit(&MiUserPfnBitMap, Page);
129129
}
130130

131+
BOOLEAN
132+
NTAPI
133+
MiIsPfnFree(IN PMMPFN Pfn1)
134+
{
135+
/* Must be a free or zero page, with no references, linked */
136+
return ((Pfn1->u3.e1.PageLocation <= StandbyPageList) &&
137+
(Pfn1->u1.Flink) &&
138+
(Pfn1->u2.Blink) &&
139+
!(Pfn1->u3.e2.ReferenceCount));
140+
}
141+
131142
BOOLEAN
132143
NTAPI
133144
MiIsPfnInUse(IN PMMPFN Pfn1)
134145
{
135-
return ((Pfn1->u3.e1.PageLocation != FreePageList) &&
136-
(Pfn1->u3.e1.PageLocation != ZeroedPageList));
146+
/* Standby list or higher, unlinked, and with references */
147+
return !MiIsPfnFree(Pfn1);
137148
}
138149

139150
PFN_NUMBER

0 commit comments

Comments
 (0)