2010-09-28 16:47:25 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
|
|
|
* FILE: ntoskrnl/mm/ARM3/zeropage.c
|
|
|
|
* PURPOSE: ARM Memory Manager Zero Page Thread Support
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#define MODULE_INVOLVED_IN_ARM3
|
2014-11-10 16:26:55 +00:00
|
|
|
#include <mm/ARM3/miarm.h>
|
2010-09-28 16:47:25 +00:00
|
|
|
|
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
|
|
|
BOOLEAN MmZeroingPageThreadActive;
|
|
|
|
KEVENT MmZeroingPageEvent;
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
|
2012-02-17 22:57:32 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
MiFindInitializationCode(OUT PVOID *StartVa,
|
|
|
|
OUT PVOID *EndVa);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
MiFreeInitializationCode(IN PVOID StartVa,
|
|
|
|
IN PVOID EndVa);
|
|
|
|
|
2010-09-28 16:47:25 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
MmZeroPageThread(VOID)
|
|
|
|
{
|
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
2012-02-17 22:57:32 +00:00
|
|
|
PVOID StartAddress, EndAddress;
|
2010-09-28 16:47:25 +00:00
|
|
|
PVOID WaitObjects[2];
|
|
|
|
KIRQL OldIrql;
|
|
|
|
PVOID ZeroAddress;
|
|
|
|
PFN_NUMBER PageIndex, FreePage;
|
|
|
|
PMMPFN Pfn1;
|
2010-12-26 15:23:03 +00:00
|
|
|
|
2012-02-17 22:57:32 +00:00
|
|
|
/* Get the discardable sections to free them */
|
|
|
|
MiFindInitializationCode(&StartAddress, &EndAddress);
|
|
|
|
if (StartAddress) MiFreeInitializationCode(StartAddress, EndAddress);
|
2014-11-02 11:30:14 +00:00
|
|
|
DPRINT("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
|
2010-09-28 16:47:25 +00:00
|
|
|
|
|
|
|
/* Set our priority to 0 */
|
|
|
|
Thread->BasePriority = 0;
|
|
|
|
KeSetPriorityThread(Thread, 0);
|
2010-12-26 15:23:03 +00:00
|
|
|
|
2010-09-28 16:47:25 +00:00
|
|
|
/* Setup the wait objects */
|
|
|
|
WaitObjects[0] = &MmZeroingPageEvent;
|
|
|
|
// WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2011-09-11 16:56:56 +00:00
|
|
|
KeWaitForMultipleObjects(1, // 2
|
|
|
|
WaitObjects,
|
|
|
|
WaitAny,
|
|
|
|
WrFreePage,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2017-11-21 22:33:42 +00:00
|
|
|
OldIrql = MiAcquirePfnLock();
|
2016-10-18 20:19:00 +00:00
|
|
|
|
2010-09-28 16:47:25 +00:00
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (!MmFreePageListHead.Total)
|
|
|
|
{
|
|
|
|
MmZeroingPageThreadActive = FALSE;
|
2017-11-21 22:33:42 +00:00
|
|
|
MiReleasePfnLock(OldIrql);
|
2010-09-28 16:47:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PageIndex = MmFreePageListHead.Flink;
|
2010-09-29 01:10:28 +00:00
|
|
|
ASSERT(PageIndex != LIST_HEAD);
|
2010-09-28 16:47:25 +00:00
|
|
|
Pfn1 = MiGetPfnEntry(PageIndex);
|
2010-11-02 15:16:22 +00:00
|
|
|
MI_SET_USAGE(MI_USAGE_ZERO_LOOP);
|
|
|
|
MI_SET_PROCESS2("Kernel 0 Loop");
|
2010-09-29 01:10:28 +00:00
|
|
|
FreePage = MiRemoveAnyPage(MI_GET_PAGE_COLOR(PageIndex));
|
2010-12-26 15:23:03 +00:00
|
|
|
|
2010-09-29 01:10:28 +00:00
|
|
|
/* The first global free page should also be the first on its own list */
|
2010-09-28 16:47:25 +00:00
|
|
|
if (FreePage != PageIndex)
|
|
|
|
{
|
|
|
|
KeBugCheckEx(PFN_LIST_CORRUPT,
|
|
|
|
0x8F,
|
|
|
|
FreePage,
|
|
|
|
PageIndex,
|
|
|
|
0);
|
|
|
|
}
|
2010-12-26 15:23:03 +00:00
|
|
|
|
2010-09-28 16:47:25 +00:00
|
|
|
Pfn1->u1.Flink = LIST_HEAD;
|
2017-11-21 22:33:42 +00:00
|
|
|
MiReleasePfnLock(OldIrql);
|
2010-12-26 15:23:03 +00:00
|
|
|
|
2011-12-19 18:44:47 +00:00
|
|
|
ZeroAddress = MiMapPagesInZeroSpace(Pfn1, 1);
|
2010-09-28 16:47:25 +00:00
|
|
|
ASSERT(ZeroAddress);
|
|
|
|
RtlZeroMemory(ZeroAddress, PAGE_SIZE);
|
|
|
|
MiUnmapPagesInZeroSpace(ZeroAddress, 1);
|
2010-12-26 15:23:03 +00:00
|
|
|
|
2017-11-21 22:33:42 +00:00
|
|
|
OldIrql = MiAcquirePfnLock();
|
2010-09-28 16:47:25 +00:00
|
|
|
|
|
|
|
MiInsertPageInList(&MmZeroedPageListHead, PageIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|