ReactOS 0.4.15-dev-8116-gf69e256
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{
30
31 DPRINT("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
32
34 {
35 DPRINT1("Page fault at high IRQL was %u\n", KeGetCurrentIrql());
36 return(STATUS_UNSUCCESSFUL);
37 }
38
39 /*
40 * Find the memory area for the faulting address
41 */
43 {
44 /*
45 * Check permissions
46 */
47 if (Mode != KernelMode)
48 {
49 DPRINT1("MmAccessFault(Mode %d, Address %x)\n", Mode, Address);
51 }
53 }
54 else
55 {
57 }
58
59 if (!FromMdl)
60 {
62 }
63 do
64 {
67 {
68 if (!FromMdl)
69 {
71 }
73 }
74
75 switch (MemoryArea->Type)
76 {
81 !FromMdl);
82 break;
83#ifdef NEWCC
84 case MEMORY_AREA_CACHE:
85 // This code locks for itself to keep from having to break a lock
86 // passed in.
87 if (!FromMdl)
90 if (!FromMdl)
92 break;
93#endif
94 default:
96 break;
97 }
98 }
100
101 DPRINT("Completed page fault handling\n");
102 if (!FromMdl)
103 {
105 }
106 return(Status);
107}
108
110NTAPI
113 BOOLEAN FromMdl)
114{
118
119 DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
120
122 {
123 DPRINT1("Page fault at high IRQL was %u, address %x\n", KeGetCurrentIrql(), Address);
124 return(STATUS_UNSUCCESSFUL);
125 }
126
127 /*
128 * Find the memory area for the faulting address
129 */
131 {
132 /*
133 * Check permissions
134 */
135 if (Mode != KernelMode)
136 {
137 DPRINT1("Address: %x\n", Address);
139 }
141 }
142 else
143 {
145 }
146
147 if (!FromMdl)
148 {
150 }
151
152 /*
153 * Call the memory area specific fault handler
154 */
155 do
156 {
159 {
160 if (!FromMdl)
161 {
163 }
165 }
166
167 switch (MemoryArea->Type)
168 {
172 (PVOID)Address,
173 !FromMdl);
174 break;
175#ifdef NEWCC
176 case MEMORY_AREA_CACHE:
177 // This code locks for itself to keep from having to break a lock
178 // passed in.
179 if (!FromMdl)
182 if (!FromMdl)
184 break;
185#endif
186 default:
188 break;
189 }
190 }
192
193 DPRINT("Completed page fault handling\n");
194 if (!FromMdl)
195 {
197 }
198 return(Status);
199}
200
202
203VOID
204NTAPI
206
208NTAPI
212 IN PVOID TrapInformation)
213{
216 BOOLEAN IsArm3Fault = FALSE;
217
218 /* Cute little hack for ROS */
220 {
221#ifdef _M_IX86
222 /* Check for an invalid page directory in kernel mode */
224 {
225 /* All is well with the world */
226 return STATUS_SUCCESS;
227 }
228#endif
229 }
230
231 /* Handle shared user page / page table, which don't have a VAD / MemoryArea */
234 {
235 /* This is an ARM3 fault */
236 DPRINT("ARM3 fault %p\n", Address);
237 return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
238 }
239
240 /* Is there a ReactOS address space yet? */
242 {
244 {
245 /* Check if this is an ARM3 memory area */
248
250 {
251 IsArm3Fault = TRUE;
252 }
253
255 }
256 else
257 {
258 /* Could this be a VAD fault from user-mode? */
261
263 {
264 IsArm3Fault = TRUE;
265 }
266
268 }
269 }
270
271 /* Is this an ARM3 memory area, or is there no address space yet? */
272 if (IsArm3Fault ||
273 ((MemoryArea == NULL) &&
277 {
278 /* This is an ARM3 fault */
279 DPRINT("ARM3 fault %p\n", MemoryArea);
280 return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
281 }
282
283Retry:
284 /* Keep same old ReactOS Behaviour */
285 if (!MI_IS_NOT_PRESENT_FAULT(FaultCode))
286 {
287 /* Call access fault */
288 Status = MmpAccessFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE);
289 }
290 else
291 {
292 /* Call not present */
293 Status = MmNotPresentFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE);
294 }
295
297 {
299 goto Retry;
300 }
301
302 return Status;
303}
304
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:111
NTSTATUS NTAPI MmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: mmfault.c:209
NTSTATUS NTAPI MmpAccessFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
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_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