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);
43 /* Set our priority to 0 */
44 Thread
->BasePriority
= 0;
45 KeSetPriorityThread(Thread
, 0);
47 /* Setup the wait objects */
48 WaitObjects
[0] = &MmZeroingPageEvent
;
49 // WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
53 Status
= KeWaitForMultipleObjects(1, // 2
61 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
64 if (!MmFreePageListHead
.Total
)
66 MmZeroingPageThreadActive
= FALSE
;
67 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
71 PageIndex
= MmFreePageListHead
.Flink
;
72 ASSERT(PageIndex
!= LIST_HEAD
);
73 Pfn1
= MiGetPfnEntry(PageIndex
);
74 FreePage
= MiRemoveAnyPage(MI_GET_PAGE_COLOR(PageIndex
));
76 /* The first global free page should also be the first on its own list */
77 if (FreePage
!= PageIndex
)
79 KeBugCheckEx(PFN_LIST_CORRUPT
,
86 Pfn1
->u1
.Flink
= LIST_HEAD
;
87 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
89 ZeroAddress
= MiMapPagesToZeroInHyperSpace(Pfn1
, 1);
91 RtlZeroMemory(ZeroAddress
, PAGE_SIZE
);
92 MiUnmapPagesInZeroSpace(ZeroAddress
, 1);
94 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
96 MiInsertPageInList(&MmZeroedPageListHead
, PageIndex
);