ReactOS 0.4.16-dev-91-g764881a
mmfault.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/mm/mmfault.c
5 * PURPOSE: Kernel memory management functions
6 * PROGRAMMERS: David Welch (welch@cwcom.net)
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <ntoskrnl.h>
12#include <cache/section/newmm.h>
13#define NDEBUG
14#include <debug.h>
15
16#define MODULE_INVOLVED_IN_ARM3
17#include "ARM3/miarm.h"
18
19/* PRIVATE FUNCTIONS **********************************************************/
20
25 BOOLEAN FromMdl,
26 ULONG FaultCode)
27{
31
32 DPRINT("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
33
35 {
36 DPRINT1("Page fault at high IRQL was %u\n", KeGetCurrentIrql());
37 return(STATUS_UNSUCCESSFUL);
38 }
39
40 /* Instruction fetch and the page is present.
41 This means the page is NX and we cannot do anything to "fix" it. */
42 if (MI_IS_INSTRUCTION_FETCH(FaultCode))
43 {
44 DPRINT1("Page fault instruction fetch at %p\n", Address);
46 }
47
48 /*
49 * Find the memory area for the faulting address
50 */
52 {
53 /*
54 * Check permissions
55 */
56 if (Mode != KernelMode)
57 {
58 DPRINT1("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
60 }
62 }
63 else
64 {
66 }
67
68 if (!FromMdl)
69 {
71 }
72 do
73 {
76 {
77 if (!FromMdl)
78 {
80 }
82 }
83
84 switch (MemoryArea->Type)
85 {
90 !FromMdl);
91 break;
92#ifdef NEWCC
93 case MEMORY_AREA_CACHE:
94 // This code locks for itself to keep from having to break a lock
95 // passed in.
96 if (!FromMdl)
99 if (!FromMdl)
101 break;
102#endif
103 default:
105 break;
106 }
107 }
109
110 DPRINT("Completed page fault handling\n");
111 if (!FromMdl)
112 {
114 }
115 return(Status);
116}
117
119NTAPI
122 BOOLEAN FromMdl)
123{
127
128 DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
129
131 {
132 DPRINT1("Page fault at high IRQL was %u, address %x\n", KeGetCurrentIrql(), Address);
133 return(STATUS_UNSUCCESSFUL);
134 }
135
136 /*
137 * Find the memory area for the faulting address
138 */
140 {
141 /*
142 * Check permissions
143 */
144 if (Mode != KernelMode)
145 {
146 DPRINT1("Address: %x\n", Address);
148 }
150 }
151 else
152 {
154 }
155
156 if (!FromMdl)
157 {
159 }
160
161 /*
162 * Call the memory area specific fault handler
163 */
164 do
165 {
168 {
169 if (!FromMdl)
170 {
172 }
174 }
175
176 switch (MemoryArea->Type)
177 {
181 (PVOID)Address,
182 !FromMdl);
183 break;
184#ifdef NEWCC
185 case MEMORY_AREA_CACHE:
186 // This code locks for itself to keep from having to break a lock
187 // passed in.
188 if (!FromMdl)
191 if (!FromMdl)
193 break;
194#endif
195 default:
197 break;
198 }
199 }
201
202 DPRINT("Completed page fault handling\n");
203 if (!FromMdl)
204 {
206 }
207 return(Status);
208}
209
211
212VOID
213NTAPI
215
217NTAPI
221 IN PVOID TrapInformation)
222{
225 BOOLEAN IsArm3Fault = FALSE;
226
227 /* Cute little hack for ROS */
229 {
230#ifdef _M_IX86
231 /* Check for an invalid page directory in kernel mode */
233 {
234 /* All is well with the world */
235 return STATUS_SUCCESS;
236 }
237#endif
238 }
239
240 /* Handle shared user page / page table, which don't have a VAD / MemoryArea */
243 {
244 /* This is an ARM3 fault */
245 DPRINT("ARM3 fault %p\n", Address);
246 return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
247 }
248
249 /* Is there a ReactOS address space yet? */
251 {
253 {
254 /* Check if this is an ARM3 memory area */
257
259 {
260 IsArm3Fault = TRUE;
261 }
262
264 }
265 else
266 {
267 /* Could this be a VAD fault from user-mode? */
270
272 {
273 IsArm3Fault = TRUE;
274 }
275
277 }
278 }
279
280 /* Is this an ARM3 memory area, or is there no address space yet? */
281 if (IsArm3Fault ||
282 ((MemoryArea == NULL) &&
286 {
287 /* This is an ARM3 fault */
288 DPRINT("ARM3 fault %p\n", MemoryArea);
289 return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
290 }
291
292Retry:
293 /* Keep same old ReactOS Behaviour */
294 if (!MI_IS_NOT_PRESENT_FAULT(FaultCode))
295 {
296 /* Call access fault */
297 Status = MmpAccessFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE, FaultCode);
298 }
299 else
300 {
301 /* Call not present */
302 Status = MmNotPresentFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE);
303 }
304
306 {
308 goto Retry;
309 }
310
311 return Status;
312}
313
unsigned char BOOLEAN
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ PSCSI_REQUEST_BLOCK _Out_ NTSTATUS _Inout_ BOOLEAN * Retry
Definition: classpnp.h:312
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
Status
Definition: gdiplustypes.h:25
_In_ ULONG Mode
Definition: hubbusif.h:303
FORCEINLINE VOID MiLockProcessWorkingSetShared(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1146
PVOID MmPagedPoolStart
Definition: miarm.h:574
FORCEINLINE VOID MiUnlockProcessWorkingSetShared(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1215
#define MI_IS_PAGE_TABLE_ADDRESS(Address)
Definition: miarm.h:177
NTSTATUS NTAPI MmArmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: pagfault.c:1698
FORCEINLINE VOID MiLockWorkingSetShared(_In_ PETHREAD Thread, _In_ PMMSUPPORT WorkingSet)
Definition: miarm.h:1306
FORCEINLINE VOID MiUnlockWorkingSetShared(_In_ PETHREAD Thread, _In_ PMMSUPPORT WorkingSet)
Definition: miarm.h:1389
BOOLEAN Mmi386MakeKernelPageTableGlobal(PVOID Address)
Definition: pagepae.c:844
VOID NTAPI MmRebalanceMemoryConsumersAndWait(VOID)
Definition: balance.c:300
NTSTATUS NTAPI MmNotPresentFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: mmfault.c:120
NTSTATUS NTAPI MmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: mmfault.c:218
NTSTATUS NTAPI MmpAccessFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl, ULONG FaultCode)
Definition: mmfault.c:23
#define KernelMode
Definition: asm.h:34
#define MM_SHARED_USER_DATA_VA
Definition: mmtypes.h:48
NTSTATUS NTAPI MmAccessFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
_In_ PMEMORY_AREA MemoryArea
Definition: newmm.h:207
NTSTATUS NTAPI MmNotPresentFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
#define MI_IS_INSTRUCTION_FETCH(FaultCode)
Definition: mm.h:125
#define MI_IS_NOT_PRESENT_FAULT(FaultCode)
Definition: mm.h:121
#define MmSystemRangeStart
Definition: mm.h:32
FORCEINLINE PMMSUPPORT MmGetCurrentAddressSpace(VOID)
Definition: mm.h:1719
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1691
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1532
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:97
NTSTATUS NTAPI MmAccessFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1910
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1704
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:93
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1726
#define STATUS_MM_RESTART_OPERATION
Definition: mm.h:104
MMSUPPORT MmSystemCacheWs
Definition: init.c:55
PVOID MmPagedPoolEnd
Definition: init.c:26
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
static WCHAR Address[46]
Definition: ping.c:68
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
BOOLEAN DeleteInProgress
Definition: mm.h:253
ULONG Type
Definition: mm.h:251
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define PAGE_ALIGN(Va)
#define PsGetCurrentProcess
Definition: psfuncs.h:17