Kernel base address and system space start can be distinct addresses, so use KERNEL_BASE and MmSystemRangeStart accordingly in the code.
Modified: trunk/reactos/ntoskrnl/include/internal/i386/mm.h
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c
Modified: trunk/reactos/ntoskrnl/ke/main.c
Modified: trunk/reactos/ntoskrnl/mm/aspace.c
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
Modified: trunk/reactos/ntoskrnl/mm/i386/pfault.c
Modified: trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/mm/mdl.c
Modified: trunk/reactos/ntoskrnl/mm/mm.c
Modified: trunk/reactos/ntoskrnl/mm/rmap.c
Modified: trunk/reactos/ntoskrnl/mm/virtual.c

Modified: trunk/reactos/ntoskrnl/include/internal/i386/mm.h
--- trunk/reactos/ntoskrnl/include/internal/i386/mm.h	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/include/internal/i386/mm.h	2005-07-06 08:20:26 UTC (rev 16447)
@@ -22,8 +22,6 @@
 #define PA_SYSTEM          (0)
 #endif
 
-#define KERNEL_BASE        (ULONG)MmSystemRangeStart
-
 #if defined(__GNUC__)
 
 #define FLUSH_TLB   {				\

Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
--- trunk/reactos/ntoskrnl/include/internal/ke.h	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/include/internal/ke.h	2005-07-06 08:20:26 UTC (rev 16447)
@@ -308,6 +308,8 @@
 
 /* INITIALIZATION FUNCTIONS *************************************************/
 
+extern ULONG_PTR KERNEL_BASE;
+
 VOID KeInitExceptions(VOID);
 VOID KeInitInterrupts(VOID);
 VOID KeInitTimer(VOID);

Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c
--- trunk/reactos/ntoskrnl/ke/i386/exp.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/ke/i386/exp.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -135,7 +135,7 @@
           current_entry = current_entry->Flink;
        }
 
-     address = (PVOID)((ULONG_PTR)address & ~KERNEL_BASE);
+     address = (PVOID)((ULONG_PTR)address & ~(ULONG_PTR)MmSystemRangeStart);
    } while(++i <= 1);
 
    return(FALSE);

Modified: trunk/reactos/ntoskrnl/ke/main.c
--- trunk/reactos/ntoskrnl/ke/main.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/ke/main.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -22,18 +22,6 @@
 ULONG NtMajorVersion = 5;
 ULONG NtMinorVersion = 0;
 ULONG NtOSCSDVersion = BUILD_OSCSDVERSION(6, 0);
-#ifdef  __GNUC__
-ULONG EXPORTED NtBuildNumber = KERNEL_VERSION_BUILD;
-ULONG EXPORTED NtGlobalFlag = 0;
-CHAR  EXPORTED KeNumberProcessors;
-KAFFINITY  EXPORTED KeActiveProcessors;
-LOADER_PARAMETER_BLOCK EXPORTED KeLoaderBlock;
-ULONG EXPORTED KeDcacheFlushCount = 0;
-ULONG EXPORTED KeIcacheFlushCount = 0;
-ULONG EXPORTED KiDmaIoCoherency = 0; /* RISC Architectures only */
-ULONG EXPORTED InitSafeBootMode = 0; /* KB83764 */
-#else
-/* Microsoft-style declarations */
 EXPORTED ULONG NtBuildNumber = KERNEL_VERSION_BUILD;
 EXPORTED ULONG NtGlobalFlag = 0;
 EXPORTED CHAR  KeNumberProcessors;
@@ -43,7 +31,6 @@
 EXPORTED ULONG KeIcacheFlushCount = 0;
 EXPORTED ULONG KiDmaIoCoherency = 0; /* RISC Architectures only */
 EXPORTED ULONG InitSafeBootMode = 0; /* KB83764 */
-#endif	/* __GNUC__ */
 
 LOADER_MODULE KeLoaderModules[64];
 static CHAR KeLoaderModuleStrings[64][256];
