ReactOS  0.4.15-dev-1171-gab82533
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 
21 
22 /* PRIVATE FUNCTIONS **********************************************************/
23 
24 VOID
25 NTAPI
27 OUT PVOID *EndVa);
28 
29 VOID
30 NTAPI
32 IN PVOID EndVa);
33 
34 VOID
35 NTAPI
37 {
39  PVOID StartAddress, EndAddress;
40  PVOID WaitObjects[2];
41  KIRQL OldIrql;
42  PVOID ZeroAddress;
43  PFN_NUMBER PageIndex, FreePage;
44  PMMPFN Pfn1;
45 
46  /* Get the discardable sections to free them */
47  MiFindInitializationCode(&StartAddress, &EndAddress);
48  if (StartAddress) MiFreeInitializationCode(StartAddress, EndAddress);
49  DPRINT("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
50 
51  /* Set our priority to 0 */
52  Thread->BasePriority = 0;
54 
55  /* Setup the wait objects */
56  WaitObjects[0] = &MmZeroingPageEvent;
57 // WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
58 
59  while (TRUE)
60  {
62  WaitObjects,
63  WaitAny,
64  WrFreePage,
65  KernelMode,
66  FALSE,
67  NULL,
68  NULL);
70 
71  while (TRUE)
72  {
74  {
77  break;
78  }
79 
80  PageIndex = MmFreePageListHead.Flink;
81  ASSERT(PageIndex != LIST_HEAD);
82  Pfn1 = MiGetPfnEntry(PageIndex);
84  MI_SET_PROCESS2("Kernel 0 Loop");
86 
87  /* The first global free page should also be the first on its own list */
88  if (FreePage != PageIndex)
89  {
90  KeBugCheckEx(PFN_LIST_CORRUPT,
91  0x8F,
92  FreePage,
93  PageIndex,
94  0);
95  }
96 
97  Pfn1->u1.Flink = LIST_HEAD;
99 
100  ZeroAddress = MiMapPagesInZeroSpace(Pfn1, 1);
101  ASSERT(ZeroAddress);
102  RtlZeroMemory(ZeroAddress, PAGE_SIZE);
103  MiUnmapPagesInZeroSpace(ZeroAddress, 1);
104 
106 
108  }
109  }
110 }
111 
112 /* EOF */
VOID NTAPI MmZeroPageThread(VOID)
Definition: zeropage.c:36
#define IN
Definition: typedefs.h:39
KEVENT MmZeroingPageEvent
Definition: zeropage.c:20
MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM]
Definition: balance.c:36
#define TRUE
Definition: types.h:120
VOID NTAPI MiFindInitializationCode(OUT PVOID *StartVa, OUT PVOID *EndVa)
Definition: sysldr.c:1451
PFN_NUMBER Flink
Definition: mm.h:309
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:901
PFN_NUMBER MmAvailablePages
Definition: freelist.c:26
MMPFNLIST MmZeroedPageListHead
Definition: pfnlist.c:41
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:908
PFN_NUMBER Flink
Definition: mm.h:373
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:254
smooth NULL
Definition: ftsmooth.c:416
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:253
VOID NTAPI MiFreeInitializationCode(IN PVOID StartVa, IN PVOID EndVa)
Definition: sysldr.c:1428
_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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PVOID NTAPI MiMapPagesInZeroSpace(IN PMMPFN Pfn1, IN PFN_NUMBER NumberOfPages)
Definition: hypermap.c:113
union _MMPFN::@1774 u1
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: mm.h:305
#define PAGE_SIZE
Definition: env_spec_w32.h:49
LIST_HEAD(acpi_bus_event_list)
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:940
#define MI_GET_PAGE_COLOR(x)
Definition: miarm.h:237
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:371
#define MC_CACHE
Definition: mm.h:93
#define OUT
Definition: typedefs.h:40
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define KeGetCurrentThread
Definition: hal.h:44
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
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:108