[NTOSKRNL]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 25 Jul 2010 00:50:03 +0000 (00:50 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 25 Jul 2010 00:50:03 +0000 (00:50 +0000)
Make MmIsAddressValid portable by using _MI_PAGING_LEVELS macro.

svn path=/trunk/; revision=48238

reactos/ntoskrnl/include/internal/amd64/mm.h
reactos/ntoskrnl/include/internal/i386/mm.h
reactos/ntoskrnl/mm/ARM3/mmsup.c
reactos/ntoskrnl/mm/amd64/page.c

index 889c43e..c52132d 100644 (file)
@@ -4,6 +4,8 @@
 
 #pragma once
 
 
 #pragma once
 
+#define _MI_PAGING_LEVELS 4
+
 /* Helper macros */
 #define PAGE_MASK(x)           ((x)&(~0xfff))
 #define PAE_PAGE_MASK(x)       ((x)&(~0xfffLL))
 /* Helper macros */
 #define PAGE_MASK(x)           ((x)&(~0xfff))
 #define PAE_PAGE_MASK(x)       ((x)&(~0xfffLL))
index edd86bb..1014884 100644 (file)
@@ -7,6 +7,12 @@
 struct _EPROCESS;
 PULONG MmGetPageDirectory(VOID);
 
 struct _EPROCESS;
 PULONG MmGetPageDirectory(VOID);
 
+#ifdef _PAE_
+#define _MI_PAGING_LEVELS 3
+#else
+#define _MI_PAGING_LEVELS 2
+#endif
+
 #define PAGE_MASK(x)           ((x)&(~0xfff))
 #define PAE_PAGE_MASK(x)       ((x)&(~0xfffLL))
 
 #define PAGE_MASK(x)           ((x)&(~0xfff))
 #define PAE_PAGE_MASK(x)       ((x)&(~0xfffLL))
 
index b84c7a0..4410a39 100644 (file)
@@ -64,22 +64,26 @@ BOOLEAN
 NTAPI
 MmIsAddressValid(IN PVOID VirtualAddress)
 {
 NTAPI
 MmIsAddressValid(IN PVOID VirtualAddress)
 {
-    //
-    // Just check the Valid bit in the Address' PDE and PTE
-    //
-    if ((MiAddressToPde(VirtualAddress)->u.Hard.Valid == 0) ||
-        (MiAddressToPte(VirtualAddress)->u.Hard.Valid == 0))
-    {
-        //
-        // Attempting to access this page is guranteed to result in a page fault
-        //
-        return FALSE;
-    }
+#if _MI_PAGING_LEVELS >= 4
+    /* Check if the PXE is valid */
+    if (MiAddressToPxe(VirtualAddress)->u.Hard.Valid == 0) return FALSE;
+#endif
 
 
-    //
-    // This address is valid now, but it will only stay so if the caller holds
-    // the PFN lock
-    //
+#if _MI_PAGING_LEVELS >= 3
+    /* Check if the PPE is valid */
+    if (MiAddressToPpe(VirtualAddress)->u.Hard.Valid == 0) return FALSE;
+#endif
+
+#if _MI_PAGING_LEVELS >= 2
+    /* Check if the PDE is valid */
+    if (MiAddressToPde(VirtualAddress)->u.Hard.Valid == 0) return FALSE;
+#endif
+
+    /* Check if the PTE is valid */
+    if (MiAddressToPte(VirtualAddress)->u.Hard.Valid == 0) return FALSE;
+
+    /* This address is valid now, but it will only stay so if the caller holds
+     * the PFN lock */
     return TRUE;
 }
 
     return TRUE;
 }
 
index d9830b4..33cdeeb 100644 (file)
@@ -519,16 +519,4 @@ MmCreateProcessAddressSpace(IN ULONG MinWs,
     return 0;
 }
 
     return 0;
 }
 
-BOOLEAN
-NTAPI
-_MmIsAddressValid(IN PVOID VirtualAddress)
-{
-    /* Check all four page table levels */
-    return (MiAddressToPxe(VirtualAddress)->u.Hard.Valid != 0 &&
-            MiAddressToPpe(VirtualAddress)->u.Hard.Valid != 0 &&
-            MiAddressToPde(VirtualAddress)->u.Hard.Valid != 0 &&
-            MiAddressToPte(VirtualAddress)->u.Hard.Valid != 0);
-}
-
-
 /* EOF */
 /* EOF */