ReactOS  0.4.14-dev-50-g13bb5e2
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 managment 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 
22 NTAPI
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  }
72  return (STATUS_ACCESS_VIOLATION);
73  }
74 
75  switch (MemoryArea->Type)
76  {
79  MemoryArea,
80  (PVOID)Address);
81  break;
82 
83  case MEMORY_AREA_CACHE:
84  // This code locks for itself to keep from having to break a lock
85  // passed in.
86  if (!FromMdl)
89  if (!FromMdl)
91  break;
92 
93  default:
95  break;
96  }
97  }
99 
100  DPRINT("Completed page fault handling\n");
101  if (!FromMdl)
102  {
104  }
105  return(Status);
106 }
107 
108 NTSTATUS
109 NTAPI
112  BOOLEAN FromMdl)
113 {
117 
118  DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
119 
121  {
122  DPRINT1("Page fault at high IRQL was %u, address %x\n", KeGetCurrentIrql(), Address);
123  return(STATUS_UNSUCCESSFUL);
124  }
125 
126  /*
127  * Find the memory area for the faulting address
128  */
130  {
131  /*
132  * Check permissions
133  */
134  if (Mode != KernelMode)
135  {
136  DPRINT1("Address: %x\n", Address);
137  return(STATUS_ACCESS_VIOLATION);
138  }
140  }
141  else
142  {
144  }
145 
146  if (!FromMdl)
147  {
149  }
150 
151  /*
152  * Call the memory area specific fault handler
153  */
154  do
155  {
158  {
159  if (!FromMdl)
160  {
162  }
163  return (STATUS_ACCESS_VIOLATION);
164  }
165 
166  switch (MemoryArea->Type)
167  {
170  MemoryArea,
171  (PVOID)Address,
172  FromMdl);
173  break;
174 
175  case MEMORY_AREA_CACHE:
176  // This code locks for itself to keep from having to break a lock
177  // passed in.
178  if (!FromMdl)
181  if (!FromMdl)
183  break;
184 
185  default:
187  break;
188  }
189  }
191 
192  DPRINT("Completed page fault handling\n");
193  if (!FromMdl)
194  {
196  }
197  return(Status);
198 }
199 
201 
202 NTSTATUS
203 NTAPI
205  IN PVOID Address,
207  IN PVOID TrapInformation)
208 {
210 
211  /* Cute little hack for ROS */
213  {
214 #ifdef _M_IX86
215  /* Check for an invalid page directory in kernel mode */
217  {
218  /* All is well with the world */
219  return STATUS_SUCCESS;
220  }
221 #endif
222  }
223 
224  /* Handle shared user page, which doesn't have a VAD / MemoryArea */
226  {
227  /* This is an ARM3 fault */
228  DPRINT("ARM3 fault %p\n", MemoryArea);
229  return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
230  }
231 
232  /* Is there a ReactOS address space yet? */
234  {
235  /* Check if this is an ARM3 memory area */
238  {
239  /* Could this be a VAD fault from user-mode? */
241  }
242  }
243 
244  /* Is this an ARM3 memory area, or is there no address space yet? */
248  {
249  /* This is an ARM3 fault */
250  DPRINT("ARM3 fault %p\n", MemoryArea);
251  return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
252  }
253 
254  /* Keep same old ReactOS Behaviour */
255  if (!MI_IS_NOT_PRESENT_FAULT(FaultCode))
256  {
257  /* Call access fault */
258  return MmpAccessFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE);
259  }
260  else
261  {
262  /* Call not present */
263  return MmNotPresentFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE);
264  }
265 }
266 
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
NTSTATUS NTAPI MmAccessFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address)
Definition: section.c:1797
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define MI_IS_NOT_PRESENT_FAULT(FaultCode)
Definition: mm.h:118
ULONG Type
Definition: mm.h:214
_In_ ULONG Mode
Definition: hubbusif.h:303
#define STATUS_MM_RESTART_OPERATION
Definition: mm.h:80
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
LONG NTSTATUS
Definition: precomp.h:26
#define MM_SHARED_USER_DATA_VA
Definition: mmtypes.h:48
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MEMORY_AREA_CACHE
Definition: mm.h:72
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
NTSTATUS NTAPI MmpAccessFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: mmfault.c:23
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
BOOLEAN DeleteInProgress
Definition: mm.h:217
#define PAGE_ALIGN(Va)
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
BOOLEAN Mmi386MakeKernelPageTableGlobal(PVOID Address)
Definition: page.c:476
NTSTATUS NTAPI MmNotPresentFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: fault.c:907
Status
Definition: gdiplustypes.h:24
PVOID MmPagedPoolStart
Definition: miarm.h:589
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
NTSTATUS NTAPI MmNotPresentFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: mmfault.c:110
NTSTATUS NTAPI MmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: mmfault.c:204
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI MmAccessFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: fault.c:688
NTSTATUS NTAPI MmArmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: pagfault.c:1650
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1364
return STATUS_SUCCESS
Definition: btrfs.c:2966
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424
#define MmSystemRangeStart
Definition: mm.h:32
FORCEINLINE PMMSUPPORT MmGetCurrentAddressSpace(VOID)
Definition: mm.h:1446