@@ -69,6 +56,9 @@
 /* Cached modules from the loader block */
 PLOADER_MODULE CachedModules[MaximumCachedModuleType];
 
+extern unsigned int _image_base__;
+ULONG_PTR KERNEL_BASE = (ULONG_PTR)&_image_base__;
+
 /* FUNCTIONS ****************************************************************/
 
 /*

Modified: trunk/reactos/ntoskrnl/mm/aspace.c
--- trunk/reactos/ntoskrnl/mm/aspace.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/aspace.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -73,7 +73,7 @@
    }
    else
    {
-      AddressSpace->LowestAddress = (PVOID)KERNEL_BASE;
+      AddressSpace->LowestAddress = MmSystemRangeStart;
    }
    AddressSpace->Process = Process;
    if (Process != NULL)

Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
--- trunk/reactos/ntoskrnl/mm/i386/page.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/i386/page.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -105,7 +105,7 @@
       MiFlushTlbIpiRoutine(Address);
    }
 #else
-   if ((Pt && MmUnmapPageTable(Pt)) || Address >= (PVOID)KERNEL_BASE)
+   if ((Pt && MmUnmapPageTable(Pt)) || Address >= MmSystemRangeStart)
    {
       FLUSH_TLB_ONE(Address);
    }
@@ -226,7 +226,7 @@
       for (i = 0; i < 4; i++)
       {
          PageDir = (PULONGLONG)MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(PageDirTable[i]));
-         if (i < PAE_ADDR_TO_PDTE_OFFSET(KERNEL_BASE))
+         if (i < PAE_ADDR_TO_PDTE_OFFSET(MmSystemRangeStart))
 	 {
 	    for (j = 0; j < 512; j++)
 	    {
@@ -274,7 +274,7 @@
       PULONG Pde;
       PULONG PageDir;
       PageDir = MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase.u.LowPart));
-      for (i = 0; i < ADDR_TO_PDE_OFFSET(KERNEL_BASE); i++)
+      for (i = 0; i < ADDR_TO_PDE_OFFSET(MmSystemRangeStart); i++)
       {
          if (PageDir[i] != 0)
          {
@@ -358,7 +358,7 @@
 	 PageDirTable[i] = PAE_PFN_TO_PTE(Pfn[1+i]) | PA_PRESENT;
       }
       MmDeleteHyperspaceMapping(PageDirTable);
-      for (i = PAE_ADDR_TO_PDTE_OFFSET(KERNEL_BASE); i < 4; i++)
+      for (i = PAE_ADDR_TO_PDTE_OFFSET(MmSystemRangeStart); i < 4; i++)
       {
          PageDir = (PULONGLONG)MmCreateHyperspaceMapping(Pfn[i+1]);
          memcpy(PageDir, &MmGlobalKernelPageDirectoryForPAE[i * 512], 512 * sizeof(ULONGLONG));
@@ -382,9 +382,9 @@
       PULONG PageDirectory;
       PageDirectory = MmCreateHyperspaceMapping(Pfn[0]);
 
-      memcpy(PageDirectory + ADDR_TO_PDE_OFFSET(KERNEL_BASE),
-             MmGlobalKernelPageDirectory + ADDR_TO_PDE_OFFSET(KERNEL_BASE),
-             (1024 - ADDR_TO_PDE_OFFSET(KERNEL_BASE)) * sizeof(ULONG));
+      memcpy(PageDirectory + ADDR_TO_PDE_OFFSET(MmSystemRangeStart),
+             MmGlobalKernelPageDirectory + ADDR_TO_PDE_OFFSET(MmSystemRangeStart),
+             (1024 - ADDR_TO_PDE_OFFSET(MmSystemRangeStart)) * sizeof(ULONG));
 
       DPRINT("Addr %x\n",ADDR_TO_PDE_OFFSET(PAGETABLE_MAP));
       PageDirectory[ADDR_TO_PDE_OFFSET(PAGETABLE_MAP)] = PFN_TO_PTE(Pfn[0]) | PA_PRESENT | PA_READWRITE;
@@ -416,7 +416,7 @@
    {
       *(ADDR_TO_PDE(Address)) = 0;
    }
-   if (Address >= (PVOID)KERNEL_BASE)
+   if (Address >= MmSystemRangeStart)
    {
       KEBUGCHECK(0);
       //       MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
@@ -474,7 +474,7 @@
    }
    MiFlushTlb(NULL, Address);
 
-   if (Address >= (PVOID)KERNEL_BASE)
+   if (Address >= MmSystemRangeStart)
    {
       //    MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
       KEBUGCHECK(0);
@@ -506,7 +506,7 @@
    {
       KEBUGCHECK(0);
    }
-   if (Address < (PVOID)KERNEL_BASE && Process && Process != PsGetCurrentProcess())
+   if (Address < MmSystemRangeStart && Process && Process != PsGetCurrentProcess())
    {
       PageDirTable = MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(Process->Pcb.DirectoryTableBase.QuadPart));
       if (PageDirTable == NULL)
@@ -556,7 +556,7 @@
    PageDir = PAE_ADDR_TO_PDE(Address);
    if (0LL == ExfInterlockedCompareExchange64UL(PageDir, &ZeroEntry, &ZeroEntry))
    {
-      if (Address >= (PVOID)KERNEL_BASE)
+      if (Address >= MmSystemRangeStart)
       {
 	 if (MmGlobalKernelPageDirectoryForPAE[PAE_ADDR_TO_PDE_OFFSET(Address)] == 0LL)
 	 {
@@ -612,7 +612,7 @@
    ULONG Entry;
    PULONG Pt, PageDir;
 
-   if (Address < (PVOID)KERNEL_BASE && Process && Process != PsGetCurrentProcess())
+   if (Address < MmSystemRangeStart && Process && Process != PsGetCurrentProcess())
    {
       PageDir = MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase.QuadPart));
       if (PageDir == NULL)
@@ -653,7 +653,7 @@
    PageDir = ADDR_TO_PDE(Address);
    if (0 == InterlockedCompareExchangeUL(PageDir, 0, 0))
    {
-      if (Address >= (PVOID)KERNEL_BASE)
+      if (Address >= MmSystemRangeStart)
       {
          if (0 == InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], 0, 0))
 	 {
@@ -1024,7 +1024,7 @@
     */
    if (Process != NULL && WasValid &&
        Process->AddressSpace.PageTableRefCountTable != NULL &&
-       Address < (PVOID)KERNEL_BASE)
+       Address < MmSystemRangeStart)
    {
       PUSHORT Ptrc;
       ULONG Idx;
@@ -1072,7 +1072,7 @@
        */
       if (Process != NULL && Pte &&
           Process->AddressSpace.PageTableRefCountTable != NULL &&
-          Address < (PVOID)KERNEL_BASE)
+          Address < MmSystemRangeStart)
       {
          PUSHORT Ptrc;
 
@@ -1116,7 +1116,7 @@
        */
       if (Process != NULL && Pte &&
           Process->AddressSpace.PageTableRefCountTable != NULL &&
-          Address < (PVOID)KERNEL_BASE)
+          Address < MmSystemRangeStart)
       {
          PUSHORT Ptrc;
 
@@ -1193,7 +1193,7 @@
 BOOLEAN
 MmIsAccessedAndResetAccessPage(PEPROCESS Process, PVOID Address)
 {
-   if (Address < (PVOID)KERNEL_BASE && Process == NULL)
+   if (Address < MmSystemRangeStart && Process == NULL)
    {
       DPRINT1("MmIsAccessedAndResetAccessPage is called for user space without a process.\n");
       KEBUGCHECK(0);
@@ -1258,7 +1258,7 @@
 
 VOID MmSetCleanPage(PEPROCESS Process, PVOID Address)
 {
-   if (Address < (PVOID)KERNEL_BASE && Process == NULL)
+   if (Address < MmSystemRangeStart && Process == NULL)
    {
       DPRINT1("MmSetCleanPage is called for user space without a process.\n");
       KEBUGCHECK(0);
@@ -1321,7 +1321,7 @@
 
 VOID MmSetDirtyPage(PEPROCESS Process, PVOID Address)
 {
-   if (Address < (PVOID)KERNEL_BASE && Process == NULL)
+   if (Address < MmSystemRangeStart && Process == NULL)
    {
       DPRINT1("MmSetDirtyPage is called for user space without a process.\n");
       KEBUGCHECK(0);
@@ -1475,7 +1475,7 @@
    DPRINT("MmCreateVirtualMappingForKernel(%x, %x, %x, %d)\n",
            Address, flProtect, Pages, PageCount);
 
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       DPRINT1("MmCreateVirtualMappingForKernel is called for user space\n");
       KEBUGCHECK(0);
@@ -1592,12 +1592,12 @@
                         PVOID Address,
                         SWAPENTRY SwapEntry)
 {
-   if (Process == NULL && Address < (PVOID)KERNEL_BASE)
+   if (Process == NULL && Address < MmSystemRangeStart)
    {
       DPRINT1("No process\n");
       KEBUGCHECK(0);
    }
-   if (Process != NULL && Address >= (PVOID)KERNEL_BASE)
+   if (Process != NULL && Address >= MmSystemRangeStart)
    {
       DPRINT1("Setting kernel address with process context\n");
       KEBUGCHECK(0);
@@ -1661,7 +1661,7 @@
    }
    if (Process != NULL &&
        Process->AddressSpace.PageTableRefCountTable != NULL &&
-       Address < (PVOID)KERNEL_BASE)
+       Address < MmSystemRangeStart)
    {
      PUSHORT Ptrc;
      ULONG Idx;
@@ -1692,7 +1692,7 @@
 
    if (Process == NULL)
    {
-      if (Address < (PVOID)KERNEL_BASE)
+      if (Address < MmSystemRangeStart)
       {
          DPRINT1("No process\n");
          KEBUGCHECK(0);
@@ -1706,13 +1706,14 @@
    }
    else
    {
-      if (Address >= (PVOID)KERNEL_BASE)
+      if (Address >= MmSystemRangeStart)
       {
          DPRINT1("Setting kernel address with process context\n");
          KEBUGCHECK(0);
       }
-      if (PageCount > KERNEL_BASE / PAGE_SIZE ||
-	  (ULONG_PTR) Address / PAGE_SIZE + PageCount > KERNEL_BASE / PAGE_SIZE)
+      if (PageCount > (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE ||
+	  (ULONG_PTR) Address / PAGE_SIZE + PageCount >
+	  (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE)
       {
          DPRINT1("Page Count to large\n");
 	 KEBUGCHECK(0);
@@ -1725,7 +1726,7 @@
       NoExecute = TRUE;
    }
    Attributes &= 0xfff;
-   if (Address >= (PVOID)KERNEL_BASE)
+   if (Address >= MmSystemRangeStart)
    {
       Attributes &= ~PA_USER;
       if (Ke386GlobalPagesEnabled)
@@ -1786,7 +1787,7 @@
          {
             MmMarkPageUnmapped(PAE_PTE_TO_PFN((Pte)));
          }
-         if (Address < (PVOID)KERNEL_BASE &&
+         if (Address < MmSystemRangeStart &&
 	     Process->AddressSpace.PageTableRefCountTable != NULL &&
              Attributes & PA_PRESENT)
          {
@@ -1798,7 +1799,7 @@
          }
          if (Pte != 0LL)
          {
-            if (Address > (PVOID)KERNEL_BASE ||
+            if (Address > MmSystemRangeStart ||
                 (Pt >= (PULONGLONG)PAGETABLE_MAP && Pt < (PULONGLONG)PAGETABLE_MAP + 4*512*512))
             {
               MiFlushTlb((PULONG)Pt, Address);
@@ -1851,7 +1852,7 @@
             MmMarkPageUnmapped(PTE_TO_PFN((Pte)));
          }
 	 InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
-         if (Address < (PVOID)KERNEL_BASE &&
+         if (Address < MmSystemRangeStart &&
 	     Process->AddressSpace.PageTableRefCountTable != NULL &&
              Attributes & PA_PRESENT)
          {
@@ -1863,7 +1864,7 @@
          }
          if (Pte != 0)
          {
-            if (Address > (PVOID)KERNEL_BASE ||
+            if (Address > MmSystemRangeStart ||
                 (Pt >= (PULONG)PAGETABLE_MAP && Pt < (PULONG)PAGETABLE_MAP + 1024*1024))
             {
                MiFlushTlb(Pt, Address);
@@ -1963,7 +1964,7 @@
       NoExecute = TRUE;
    }
    Attributes &= 0xfff;
-   if (Address >= (PVOID)KERNEL_BASE)
+   if (Address >= MmSystemRangeStart)
    {
       Attributes &= ~PA_USER;
       if (Ke386GlobalPagesEnabled)
@@ -2233,7 +2234,7 @@
 {
    ULONG StartOffset, EndOffset, Offset;
 
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       KEBUGCHECK(0);
    }
@@ -2322,7 +2323,7 @@
    if (Ke386Pae)
    {
       PULONGLONG CurrentPageDirectory = (PULONGLONG)PAE_PAGEDIRECTORY_MAP;
-      for (i = PAE_ADDR_TO_PDE_OFFSET(KERNEL_BASE); i < 4 * 512; i++)
+      for (i = PAE_ADDR_TO_PDE_OFFSET(MmSystemRangeStart); i < 4 * 512; i++)
       {
          if (!(i >= PAE_ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) && i < PAE_ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) + 4) &&
 	     !(i >= PAE_ADDR_TO_PDE_OFFSET(HYPERSPACE) && i < PAE_ADDR_TO_PDE_OFFSET(HYPERSPACE) + 2) &&
@@ -2340,7 +2341,7 @@
    else
    {
       PULONG CurrentPageDirectory = (PULONG)PAGEDIRECTORY_MAP;
-      for (i = ADDR_TO_PDE_OFFSET(KERNEL_BASE); i < 1024; i++)
+      for (i = ADDR_TO_PDE_OFFSET(MmSystemRangeStart); i < 1024; i++)
       {
          if (i != ADDR_TO_PDE_OFFSET(PAGETABLE_MAP) &&
 	     i != ADDR_TO_PDE_OFFSET(HYPERSPACE) &&
@@ -2360,7 +2361,7 @@
 ULONG
 MiGetUserPageDirectoryCount(VOID)
 {
-   return Ke386Pae ? PAE_ADDR_TO_PDE_OFFSET(KERNEL_BASE) : ADDR_TO_PDE_OFFSET(KERNEL_BASE);
+   return Ke386Pae ? PAE_ADDR_TO_PDE_OFFSET(MmSystemRangeStart) : ADDR_TO_PDE_OFFSET(MmSystemRangeStart);
 }
 
 VOID INIT_FUNCTION

Modified: trunk/reactos/ntoskrnl/mm/i386/pfault.c
--- trunk/reactos/ntoskrnl/mm/i386/pfault.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/i386/pfault.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -51,7 +51,7 @@
       Mode = KernelMode;
    }
 
-   if (Mode == KernelMode && Cr2 >= KERNEL_BASE &&
+   if (Mode == KernelMode && Cr2 >= (ULONG_PTR)MmSystemRangeStart &&
          Mmi386MakeKernelPageTableGlobal((PVOID)Cr2))
    {
       return(STATUS_SUCCESS);

Modified: trunk/reactos/ntoskrnl/mm/marea.c
--- trunk/reactos/ntoskrnl/mm/marea.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/marea.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -469,8 +469,8 @@
    ULONG_PTR Length,
    ULONG_PTR Granularity)
 {
-   PVOID HighestAddress = AddressSpace->LowestAddress < (PVOID)KERNEL_BASE ?
-                          (PVOID)(KERNEL_BASE - 1) : (PVOID)MAXULONG_PTR;
+   PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+                          (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
    PVOID AlignedAddress;
    PMEMORY_AREA Node;
    PMEMORY_AREA FirstNode;
@@ -546,8 +546,8 @@
    ULONG_PTR Length,
    ULONG_PTR Granularity)
 {
-   PVOID HighestAddress = AddressSpace->LowestAddress < (PVOID)KERNEL_BASE ?
-                          (PVOID)(KERNEL_BASE - 1) : (PVOID)MAXULONG_PTR;
+   PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+                          (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
    PVOID AlignedAddress;
    PMEMORY_AREA Node;
    PMEMORY_AREA PreviousNode;
@@ -645,16 +645,16 @@
 {
    PMEMORY_AREA Node = AddressSpace->MemoryAreaRoot;
    PMEMORY_AREA RightNeighbour = NULL;
-   PVOID HighestAddress = AddressSpace->LowestAddress < (PVOID)KERNEL_BASE ?
-                          (PVOID)(KERNEL_BASE - 1) : (PVOID)MAXULONG_PTR;
+   PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+                          (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
 
    MmVerifyMemoryAreas(AddressSpace);
 
    Address = MM_ROUND_DOWN(Address, PAGE_SIZE);
 
-   if (AddressSpace->LowestAddress < (PVOID)KERNEL_BASE)
+   if (AddressSpace->LowestAddress < MmSystemRangeStart)
    {
-      if (Address >= (PVOID)KERNEL_BASE)
+      if (Address >= MmSystemRangeStart)
       {
          return 0;
       }
@@ -970,15 +970,15 @@
                          - (ULONG_PTR) MM_ROUND_DOWN(*BaseAddress, Granularity));
       *BaseAddress = MM_ROUND_DOWN(*BaseAddress, Granularity);
 
-      if (AddressSpace->LowestAddress == (PVOID)KERNEL_BASE &&
+      if (AddressSpace->LowestAddress == MmSystemRangeStart &&
           *BaseAddress < (PVOID)KERNEL_BASE)
       {
          CHECKPOINT;
          return STATUS_ACCESS_VIOLATION;
       }
 
-      if (AddressSpace->LowestAddress < (PVOID)KERNEL_BASE &&
-          (ULONG_PTR)(*BaseAddress) + tmpLength > KERNEL_BASE)
+      if (AddressSpace->LowestAddress < MmSystemRangeStart &&
+          (ULONG_PTR)(*BaseAddress) + tmpLength > (ULONG_PTR)MmSystemRangeStart)
       {
          CHECKPOINT;
          return STATUS_ACCESS_VIOLATION;

Modified: trunk/reactos/ntoskrnl/mm/mdl.c
--- trunk/reactos/ntoskrnl/mm/mdl.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/mdl.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -217,7 +217,7 @@
     * so there is no need to free it
     */
    if ((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) &&
-         ((ULONG_PTR)BaseAddress >= KERNEL_BASE))
+         (BaseAddress >= MmSystemRangeStart))
    {
       return;
    }
@@ -242,7 +242,7 @@
                              NULL);
    }
 
-   if ((ULONG_PTR)BaseAddress >= KERNEL_BASE)
+   if (BaseAddress >= MmSystemRangeStart)
    {
       ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
 
@@ -377,7 +377,7 @@
    ASSERT(NrPages <= (Mdl->Size - sizeof(MDL))/sizeof(PFN_TYPE));
 
 
-   if (Mdl->StartVa >= (PVOID)KERNEL_BASE &&
+   if (Mdl->StartVa >= MmSystemRangeStart &&
        MmGetPfnForProcess(NULL, Mdl->StartVa) >= MmPageArraySize)
    {
        /* phys addr is not phys memory so this must be io memory */
@@ -392,7 +392,7 @@
    }
 
 
-   if (Mdl->StartVa >= (PVOID)KERNEL_BASE)
+   if (Mdl->StartVa >= MmSystemRangeStart)
    {
       /* FIXME: why isn't AccessMode used? */
       Mode = KernelMode;
@@ -556,7 +556,7 @@
     * mdl buffer must (at least) be in kernel space, thou this doesn't
     * necesarely mean that the buffer in within _nonpaged_ kernel space...
     */
-   ASSERT((ULONG_PTR)Mdl->StartVa >= KERNEL_BASE);
+   ASSERT(Mdl->StartVa >= MmSystemRangeStart);
 
    PageCount = PAGE_ROUND_UP(Mdl->ByteOffset + Mdl->ByteCount) / PAGE_SIZE;
    MdlPages = (PPFN_TYPE)(Mdl + 1);

Modified: trunk/reactos/ntoskrnl/mm/mm.c
--- trunk/reactos/ntoskrnl/mm/mm.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/mm.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -35,7 +35,7 @@
 
   if (ExGetPreviousMode() == UserMode)
     {
-      if ((ULONG_PTR)Dest >= KERNEL_BASE)
+      if (Dest >= MmSystemRangeStart)
    {
      return(STATUS_ACCESS_VIOLATION);
    }
@@ -56,7 +56,7 @@
 
   if (ExGetPreviousMode() == UserMode)
     {
-      if ((ULONG_PTR)Src >= KERNEL_BASE)
+      if (Src >= MmSystemRangeStart)
    {
      return(STATUS_ACCESS_VIOLATION);
    }
@@ -158,7 +158,7 @@
    MEMORY_AREA* MemoryArea;
    PMADDRESS_SPACE AddressSpace;
 
-   if ((ULONG_PTR)VirtualAddress >= KERNEL_BASE)
+   if (VirtualAddress >= MmSystemRangeStart)
    {
       AddressSpace = MmGetKernelAddressSpace();
    }
@@ -205,7 +205,7 @@
    /*
     * Find the memory area for the faulting address
     */
-   if (Address >= KERNEL_BASE)
+   if (Address >= (ULONG_PTR)MmSystemRangeStart)
    {
       /*
        * Check permissions
@@ -325,7 +325,7 @@
        * after my init patch anyways
        */
       CPRINT("No current process\n");
-      if (Address < KERNEL_BASE)
+      if (Address < (ULONG_PTR)MmSystemRangeStart)
       {
          return(STATUS_UNSUCCESSFUL);
       }
@@ -334,7 +334,7 @@
    /*
     * Find the memory area for the faulting address
     */
-   if (Address >= KERNEL_BASE)
+   if (Address >= (ULONG_PTR)MmSystemRangeStart)
    {
       /*
        * Check permissions

Modified: trunk/reactos/ntoskrnl/mm/rmap.c
--- trunk/reactos/ntoskrnl/mm/rmap.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/rmap.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -74,7 +74,7 @@
    {
       KEBUGCHECK(0);
    }
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       Status = ObReferenceObjectByPointer(Process, PROCESS_ALL_ACCESS, NULL, KernelMode);
       ExReleaseFastMutex(&RmapListLock);
@@ -100,7 +100,7 @@
    if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
    {
       MmUnlockAddressSpace(AddressSpace);
-      if (Address < (PVOID)KERNEL_BASE)
+      if (Address < MmSystemRangeStart)
       {
          ObDereferenceObject(Process);
       }
@@ -122,7 +122,7 @@
       if (PageOp == NULL)
       {
          MmUnlockAddressSpace(AddressSpace);
-         if (Address < (PVOID)KERNEL_BASE)
+         if (Address < MmSystemRangeStart)
          {
             ObDereferenceObject(Process);
          }
@@ -142,13 +142,13 @@
    }
    else if ((Type == MEMORY_AREA_VIRTUAL_MEMORY) || (Type == MEMORY_AREA_PEB_OR_TEB))
    {
-      PageOp = MmGetPageOp(MemoryArea, Address < (PVOID)KERNEL_BASE ? Process->UniqueProcessId : NULL,
+      PageOp = MmGetPageOp(MemoryArea, Address < MmSystemRangeStart ? Process->UniqueProcessId : NULL,
                            Address, NULL, 0, MM_PAGEOP_PAGEOUT, TRUE);
 
       if (PageOp == NULL)
       {
          MmUnlockAddressSpace(AddressSpace);
-         if (Address < (PVOID)KERNEL_BASE)
+         if (Address < MmSystemRangeStart)
          {
             ObDereferenceObject(Process);
          }
@@ -170,7 +170,7 @@
    {
       KEBUGCHECK(0);
    }
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       ObDereferenceObject(Process);
    }
@@ -204,7 +204,7 @@
       KEBUGCHECK(0);
    }
 
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       Status = ObReferenceObjectByPointer(Process, PROCESS_ALL_ACCESS, NULL, KernelMode);
       ExReleaseFastMutex(&RmapListLock);
@@ -225,7 +225,7 @@
    if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
    {
       MmUnlockAddressSpace(AddressSpace);
-      if (Address < (PVOID)KERNEL_BASE)
+      if (Address < MmSystemRangeStart)
       {
          ObDereferenceObject(Process);
       }
@@ -245,7 +245,7 @@
       if (PageOp == NULL)
       {
          MmUnlockAddressSpace(AddressSpace);
-         if (Address < (PVOID)KERNEL_BASE)
+         if (Address < MmSystemRangeStart)
          {
             ObDereferenceObject(Process);
          }
@@ -265,12 +265,12 @@
    }
    else if ((Type == MEMORY_AREA_VIRTUAL_MEMORY) || (Type == MEMORY_AREA_PEB_OR_TEB))
    {
-      PageOp = MmGetPageOp(MemoryArea, Address < (PVOID)KERNEL_BASE ? Process->UniqueProcessId : NULL,
+      PageOp = MmGetPageOp(MemoryArea, Address < MmSystemRangeStart ? Process->UniqueProcessId : NULL,
                            Address, NULL, 0, MM_PAGEOP_PAGEOUT, TRUE);
       if (PageOp == NULL)
       {
          MmUnlockAddressSpace(AddressSpace);
-         if (Address < (PVOID)KERNEL_BASE)
+         if (Address < MmSystemRangeStart)
          {
             ObDereferenceObject(Process);
          }
@@ -292,7 +292,7 @@
    {
       KEBUGCHECK(0);
    }
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       ObDereferenceObject(Process);
    }

Modified: trunk/reactos/ntoskrnl/mm/virtual.c
--- trunk/reactos/ntoskrnl/mm/virtual.c	2005-07-06 07:54:04 UTC (rev 16446)
+++ trunk/reactos/ntoskrnl/mm/virtual.c	2005-07-06 08:20:26 UTC (rev 16447)
@@ -123,7 +123,7 @@
    MEMORY_AREA* MemoryArea;
    PMADDRESS_SPACE AddressSpace;
 
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       Status = ObReferenceObjectByHandle(ProcessHandle,
                                          PROCESS_QUERY_INFORMATION,
@@ -248,7 +248,7 @@
    }
 
    MmUnlockAddressSpace(AddressSpace);
-   if (Address < (PVOID)KERNEL_BASE)
+   if (Address < MmSystemRangeStart)
    {
       ObDereferenceObject(Process);
    }
@@ -286,7 +286,7 @@
 
    PrevMode =  ExGetPreviousMode();
 
-   if (Address >= (PVOID)KERNEL_BASE)
+   if (Address >= MmSystemRangeStart)
    {
       DPRINT1("Invalid parameter\n");
       return STATUS_INVALID_PARAMETER;