2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/mm/ARM3/zeropage.c
5 * PURPOSE: ARM Memory Manager Zero Page Thread Support
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 #define MODULE_INVOLVED_IN_ARM3
16 #include "../ARM3/miarm.h"
18 /* GLOBALS ********************************************************************/
20 BOOLEAN MmZeroingPageThreadActive
;
21 KEVENT MmZeroingPageEvent
;
23 /* PRIVATE FUNCTIONS **********************************************************/
27 MmZeroPageThread(VOID
)
29 PKTHREAD Thread
= KeGetCurrentThread();
30 //PVOID StartAddress, EndAddress;
34 PFN_NUMBER PageIndex
, FreePage
;
37 /* FIXME: Get the discardable sections to free them */
38 // MiFindInitializationCode(&StartAddress, &EndAddress);
39 // if (StartAddress) MiFreeInitializationCode(StartAddress, EndAddress);
40 DPRINT1("Free non-cache pages: %lx\n", MmAvailablePages
+ MiMemoryConsumers
[MC_CACHE
].PagesUsed
);
42 /* Set our priority to 0 */
43 Thread
->BasePriority
= 0;
44 KeSetPriorityThread(Thread
, 0);
46 /* Setup the wait objects */
47 WaitObjects
[0] = &MmZeroingPageEvent
;
48 // WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
52 KeWaitForMultipleObjects(1, // 2
60 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
63 if (!MmFreePageListHead
.Total
)
65 MmZeroingPageThreadActive
= FALSE
;
66 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
70 PageIndex
= MmFreePageListHead
.Flink
;
71 ASSERT(PageIndex
!= LIST_HEAD
);
72 Pfn1
= MiGetPfnEntry(PageIndex
);
73 MI_SET_USAGE(MI_USAGE_ZERO_LOOP
);
74 MI_SET_PROCESS2("Kernel 0 Loop");
75 FreePage
= MiRemoveAnyPage(MI_GET_PAGE_COLOR(PageIndex
));
77 /* The first global free page should also be the first on its own list */
78 if (FreePage
!= PageIndex
)
80 KeBugCheckEx(PFN_LIST_CORRUPT
,
87 Pfn1
->u1
.Flink
= LIST_HEAD
;
88 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
90 ZeroAddress
= MiMapPagesInZeroSpace(Pfn1
, 1);
92 RtlZeroMemory(ZeroAddress
, PAGE_SIZE
);
93 MiUnmapPagesInZeroSpace(ZeroAddress
, 1);
95 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
97 MiInsertPageInList(&MmZeroedPageListHead
, PageIndex
);