https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4d043aa05ea8cf7741a4d…
commit 4d043aa05ea8cf7741a4d93bb6792202781000b5
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Mon Jan 1 23:03:56 2018 +0100
[NTOS:MM] Make use of FaultCode and MI_IS_NOT_PRESENT_FAULT and MI_IS_WRITE_ACCESS
macros in MmArmAccessFault.
---
ntoskrnl/include/internal/amd64/mm.h | 1 +
ntoskrnl/include/internal/arm/mm.h | 1 +
ntoskrnl/include/internal/i386/mm.h | 1 +
ntoskrnl/mm/ARM3/pagfault.c | 31 +++++++++++++++----------------
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/ntoskrnl/include/internal/amd64/mm.h b/ntoskrnl/include/internal/amd64/mm.h
index 0d28381422..d2769fd859 100644
--- a/ntoskrnl/include/internal/amd64/mm.h
+++ b/ntoskrnl/include/internal/amd64/mm.h
@@ -108,6 +108,7 @@
/* Macros to identify the page fault reason from the error code */
#define MI_IS_NOT_PRESENT_FAULT(FaultCode) !BooleanFlagOn(FaultCode, 0x1)
+#define MI_IS_WRITE_ACCESS(FaultCode) BooleanFlagOn(FaultCode, 0x2)
/* On x64, these are the same */
#define MI_WRITE_VALID_PPE MI_WRITE_VALID_PTE
diff --git a/ntoskrnl/include/internal/arm/mm.h b/ntoskrnl/include/internal/arm/mm.h
index bc26ab72d8..0d08a55cdf 100644
--- a/ntoskrnl/include/internal/arm/mm.h
+++ b/ntoskrnl/include/internal/arm/mm.h
@@ -90,6 +90,7 @@
/* Macros to identify the page fault reason from the error code */
#define MI_IS_NOT_PRESENT_FAULT(FaultCode) TRUE
+#define MI_IS_WRITE_ACCESS(FaultCode) TRUE
/* Convert an address to a corresponding PTE */
#define MiAddressToPte(x) \
diff --git a/ntoskrnl/include/internal/i386/mm.h b/ntoskrnl/include/internal/i386/mm.h
index d38ab01c31..573de1eb45 100644
--- a/ntoskrnl/include/internal/i386/mm.h
+++ b/ntoskrnl/include/internal/i386/mm.h
@@ -114,6 +114,7 @@
/* Macros to identify the page fault reason from the error code */
#define MI_IS_NOT_PRESENT_FAULT(FaultCode) !BooleanFlagOn(FaultCode, 0x1)
+#define MI_IS_WRITE_ACCESS(FaultCode) BooleanFlagOn(FaultCode, 0x2)
/* On x86, these two are the same */
#define MI_WRITE_VALID_PPE MI_WRITE_VALID_PTE
diff --git a/ntoskrnl/mm/ARM3/pagfault.c b/ntoskrnl/mm/ARM3/pagfault.c
index b85a25be05..e5225fd63b 100644
--- a/ntoskrnl/mm/ARM3/pagfault.c
+++ b/ntoskrnl/mm/ARM3/pagfault.c
@@ -1644,7 +1644,6 @@ MmArmAccessFault(IN ULONG FaultCode,
ULONG Color;
BOOLEAN IsSessionAddress;
PMMPFN Pfn1;
- BOOLEAN StoreInstruction = !MI_IS_NOT_PRESENT_FAULT(FaultCode);
DPRINT("ARM3 FAULT AT: %p\n", Address);
/* Check for page fault on high IRQL */
@@ -1694,10 +1693,10 @@ MmArmAccessFault(IN ULONG FaultCode,
/* Not yet implemented in ReactOS */
ASSERT(MI_IS_PAGE_LARGE(PointerPde) == FALSE);
- ASSERT(((StoreInstruction) && MI_IS_PAGE_COPY_ON_WRITE(PointerPte)) ==
FALSE);
+ ASSERT((!MI_IS_NOT_PRESENT_FAULT(FaultCode) &&
MI_IS_PAGE_COPY_ON_WRITE(PointerPte)) == FALSE);
/* Check if this was a write */
- if (StoreInstruction)
+ if (MI_IS_WRITE_ACCESS(FaultCode))
{
/* Was it to a read-only page? */
Pfn1 = MI_PFN_ELEMENT(PointerPte->u.Hard.PageFrameNumber);
@@ -1745,7 +1744,7 @@ MmArmAccessFault(IN ULONG FaultCode,
/* PXE/PPE/PDE (still) not valid, kill the system */
KeBugCheckEx(PAGE_FAULT_IN_NONPAGED_AREA,
(ULONG_PTR)Address,
- StoreInstruction,
+ FaultCode,
(ULONG_PTR)TrapInformation,
2);
}
@@ -1766,7 +1765,7 @@ MmArmAccessFault(IN ULONG FaultCode,
if (TempPte.u.Hard.Valid)
{
/* Check if this was a write */
- if (StoreInstruction)
+ if (MI_IS_WRITE_ACCESS(FaultCode))
{
/* Was it to a read-only page? */
Pfn1 = MI_PFN_ELEMENT(PointerPte->u.Hard.PageFrameNumber);
@@ -1799,7 +1798,7 @@ MmArmAccessFault(IN ULONG FaultCode,
/* It failed, this address is invalid */
KeBugCheckEx(PAGE_FAULT_IN_NONPAGED_AREA,
(ULONG_PTR)Address,
- StoreInstruction,
+ FaultCode,
(ULONG_PTR)TrapInformation,
6);
}
@@ -1867,7 +1866,7 @@ _WARN("Session space stuff is not implemented yet!")
if (TempPte.u.Hard.Valid == 1)
{
/* Check if this was a write */
- if (StoreInstruction)
+ if (MI_IS_WRITE_ACCESS(FaultCode))
{
/* Was it to a read-only page that is not copy on write? */
Pfn1 = MI_PFN_ELEMENT(PointerPte->u.Hard.PageFrameNumber);
@@ -1889,7 +1888,7 @@ _WARN("Session space stuff is not implemented yet!")
/* Check for read-only write in session space */
if ((IsSessionAddress) &&
- (StoreInstruction) &&
+ MI_IS_WRITE_ACCESS(FaultCode) &&
!MI_IS_PAGE_WRITEABLE(&TempPte))
{
/* Sanity check */
@@ -1932,7 +1931,7 @@ _WARN("Session space stuff is not implemented yet!")
/* Bad boy, bad boy, whatcha gonna do, whatcha gonna do when ARM3 comes
for you! */
KeBugCheckEx(DRIVER_CAUGHT_MODIFYING_FREED_POOL,
(ULONG_PTR)Address,
- StoreInstruction,
+ FaultCode,
Mode,
4);
}
@@ -1962,7 +1961,7 @@ _WARN("Session space stuff is not implemented yet!")
/* Bugcheck the system! */
KeBugCheckEx(PAGE_FAULT_IN_NONPAGED_AREA,
(ULONG_PTR)Address,
- StoreInstruction,
+ FaultCode,
(ULONG_PTR)TrapInformation,
1);
}
@@ -1973,14 +1972,14 @@ _WARN("Session space stuff is not implemented yet!")
/* Bugcheck the system! */
KeBugCheckEx(PAGE_FAULT_IN_NONPAGED_AREA,
(ULONG_PTR)Address,
- StoreInstruction,
+ FaultCode,
(ULONG_PTR)TrapInformation,
0);
}
}
/* Check for demand page */
- if ((StoreInstruction) &&
+ if (MI_IS_WRITE_ACCESS(FaultCode) &&
!(ProtoPte) &&
!(IsSessionAddress) &&
!(TempPte.u.Hard.Valid))
@@ -1999,7 +1998,7 @@ _WARN("Session space stuff is not implemented yet!")
}
/* Now do the real fault handling */
- Status = MiDispatchFault(StoreInstruction,
+ Status = MiDispatchFault(!MI_IS_NOT_PRESENT_FAULT(FaultCode),
Address,
PointerPte,
ProtoPte,
@@ -2148,7 +2147,7 @@ UserFault:
if (TempPte.u.Hard.Valid)
{
/* Check if this is a write on a readonly PTE */
- if (StoreInstruction)
+ if (MI_IS_WRITE_ACCESS(FaultCode))
{
/* Is this a copy on write PTE? */
if (MI_IS_PAGE_COPY_ON_WRITE(&TempPte))
@@ -2417,7 +2416,7 @@ UserFault:
{
/* Run a software access check first, including to detect guard pages */
Status = MiAccessCheck(PointerPte,
- StoreInstruction,
+ !MI_IS_NOT_PRESENT_FAULT(FaultCode),
Mode,
ProtectionCode,
TrapInformation,
@@ -2444,7 +2443,7 @@ UserFault:
}
/* Dispatch the fault */
- Status = MiDispatchFault(StoreInstruction,
+ Status = MiDispatchFault(!MI_IS_NOT_PRESENT_FAULT(FaultCode),
Address,
PointerPte,
ProtoPte,