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 MiFindInitializationCode(OUT PVOID
*StartVa
,
32 MiFreeInitializationCode(IN PVOID StartVa
,
37 MmZeroPageThread(VOID
)
39 PKTHREAD Thread
= KeGetCurrentThread();
40 PVOID StartAddress
, EndAddress
;
44 PFN_NUMBER PageIndex
, FreePage
;
47 /* Get the discardable sections to free them */
48 MiFindInitializationCode(&StartAddress
, &EndAddress
);
49 if (StartAddress
) MiFreeInitializationCode(StartAddress
, EndAddress
);
50 DPRINT1("Free non-cache pages: %lx\n", MmAvailablePages
+ MiMemoryConsumers
[MC_CACHE
].PagesUsed
);
52 /* Set our priority to 0 */
53 Thread
->BasePriority
= 0;
54 KeSetPriorityThread(Thread
, 0);
56 /* Setup the wait objects */
57 WaitObjects
[0] = &MmZeroingPageEvent
;
58 // WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
62 KeWaitForMultipleObjects(1, // 2
70 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
73 if (!MmFreePageListHead
.Total
)
75 MmZeroingPageThreadActive
= FALSE
;
76 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
80 PageIndex
= MmFreePageListHead
.Flink
;
81 ASSERT(PageIndex
!= LIST_HEAD
);
82 Pfn1
= MiGetPfnEntry(PageIndex
);
83 MI_SET_USAGE(MI_USAGE_ZERO_LOOP
);
84 MI_SET_PROCESS2("Kernel 0 Loop");
85 FreePage
= MiRemoveAnyPage(MI_GET_PAGE_COLOR(PageIndex
));
87 /* The first global free page should also be the first on its own list */
88 if (FreePage
!= PageIndex
)
90 KeBugCheckEx(PFN_LIST_CORRUPT
,
97 Pfn1
->u1
.Flink
= LIST_HEAD
;
98 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
100 ZeroAddress
= MiMapPagesInZeroSpace(Pfn1
, 1);
102 RtlZeroMemory(ZeroAddress
, PAGE_SIZE
);
103 MiUnmapPagesInZeroSpace(ZeroAddress
, 1);
105 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
107 MiInsertPageInList(&MmZeroedPageListHead
, PageIndex
);