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)
9 /* INCLUDES *******************************************************************/
15 #define MODULE_INVOLVED_IN_ARM3
16 #include "ARM3/miarm.h"
18 /* PRIVATE FUNCTIONS **********************************************************/
22 MmpAccessFault(KPROCESSOR_MODE Mode
,
26 PMMSUPPORT AddressSpace
;
27 MEMORY_AREA
* MemoryArea
;
29 BOOLEAN Locked
= FromMdl
;
31 DPRINT("MmAccessFault(Mode %d, Address %x)\n", Mode
, Address
);
33 if (KeGetCurrentIrql() >= DISPATCH_LEVEL
)
35 DPRINT1("Page fault at high IRQL was %d\n", KeGetCurrentIrql());
36 return(STATUS_UNSUCCESSFUL
);
40 * Find the memory area for the faulting address
42 if (Address
>= (ULONG_PTR
)MmSystemRangeStart
)
47 if (Mode
!= KernelMode
)
49 DPRINT1("MmAccessFault(Mode %d, Address %x)\n", Mode
, Address
);
50 return(STATUS_ACCESS_VIOLATION
);
52 AddressSpace
= MmGetKernelAddressSpace();
56 AddressSpace
= &PsGetCurrentProcess()->Vm
;
61 MmLockAddressSpace(AddressSpace
);
65 MemoryArea
= MmLocateMemoryAreaByAddress(AddressSpace
, (PVOID
)Address
);
66 if (MemoryArea
== NULL
|| MemoryArea
->DeleteInProgress
)
70 MmUnlockAddressSpace(AddressSpace
);
72 return (STATUS_ACCESS_VIOLATION
);
75 switch (MemoryArea
->Type
)
77 case MEMORY_AREA_SECTION_VIEW
:
78 Status
= MmAccessFaultSectionView(AddressSpace
,
84 case MEMORY_AREA_VIRTUAL_MEMORY
:
85 Status
= STATUS_ACCESS_VIOLATION
;
89 Status
= STATUS_ACCESS_VIOLATION
;
93 while (Status
== STATUS_MM_RESTART_OPERATION
);
95 DPRINT("Completed page fault handling\n");
98 MmUnlockAddressSpace(AddressSpace
);
105 MmNotPresentFault(KPROCESSOR_MODE Mode
,
109 PMMSUPPORT AddressSpace
;
110 MEMORY_AREA
* MemoryArea
;
112 BOOLEAN Locked
= FromMdl
;
114 DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode
, Address
);
116 if (KeGetCurrentIrql() >= DISPATCH_LEVEL
)
118 DPRINT1("Page fault at high IRQL was %d, address %x\n", KeGetCurrentIrql(), Address
);
119 return(STATUS_UNSUCCESSFUL
);
123 * Find the memory area for the faulting address
125 if (Address
>= (ULONG_PTR
)MmSystemRangeStart
)
130 if (Mode
!= KernelMode
)
132 DPRINT1("Address: %x\n", Address
);
133 return(STATUS_ACCESS_VIOLATION
);
135 AddressSpace
= MmGetKernelAddressSpace();
139 AddressSpace
= &PsGetCurrentProcess()->Vm
;
144 MmLockAddressSpace(AddressSpace
);
148 * Call the memory area specific fault handler
152 MemoryArea
= MmLocateMemoryAreaByAddress(AddressSpace
, (PVOID
)Address
);
153 if (MemoryArea
== NULL
|| MemoryArea
->DeleteInProgress
)
157 MmUnlockAddressSpace(AddressSpace
);
159 return (STATUS_ACCESS_VIOLATION
);
162 switch (MemoryArea
->Type
)
164 case MEMORY_AREA_SECTION_VIEW
:
165 Status
= MmNotPresentFaultSectionView(AddressSpace
,
171 case MEMORY_AREA_VIRTUAL_MEMORY
:
172 Status
= MmNotPresentFaultVirtualMemory(AddressSpace
,
179 Status
= STATUS_ACCESS_VIOLATION
;
183 while (Status
== STATUS_MM_RESTART_OPERATION
);
185 DPRINT("Completed page fault handling\n");
188 MmUnlockAddressSpace(AddressSpace
);
193 extern BOOLEAN
Mmi386MakeKernelPageTableGlobal(PVOID Address
);
197 MmAccessFault(IN BOOLEAN StoreInstruction
,
199 IN KPROCESSOR_MODE Mode
,
200 IN PVOID TrapInformation
)
202 PMEMORY_AREA MemoryArea
= NULL
;
204 /* Cute little hack for ROS */
205 if ((ULONG_PTR
)Address
>= (ULONG_PTR
)MmSystemRangeStart
)
208 /* Check for an invalid page directory in kernel mode */
209 if (Mmi386MakeKernelPageTableGlobal(Address
))
211 /* All is well with the world */
212 return STATUS_SUCCESS
;
217 /* Is there a ReactOS address space yet? */
218 if (MmGetKernelAddressSpace())
220 /* Check if this is an ARM3 memory area */
221 MemoryArea
= MmLocateMemoryAreaByAddress(MmGetKernelAddressSpace(), Address
);
222 if (!(MemoryArea
) && (Address
<= MM_HIGHEST_USER_ADDRESS
))
224 /* Could this be a VAD fault from user-mode? */
225 MemoryArea
= MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address
);
229 /* Is this an ARM3 memory area, or is there no address space yet? */
230 if (((MemoryArea
) && (MemoryArea
->Type
== MEMORY_AREA_OWNED_BY_ARM3
)) ||
231 (!(MemoryArea
) && ((ULONG_PTR
)Address
>= (ULONG_PTR
)MmPagedPoolStart
)) ||
232 (!MmGetKernelAddressSpace()))
234 /* This is an ARM3 fault */
235 DPRINT("ARM3 fault %p\n", MemoryArea
);
236 return MmArmAccessFault(StoreInstruction
, Address
, Mode
, TrapInformation
);
239 /* Keep same old ReactOS Behaviour */
240 if (StoreInstruction
)
242 /* Call access fault */
243 return MmpAccessFault(Mode
, (ULONG_PTR
)Address
, TrapInformation
? FALSE
: TRUE
);
247 /* Call not present */
248 return MmNotPresentFault(Mode
, (ULONG_PTR
)Address
, TrapInformation
? FALSE
: TRUE
);