ReactOS  0.4.15-dev-3203-gacde1e0
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 
42  /* Get the discardable sections to free them */
43  MiFindInitializationCode(&StartAddress, &EndAddress);
44  if (StartAddress) MiFreeInitializationCode(StartAddress, EndAddress);
45  DPRINT("Free pages: %lx\n", MmAvailablePages);
46 
47  /* Set our priority to 0 */
48  Thread->BasePriority = 0;
50 
51  /* Setup the wait objects */
52  WaitObjects[0] = &MmZeroingPageEvent;
53 // WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
54 
55  while (TRUE)
56  {
57  KIRQL OldIrql;
58 
60  WaitObjects,
61  WaitAny,
62  WrFreePage,
63  KernelMode,
64  FALSE,
65  NULL,
66  NULL);
67  OldIrql = MiAcquirePfnLock();
68 
69  while (TRUE)
70  {
71  ULONG PageCount = 0;
72  PMMPFN Pfn1 = (PMMPFN)LIST_HEAD;
73  PVOID ZeroAddress;
74  PFN_NUMBER PageIndex, FreePage;
75 
76  while (PageCount < MI_ZERO_PTES)
77  {
78  PMMPFN Pfn2;
79 
81  break;
82 
83  PageIndex = MmFreePageListHead.Flink;
84  ASSERT(PageIndex != LIST_HEAD);
86  MI_SET_PROCESS2("Kernel 0 Loop");
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  Pfn2 = MiGetPfnEntry(PageIndex);
100  Pfn2->u1.Flink = (PFN_NUMBER)Pfn1;
101  Pfn1 = Pfn2;
102  PageCount++;
103  }
104  MiReleasePfnLock(OldIrql);
105 
106  if (PageCount == 0)
107  {
109  break;
110  }
111 
112  ZeroAddress = MiMapPagesInZeroSpace(Pfn1, PageCount);
113  ASSERT(ZeroAddress);
114  KeZeroPages(ZeroAddress, PageCount * PAGE_SIZE);
115  MiUnmapPagesInZeroSpace(ZeroAddress, PageCount);
116 
117  OldIrql = MiAcquirePfnLock();
118 
119  while (Pfn1 != (PMMPFN)LIST_HEAD)
120  {
121  PageIndex = MiGetPfnEntryIndex(Pfn1);
122  Pfn1 = (PMMPFN)Pfn1->u1.Flink;
124  }
125  }
126  }
127 }
128 
129 /* EOF */
VOID NTAPI MmZeroPageThread(VOID)
Definition: zeropage.c:36
union _MMPFN::@1746 u1
#define IN
Definition: typedefs.h:39
KEVENT MmZeroingPageEvent
Definition: zeropage.c:20
#define TRUE
Definition: types.h:120
VOID NTAPI MiFindInitializationCode(OUT PVOID *StartVa, OUT PVOID *EndVa)
Definition: sysldr.c:1450
PFN_NUMBER Flink
Definition: mm.h:366
PFN_NUMBER MmAvailablePages
Definition: freelist.c:26
MMPFNLIST MmZeroedPageListHead
Definition: pfnlist.c:41
PFN_NUMBER Flink
Definition: mm.h:434
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG PFN_NUMBER
Definition: ke.h:9
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:308
VOID NTAPI MiInsertPageInList(IN PMMPFNLIST ListHead, IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:771
#define MI_SET_USAGE(x)
Definition: mm.h:306
KIRQL OldIrql
Definition: mm.h:1502
VOID FASTCALL KeZeroPages(IN PVOID Address, IN ULONG Size)
Definition: cpu.c:56
VOID NTAPI MiFreeInitializationCode(IN PVOID StartVa, IN PVOID EndVa)
Definition: sysldr.c:1427
#define ASSERT(a)
Definition: mode.c:44
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
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:111
Definition: mm.h:362
#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:1000
#define MI_GET_PAGE_COLOR(x)
Definition: miarm.h:236
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:477
VOID NTAPI MiUnmapPagesInZeroSpace(IN PVOID VirtualAddress, IN PFN_NUMBER NumberOfPages)
Definition: hypermap.c:187
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1327
PFN_NUMBER Total
Definition: mm.h:432
struct _MMPFN * PMMPFN
#define NULL
Definition: types.h:112
FORCEINLINE PFN_NUMBER MiGetPfnEntryIndex(IN PMMPFN Pfn1)
Definition: mm.h:1020
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71
#define KeGetCurrentThread
Definition: hal.h:55
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define MI_ZERO_PTES
Definition: mm.h:82
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