ReactOS  r75907
zeropage.c
Go to the documentation of this file.
1 /*
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
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 #define MODULE_INVOLVED_IN_ARM3
16 #include <mm/ARM3/miarm.h>
17 
18 /* GLOBALS ********************************************************************/
19 
22 
23 /* PRIVATE FUNCTIONS **********************************************************/
24 
25 VOID
26 NTAPI
28 OUT PVOID *EndVa);
29 
30 VOID
31 NTAPI
33 IN PVOID EndVa);
34 
35 VOID
36 NTAPI
38 {
40  PVOID StartAddress, EndAddress;
41  PVOID WaitObjects[2];
42  KIRQL OldIrql;
43  PVOID ZeroAddress;
44  PFN_NUMBER PageIndex, FreePage;
45  PMMPFN Pfn1;
46 
47  /* Get the discardable sections to free them */
48  MiFindInitializationCode(&StartAddress, &EndAddress);
49  if (StartAddress) MiFreeInitializationCode(StartAddress, EndAddress);
50  DPRINT("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
51 
52  /* Set our priority to 0 */
53  Thread->BasePriority = 0;
54  KeSetPriorityThread(Thread, 0);
55 
56  /* Setup the wait objects */
57  WaitObjects[0] = &MmZeroingPageEvent;
58 // WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
59 
60  while (TRUE)
61  {
63  WaitObjects,
64  WaitAny,
65  WrFreePage,
66  KernelMode,
67  FALSE,
68  NULL,
69  NULL);
72 
73  while (TRUE)
74  {
76  {
79  break;
80  }
81 
82  PageIndex = MmFreePageListHead.Flink;
83  ASSERT(PageIndex != LIST_HEAD);
84  Pfn1 = MiGetPfnEntry(PageIndex);
86  MI_SET_PROCESS2("Kernel 0 Loop");
87  FreePage = MiRemoveAnyPage(MI_GET_PAGE_COLOR(PageIndex));
88 
89  /* The first global free page should also be the first on its own list */
90  if (FreePage != PageIndex)
91  {
92  KeBugCheckEx(PFN_LIST_CORRUPT,
93  0x8F,
94  FreePage,
95  PageIndex,
96  0);
97  }
98 
99  Pfn1->u1.Flink = LIST_HEAD;
101 
102  ZeroAddress = MiMapPagesInZeroSpace(Pfn1, 1);
103  ASSERT(ZeroAddress);
104  RtlZeroMemory(ZeroAddress, PAGE_SIZE);
105  MiUnmapPagesInZeroSpace(ZeroAddress, 1);
106 
108 
110  }
111  }
112 }
113 
114 /* EOF */
DWORD *typedef PVOID
Definition: winlogon.h:52
VOID NTAPI MmZeroPageThread(VOID)
Definition: zeropage.c:37
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
KEVENT MmZeroingPageEvent
Definition: zeropage.c:21
MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM]
Definition: balance.c:36
BOOLEAN MmZeroingPageThreadActive
Definition: zeropage.c:20
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID NTAPI MiFindInitializationCode(OUT PVOID *StartVa, OUT PVOID *EndVa)
Definition: sysldr.c:1450
PFN_NUMBER Flink
Definition: mm.h:305
PFN_NUMBER MmAvailablePages
Definition: freelist.c:26
MMPFNLIST MmZeroedPageListHead
Definition: pfnlist.c:41
PFN_NUMBER Flink
Definition: mm.h:369
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG PFN_NUMBER
Definition: ke.h:8
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define MI_SET_PROCESS2(x)
Definition: mm.h:250
smooth NULL
Definition: ftsmooth.c:513
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI MiInsertPageInList(IN PMMPFNLIST ListHead, IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:778
#define MI_SET_USAGE(x)
Definition: mm.h:249
union _MMPFN::@1600 u1
SCHAR BasePriority
Definition: ketypes.h:1209
unsigned char BOOLEAN
VOID NTAPI MiFreeInitializationCode(IN PVOID StartVa, IN PVOID EndVa)
Definition: sysldr.c:1427
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
PVOID NTAPI MiMapPagesInZeroSpace(IN PMMPFN Pfn1, IN PFN_NUMBER NumberOfPages)
Definition: hypermap.c:113
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: mm.h:301
#define PAGE_SIZE
Definition: env_spec_w32.h:49
LIST_HEAD(acpi_bus_event_list)
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:873
#define MI_GET_PAGE_COLOR(x)
Definition: miarm.h:208
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:475
VOID NTAPI MiUnmapPagesInZeroSpace(IN PVOID VirtualAddress, IN PFN_NUMBER NumberOfPages)
Definition: hypermap.c:185
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1327
PFN_NUMBER Total
Definition: mm.h:367
#define MC_CACHE
Definition: mm.h:91
#define OUT
Definition: typedefs.h:40
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define KeGetCurrentThread
Definition: hal.h:44
MMPFNLIST MmFreePageListHead
Definition: pfnlist.c:42
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:90