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 #line 15 "ARMĀ³::ZEROPAGE"
16 #define MODULE_INVOLVED_IN_ARM3
17 #include "../ARM3/miarm.h"
19 /* GLOBALS ********************************************************************/
21 BOOLEAN MmZeroingPageThreadActive
;
22 KEVENT MmZeroingPageEvent
;
24 /* PRIVATE FUNCTIONS **********************************************************/
28 MmZeroPageThread(VOID
)
30 PKTHREAD Thread
= KeGetCurrentThread();
31 //PVOID StartAddress, EndAddress;
36 PFN_NUMBER PageIndex
, FreePage
;
39 /* FIXME: Get the discardable sections to free them */
40 // MiFindInitializationCode(&StartAddress, &EndAddress);
41 // if (StartAddress) MiFreeInitializationCode(StartAddress, EndAddress);
42 DPRINT1("Free non-cache pages: %lx\n", MmAvailablePages
+ MiMemoryConsumers
[MC_CACHE
].PagesUsed
);
44 /* Set our priority to 0 */
45 Thread
->BasePriority
= 0;
46 KeSetPriorityThread(Thread
, 0);
48 /* Setup the wait objects */
49 WaitObjects
[0] = &MmZeroingPageEvent
;
50 // WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
54 Status
= KeWaitForMultipleObjects(1, // 2
62 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
65 if (!MmFreePageListHead
.Total
)
67 MmZeroingPageThreadActive
= FALSE
;
68 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
72 PageIndex
= MmFreePageListHead
.Flink
;
73 ASSERT(PageIndex
!= LIST_HEAD
);
74 Pfn1
= MiGetPfnEntry(PageIndex
);
75 MI_SET_USAGE(MI_USAGE_ZERO_LOOP
);
76 MI_SET_PROCESS2("Kernel 0 Loop");
77 FreePage
= MiRemoveAnyPage(MI_GET_PAGE_COLOR(PageIndex
));
79 /* The first global free page should also be the first on its own list */
80 if (FreePage
!= PageIndex
)
82 KeBugCheckEx(PFN_LIST_CORRUPT
,
89 Pfn1
->u1
.Flink
= LIST_HEAD
;
90 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
92 ZeroAddress
= MiMapPagesToZeroInHyperSpace(Pfn1
, 1);
94 RtlZeroMemory(ZeroAddress
, PAGE_SIZE
);
95 MiUnmapPagesInZeroSpace(ZeroAddress
, 1);
97 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
99 MiInsertPageInList(&MmZeroedPageListHead
, PageIndex
);